Browse Source

Add Wave420L init resource

yanhong.wang 2 years ago
parent
commit
ec66878bb3
100 changed files with 35722 additions and 0 deletions
  1. 17 0
      wave420l/code/TestRunnerParamWave420lEnc.txt
  2. 437 0
      wave420l/code/TestRunnerWave420lEnc.sh
  3. 271 0
      wave420l/code/Wave420Enc.mak
  4. 48 0
      wave420l/code/cfg/rc_cu_1A_8b.cfg
  5. 46 0
      wave420l/code/cfg/set1_001A.cfg
  6. 2 0
      wave420l/code/cmd/hevc_enc_test.cmd
  7. 1685 0
      wave420l/code/common.sh
  8. 79 0
      wave420l/code/config.h
  9. 5029 0
      wave420l/code/ffmpeg/include/libavcodec/avcodec.h
  10. 116 0
      wave420l/code/ffmpeg/include/libavcodec/avfft.h
  11. 95 0
      wave420l/code/ffmpeg/include/libavcodec/dxva2.h
  12. 397 0
      wave420l/code/ffmpeg/include/libavcodec/old_codec_ids.h
  13. 173 0
      wave420l/code/ffmpeg/include/libavcodec/vaapi.h
  14. 162 0
      wave420l/code/ffmpeg/include/libavcodec/vda.h
  15. 195 0
      wave420l/code/ffmpeg/include/libavcodec/vdpau.h
  16. 104 0
      wave420l/code/ffmpeg/include/libavcodec/version.h
  17. 168 0
      wave420l/code/ffmpeg/include/libavcodec/xvmc.h
  18. 2239 0
      wave420l/code/ffmpeg/include/libavformat/avformat.h
  19. 481 0
      wave420l/code/ffmpeg/include/libavformat/avio.h
  20. 76 0
      wave420l/code/ffmpeg/include/libavformat/version.h
  21. 52 0
      wave420l/code/ffmpeg/include/libavutil/adler32.h
  22. 65 0
      wave420l/code/ffmpeg/include/libavutil/aes.h
  23. 160 0
      wave420l/code/ffmpeg/include/libavutil/attributes.h
  24. 149 0
      wave420l/code/ffmpeg/include/libavutil/audio_fifo.h
  25. 6 0
      wave420l/code/ffmpeg/include/libavutil/audioconvert.h
  26. 66 0
      wave420l/code/ffmpeg/include/libavutil/avassert.h
  27. 8 0
      wave420l/code/ffmpeg/include/libavutil/avconfig.h
  28. 302 0
      wave420l/code/ffmpeg/include/libavutil/avstring.h
  29. 320 0
      wave420l/code/ffmpeg/include/libavutil/avutil.h
  30. 67 0
      wave420l/code/ffmpeg/include/libavutil/base64.h
  31. 77 0
      wave420l/code/ffmpeg/include/libavutil/blowfish.h
  32. 216 0
      wave420l/code/ffmpeg/include/libavutil/bprint.h
  33. 109 0
      wave420l/code/ffmpeg/include/libavutil/bswap.h
  34. 274 0
      wave420l/code/ffmpeg/include/libavutil/buffer.h
  35. 221 0
      wave420l/code/ffmpeg/include/libavutil/channel_layout.h
  36. 464 0
      wave420l/code/ffmpeg/include/libavutil/common.h
  37. 111 0
      wave420l/code/ffmpeg/include/libavutil/cpu.h
  38. 85 0
      wave420l/code/ffmpeg/include/libavutil/crc.h
  39. 152 0
      wave420l/code/ffmpeg/include/libavutil/dict.h
  40. 117 0
      wave420l/code/ffmpeg/include/libavutil/error.h
  41. 113 0
      wave420l/code/ffmpeg/include/libavutil/eval.h
  42. 144 0
      wave420l/code/ffmpeg/include/libavutil/fifo.h
  43. 66 0
      wave420l/code/ffmpeg/include/libavutil/file.h
  44. 659 0
      wave420l/code/ffmpeg/include/libavutil/frame.h
  45. 99 0
      wave420l/code/ffmpeg/include/libavutil/hmac.h
  46. 200 0
      wave420l/code/ffmpeg/include/libavutil/imgutils.h
  47. 77 0
      wave420l/code/ffmpeg/include/libavutil/intfloat.h
  48. 40 0
      wave420l/code/ffmpeg/include/libavutil/intfloat_readwrite.h
  49. 621 0
      wave420l/code/ffmpeg/include/libavutil/intreadwrite.h
  50. 62 0
      wave420l/code/ffmpeg/include/libavutil/lfg.h
  51. 313 0
      wave420l/code/ffmpeg/include/libavutil/log.h
  52. 66 0
      wave420l/code/ffmpeg/include/libavutil/lzo.h
  53. 147 0
      wave420l/code/ffmpeg/include/libavutil/mathematics.h
  54. 81 0
      wave420l/code/ffmpeg/include/libavutil/md5.h
  55. 342 0
      wave420l/code/ffmpeg/include/libavutil/mem.h
  56. 32 0
      wave420l/code/ffmpeg/include/libavutil/murmur3.h
  57. 175 0
      wave420l/code/ffmpeg/include/libavutil/old_pix_fmts.h
  58. 757 0
      wave420l/code/ffmpeg/include/libavutil/opt.h
  59. 187 0
      wave420l/code/ffmpeg/include/libavutil/parseutils.h
  60. 291 0
      wave420l/code/ffmpeg/include/libavutil/pixdesc.h
  61. 397 0
      wave420l/code/ffmpeg/include/libavutil/pixfmt.h
  62. 43 0
      wave420l/code/ffmpeg/include/libavutil/random_seed.h
  63. 155 0
      wave420l/code/ffmpeg/include/libavutil/rational.h
  64. 75 0
      wave420l/code/ffmpeg/include/libavutil/ripemd.h
  65. 256 0
      wave420l/code/ffmpeg/include/libavutil/samplefmt.h
  66. 74 0
      wave420l/code/ffmpeg/include/libavutil/sha.h
  67. 75 0
      wave420l/code/ffmpeg/include/libavutil/sha512.h
  68. 41 0
      wave420l/code/ffmpeg/include/libavutil/time.h
  69. 140 0
      wave420l/code/ffmpeg/include/libavutil/timecode.h
  70. 74 0
      wave420l/code/ffmpeg/include/libavutil/timestamp.h
  71. 153 0
      wave420l/code/ffmpeg/include/libavutil/version.h
  72. 62 0
      wave420l/code/ffmpeg/include/libavutil/xtea.h
  73. 94 0
      wave420l/code/sample/Android.mk
  74. 22 0
      wave420l/code/sample/helper/bitstream/binaryreader.c
  75. 505 0
      wave420l/code/sample/helper/bitstream/bitstreamfeeder.c
  76. 165 0
      wave420l/code/sample/helper/bitstream/bitstreamreader.c
  77. 144 0
      wave420l/code/sample/helper/bitstream/bsfeeder_fixedsize_impl.c
  78. 1061 0
      wave420l/code/sample/helper/bitstream/bsfeeder_framesize_impl.c
  79. 124 0
      wave420l/code/sample/helper/bitstream/bsfeeder_size_plus_es_impl.c
  80. 140 0
      wave420l/code/sample/helper/comparator/bin_comparator_impl.c
  81. 339 0
      wave420l/code/sample/helper/comparator/comparator.c
  82. 183 0
      wave420l/code/sample/helper/comparator/md5_comparator_impl.c
  83. 324 0
      wave420l/code/sample/helper/comparator/yuv_comparator_impl.c
  84. 858 0
      wave420l/code/sample/helper/display/fbdev_impl.c
  85. 163 0
      wave420l/code/sample/helper/display/hdmi_impl.c
  86. 373 0
      wave420l/code/sample/helper/display/simplerenderer.c
  87. 2041 0
      wave420l/code/sample/helper/main_helper.c
  88. 1890 0
      wave420l/code/sample/helper/main_helper.h
  89. 1681 0
      wave420l/code/sample/helper/misc/cfgParser.c
  90. 17 0
      wave420l/code/sample/helper/misc/cnm_fpga.c
  91. 2002 0
      wave420l/code/sample/helper/misc/cnm_video_helper.c
  92. 289 0
      wave420l/code/sample/helper/misc/container.c
  93. 211 0
      wave420l/code/sample/helper/misc/datastructure.c
  94. 1225 0
      wave420l/code/sample/helper/misc/debug.c
  95. 54 0
      wave420l/code/sample/helper/misc/debug.h
  96. 154 0
      wave420l/code/sample/helper/misc/getopt.c
  97. 37 0
      wave420l/code/sample/helper/misc/getopt.h
  98. 242 0
      wave420l/code/sample/helper/misc/getopt_long.c
  99. 238 0
      wave420l/code/sample/helper/misc/header_struct.h
  100. 288 0
      wave420l/code/sample/helper/misc/md5.c

+ 17 - 0
wave420l/code/TestRunnerParamWave420lEnc.txt

@@ -0,0 +1,17 @@
+default=0                        #Default Option test:
+                                 #default=0   off
+                                 #default=1   on
+                                 #-99 all random
+                                 
+secondary-axi=0                  #0 ~ 7,(bitmask - 0x01:IMD, 0x02:RDO, 0x04:LF),  -99(random)
+
+yuv_src_mode=0                   #0:planar, 1:nv12, 2:nv21, 3:YUYV(packed), 4:YVYU, 5:UYVY, 6:VYUY      -99(random)
+srcFormat3p4b=0                  #three pixel four bytes                          -99(random)
+stream-endian=31                 #16 ~ 31,                                        -99(random)
+frame-endian=31                  #16 ~ 31,                                        -99(random)
+source-endian=31                 #16 ~ 31,                                        -99(random)
+rotAngle=0                       # 0, 90, 180, 270,                               -99(random)
+mirDir=0                         # 0 ~ 3,                                         -99(random)
+bsmode=1                         #0:ringbuffer, 1:linebuffer                      -99(random)
+
+MODE_COMP_ENCODED=1              #-c  compare between FPGA output & ref-c output

+ 437 - 0
wave420l/code/TestRunnerWave420lEnc.sh

@@ -0,0 +1,437 @@
+#!/bin/bash
+
+source common.sh
+
+# default values
+g_product_name="wave4"
+test_exec="./w4_enc_test"
+wiki_log_file="./log/enc_confluence.log"
+enable_random=0;
+txt_param_switch=0;
+secondary_axi_def=0 
+build_stream=0
+cfg_dir=./cfg
+yuv_base_path=./yuv
+if [ "${OS}" = "Windows_NT" ]; then
+    ref_c_exec=./hevc_enc.exe
+else
+    ref_c_exec=./hevc_enc
+fi
+
+ACLK_MAX=27
+BCLK_MAX=27
+CCLK_MAX=21
+MCLK_MAX=29
+VCLK_MAX=29
+cframe50d_temp=0
+
+function help {
+    echo ""
+    echo "-------------------------------------------------------------------------------"
+    echo "Chips&Media conformance Tool v2.0"
+    echo "All copyright reserved by Chips&Media"
+    echo "-------------------------------------------------------------------------------"
+    echo "$0 OPTION streamlist_file"
+    echo "-h              help"
+    echo "--yuv-dir       input yuv directory"
+    echo "--ref-dir       ref-c directory"
+    echo "--bin-dir       ref-c directory"
+    echo "--enable-random [optional] generate random opton"
+    echo "--build-stream  Just generate golden stream with Ref-C."
+}
+
+
+OPTSTRING="-o hn:c:"
+#ifdef SUPPORT_CONFTEST
+OPTSTRING="${OPTSTRING}t"
+#endif
+OPTSTRING="${OPTSTRING} -l jump-stream:,bsmode:,enable-random,md5-dir:,yuv-dir:,build-stream,ref-dir:,wiki:,n:"
+OPTS=`getopt $OPTSTRING -- "$@"`
+
+if [ $? != 0 ]; then
+    exit 1;
+fi
+
+eval set -- "$OPTS"
+
+while true; do
+    case "$1" in
+        -h) 
+            help
+            exit 0
+            shift;;
+        -n) 
+            frame_num="-n $2"
+            if [ "$2" = "" ]; then
+                frame_num_refc=""
+            else
+                frame_num_refc="-f $2"
+            fi
+            shift 2;;
+        -c)
+            codec=$(echo $2 | tr '[:upper:]' '[:lower:]')
+            shift 2;;
+        --enable-random)
+            enable_random=1
+            shift;;
+        --yuv-dir)
+            yuv_dir=$2
+            shift 2;;
+        --ref-dir)
+            ref_dir=$2
+            shift 2;;
+        --build-stream)
+            build_stream=1;
+            shift;;
+        --wiki)
+            wiki_log_file=$2
+            shift 2;;
+        --) 
+            shift
+            break;;
+    esac
+done
+
+shift $(($OPTIND - 1))
+
+################################################################################
+# Get param from target text file                                              #
+################################################################################
+input_param_name=TestRunnerParamWave420lEnc.txt
+if [ -f $input_param_name ] && [ $enable_random == 0 ]; then
+    echo "read $input_param_name"
+    while read line; do
+        # remove right comment
+        line=$(echo $line | tr -d '\n')
+        line=$(echo $line | tr -d '\r')
+        line="${line%%\#*}"
+
+        attr=$(echo $line | cut -d'=' -f1)
+        attr=$(echo $attr | tr -d ' ')
+        if [ "$attr" == "enable-cbcrInterleave" ]; then
+            value=$(echo $line | cut -d '=' -f3)
+        else
+            value=$(echo $line | cut -d'=' -f2)
+        fi
+        if [ "$attr" != "MODE_COMP" ]; then
+            value=$(echo $value | tr -d ' ')
+        fi
+
+        case "$attr" in
+            default)                default_opt="$value";;
+            secondary-axi)          secondary_axi_temp="$value";;
+            enable-cbcrInterleave)  nv21_temp="$value";;
+            enable_nv21)                   nv21_temp="$value";;
+            yuv_src_mode)           yuv_src_mode_temp="$value";;
+            srcFormat3p4b)          srcFormat3p4b_temp="$value";;
+            stream-endian)          stream_endian_temp="$value";;
+            source-endian)          source_endian_temp="$value";;
+            frame-endian)           frame_endian_temp="$value";;                  
+            bsmode)                 bsmode_temp="$value";;
+            rotAngle)               rotAngle_temp="$value";;
+            mirDir)                 mirDir_temp="$value";;
+            MODE_COMP_ENCODED)      MODE_COMP_ENCODED_temp="$value";;
+            n)                      frame_num="-n $value"
+                                    if [ "$value" = "0" ]; then
+                                        frame_num_refc=""
+                                    else
+                                        frame_num_refc="-f $value"
+                                    fi;;
+            subFrameSyncEn)         subframe_sync_temp="$value";;
+            cframe50d)              cframe50d_temp=0;;
+            txt-param)              txt_param_switch=1;;
+            *) ;;
+        esac
+    done < $input_param_name
+else
+    if [ ! -f "$input_param_name" ]; then
+        echo " $input_param_name file doesn't exist"; 
+    fi
+fi
+
+streamset_path=$1
+echo "streamset_path=$1"
+streamset_file=`basename ${streamset_path}`
+
+if [ ! -f "${streamset_path}" ]; then
+    echo "No such file: ${streamset_path}"
+    exit 1
+fi
+
+################################################################################
+# Get version information                                                      #
+################################################################################
+if [ $build_stream -eq 0 ]; then
+    get_product_id $test_exec
+    product_id=$?
+    if [ "${g_revision}" = "" ] || [ ${productId} != 6 ]; then
+        echo "Invalid product ID($product_id), expected value(6)"
+        exit 1
+    fi
+fi
+
+################################################################################
+# calculate stream number                                                      #
+################################################################################
+stream_file_array=()
+index=0
+num_of_streams=0
+while read line || [ -n "$line" ]; do
+    line=$(echo $line | tr -d '\n')
+    line=$(echo $line | tr -d '\r')
+    line=${line#*( )}   # remove front whitespace
+    line=$(echo $line | cut -d' ' -f1)
+    firstchar=${line:0:1}
+    case "$firstchar" in
+        "@") break;;        # exit flag
+        "#") continue;;     # comment
+        ";") continue;;     # comment
+        "")  continue;;     # comment
+        *)
+    esac
+    stream_file_array[$index]="$line"
+    index=$(($index + 1))
+done < ${streamset_path}
+
+num_of_streams=${#stream_file_array[@]}
+
+#echo ${stream_file_array[@]}
+
+count=1
+success_count=0
+failure_count=0
+remain_count=${num_of_streams}
+basedir=${basedir//\/}  # remove last delimeter
+
+mkdir -p temp
+mkdir -p output
+mkdir -p log/encoder_conformance
+conf_log_path="log/encoder_conformance/${streamset_file}_r${revision}.log"
+conf_err_log_path="log/encoder_conformance/${streamset_file}_error_r${revision}.log"
+temp_log_path="./temp/temp.log"
+# truncate contents of log file
+echo "" > $conf_log_path
+echo "" > $conf_err_log_path
+echo "" > $temp_log_path
+beginTime=$(date +%s%N)
+
+################################################################################
+# read cfg file.                                                               #
+################################################################################
+for line in ${stream_file_array[@]}; do
+    cfg_path="${cfg_dir}/${line}"
+    cfg_base_path=$(dirname $line)
+    if [ "$cfg_base_path" == "" ]; then
+        cfg_base_path="."
+    fi
+
+    test_param=""
+
+    while read line2; do
+        #remove right comment
+        line2=$(echo $line2 | tr -d '\n')
+        line2=$(echo $line2 | tr -d '\r')
+        line2="${line2%%\#*}"
+
+        attr=$(echo $line2 | cut -d':' -f1)
+        attr=$(echo $attr | tr -d ' ')
+        value=$(echo $line2 | cut -d':' -f2)
+        value=$(echo $value | tr -d ' ')
+
+        value="${value//\"}"
+        case "$attr" in
+            BitstreamFile) 
+                BitstreamFile="$value"
+                ;;
+            InputFile) 
+                input_yuv="$value"
+                ;;
+            SourceWidth) 
+                source_width="$value"
+                ;;
+            SourceHeight) 
+                source_height="$value"
+                ;;
+            WaveFrontSynchro)
+                WaveFrontSynchro="$value"
+                ;;
+            DeSliceMode)
+                deslice_mode="$value"
+                ;;
+            *) ;;
+        esac
+        #echo "attr: $attr, value: $value"
+    done < $cfg_path
+
+#default value
+    MODE_COMP_ENCODED=1            #MODE_COMP_ENCODED(bit_stream)
+    if [ $enable_random == 1 ] && [ $txt_param_switch == 0 ]; then
+        get_random_param 0 $g_product_name
+    else
+        get_default_param 0 $g_product_name
+    fi
+
+    g_secondary_axi=$(($g_secondary_axi >> 1))
+    if [ "$MODE_COMP_CONV_YUV" == "1" ]; then
+        g_subCtuMap=0
+    fi
+
+################################################################################
+# WAVE420L CONSTRAINTS                                                         #
+################################################################################
+    g_rotAngle=0
+    g_mirDir=0
+    g_srcFormat3p4b=0
+    g_bsmode=1
+    g_afbcd=0
+    g_enableWtl=0
+    g_cframe50d=0
+    g_minBurstLength=0
+    g_yuv422=0
+
+################################################################################
+# make argv parameter                                                          #
+################################################################################
+    build_test_param 0 
+    test_param="${test_param} $g_func_ret_str"
+    rot_arg=0
+
+    output_filename="$(basename $line).bin"
+    test_param="${test_param} --output=$output_filename --cfgFileName=$cfg_path"
+    
+    yuv_path="${yuv_base_path}/${input_yuv}"
+
+
+    file_name=${BitstreamFile%.*}
+    file_ext=${BitstreamFile##*.}
+    
+    ref_stream_path="${ref_dir}/${cfg_base_path}/${file_name}_${rot_arg}.${file_ext}"
+
+    test_param="${test_param} --ref_stream_path=${ref_stream_path}"
+
+################################################################################
+# print information                                                            #
+################################################################################
+    log_conf "--------------------------------------------------------------------------------" ${temp_log_path}
+    log_conf "[${count}/${num_of_streams}] ${cfg_path}" ${temp_log_path}
+    log_conf "--------------------------------------------------------------------------------" ${temp_log_path}
+
+    log_conf "yuv_path          : $yuv_path" $temp_log_path
+    log_conf "ref_stream_path   : $ref_stream_path" $temp_log_path
+    log_conf "width X Height    : $source_width X $source_height" $temp_log_path
+    log_conf "BitstreamFile     : $BitstreamFile" $temp_log_path
+    log_conf "-------------------------------------------" $temp_log_path
+    log_conf "RANDOM TEST       : ${ON_OFF[$enable_random]}" $temp_log_path
+    log_conf "BITSTREAM MODE    : ${ENC_BSMODE_NAME[$g_bsmode]}" $temp_log_path
+    log_conf "Endian            : ${g_stream_endian}, ${g_frame_endian}, ${g_source_endian}" $temp_log_path
+    log_conf "Standard          : HEVC" $temp_log_path
+    if  [ "$g_packedFormat" == "1" ]; then
+        log_conf "YUV Format        : (${g_packedFormat})YUYV" $temp_log_path
+    elif  [ "$g_packedFormat" == "2" ]; then
+        log_conf "YUV Format        : (${g_packedFormat})YVYU" $temp_log_path
+    elif  [ "$g_packedFormat" == "3" ]; then
+        log_conf "YUV Format        : (${g_packedFormat})UYVY" $temp_log_path
+    elif  [ "$g_packedFormat" == "4" ]; then
+        log_conf "YUV Format        : (${g_packedFormat})VYUY" $temp_log_path
+    elif [ "$g_enable_nv21" == "0" ] || [ "$g_enable_nv21" == "1" ]; then
+        log_conf "YUV Format        : cbcrInterleave nv21=${g_enable_nv21}" $temp_log_path
+    else
+        log_conf "YUV Format        : 420 Planar" $temp_log_path
+    fi
+    log_conf "rot_arg           : $rot_arg" $temp_log_path
+    log_conf "--------------------------------------------------------------------------------" $temp_log_path
+    cat $temp_log_path >> $conf_log_path
+
+################################################################################
+# make ref-prebuilt stream                                                     #
+################################################################################
+    if [ ! -f "$ref_stream_path" ] || [ $build_stream -eq 1 ]; then
+        ref_stream_base_dir=$(dirname $ref_stream_path)
+        if [ ! -d "$ref_stream_base_dir" ]; then
+            mkdir -p "$ref_stream_base_dir"
+	        chmod 755 "$ref_stream_base_dir"
+            echo "CREATE REF-STREAM DIR: $ref_stream_base_dir"
+        fi
+        echo "$ref_c_exec -c $cfg_path -p $yuv_base_path -b temp.bin --PrpMode=$rot_arg $extra_param --enable_fbc=0 --TLevel=0 --DumpPicOut=1 --ApiScenario=0 -t ./ $frame_num_refc"
+        rm -rf vcpu_pic_out_qc.txt
+        $ref_c_exec -c $cfg_path -p $yuv_base_path -b temp.bin --PrpMode=$rot_arg $extra_param --enable_fbc=0 --TLevel=0 --DumpPicOut=1 --ApiScenario=0 -t ./ $frame_num_refc
+
+        cp -v temp.bin $ref_stream_path
+        cp -v vcpu_pic_out_qc.txt $recon_md5_base_path/${file_name}.265_0.txt
+
+        if [ $build_stream -eq 1 ]; then
+            remain_count=$(($remain_count - 1))
+            count=$(($count + 1))
+            continue
+        fi
+    fi
+
+################################################################################
+# run Test                                                                     #
+################################################################################
+    result=0
+    test_param_print=$test_param
+    log_conf "$test_exec $test_param_print" $temp_log_path
+    cat $temp_log_path >> $conf_log_path
+
+    test_exec_param="$test_exec $test_param"
+    $test_exec_param || result=1
+
+    if [ "$result" == "0" ]; then
+        log_conf "[RESULT] SUCCESS" $conf_log_path
+        success_count=$(($success_count + 1))
+    else
+        cat ./ErrorLog.txt >> $conf_log_path
+        log_conf "[RESULT] FAILURE" $conf_log_path
+        failure_count=$(($failure_count + 1))
+        cat $temp_log_path >> $conf_err_log_path
+        cat ./ErrorLog.txt >> $conf_err_log_path
+        echo "[RESULT] FAILURE" >> $conf_err_log_path
+        if [ $result -eq 10 ]; then
+            echo "Abnormal exit!!!"
+            break
+        fi
+    fi
+    remain_count=$(($remain_count - 1))
+    count=$(($count + 1))
+    # clear temp log
+    echo "" > $temp_log_path
+done 
+
+endTime=$(date +%s%N)
+elapsed=$((($endTime - $beginTime) / 1000000000))
+elapsedH=$(($elapsed / 3600))
+elapsedS=$(($elapsed % 60))
+elapsedM=$(((($elapsed - $elapsedS) / 60) % 60))
+if [ "$((elapsedS / 10))" == "0" ]; then elapsedS="0${elapsedS}" ;fi
+if [ "$((elapsedM / 10))" == "0" ]; then elapsedM="0${elapsedM}" ;fi
+if [ "$((elapsedH / 10))" == "0" ]; then elapsedH="0${elapsedH}" ;fi
+
+if [ $elapsed -le 60 ]; then
+    time_hms="{color:red}*${elapsedH}:${elapsedM}:${elapsedS}*{color}"
+else
+    time_hms="${elapsedH}:${elapsedM}:${elapsedS}"
+fi
+
+log_filename=$(basename $conf_log_path)
+log_err_filename=$(basename $conf_err_log_path)
+if [ $failure_count == 0 ] && [ $num_of_streams != 0 ]; then
+    pass=${PASS}
+    rm $conf_err_log_path
+    log_err_filename=""
+else
+    pass=${FAIL}
+fi
+
+wiki_log="| $streamset_file | $num_of_streams | $success_count | $failure_count | $remain_count | $log_filename | ${log_err_filename} | $pass | $time_hms | | | |"
+
+echo $wiki_log
+echo $wiki_log >> $wiki_log_file
+
+if [ "$num_of_streams" == "0" ]; then
+    echo "num_of_streams: $num_of_streams = exit 1"
+    exit 1
+fi
+
+exit $failure_count
+ 

+ 271 - 0
wave420l/code/Wave420Enc.mak

@@ -0,0 +1,271 @@
+# ----------------------------------------------------------------------
+#
+# Project: C&M Video encoder sample
+#
+# ----------------------------------------------------------------------
+.PHONY: create_dir force_dependency
+
+USE_FFMPEG  = yes
+USE_PTHREAD = yes
+
+UNAME = $(shell uname -a)
+ifneq (,$(findstring i386, $(UNAME)))
+    USE_32BIT = yes
+endif
+
+
+ifeq ($(USE_32BIT), yes)
+PLATFORM    = nativelinux
+else
+PLATFORM    = nativelinux_64bit
+endif
+
+CROSS_CC_PREFIX = 
+VDI_C           = vdi/linux/vdi.c
+VDI_OSAL_C      = vdi/linux/vdi_osal.c
+MM_C            = 
+PLATFORM_FLAGS  = 
+
+ifeq ("$(BUILD_CONFIGURATION)", "NonOS")
+    CROSS_CC_PREFIX = arm-none-eabi-
+    VDI_C           = vdi/nonos/vdi.c
+    VDI_OSAL_C      = vdi/nonos/vdi_osal.c
+    MM_C            = vdi/mm.c
+    USE_FFMPEG      = no
+    USE_PTHREAD     = no
+    PLATFORM        = none
+    DEFINES         = -DLIB_C_STUB
+    PLATFORM_FLAGS  = 
+endif
+ifeq ("$(BUILD_CONFIGURATION)", "EmbeddedLinux")
+    CROSS_CC_PREFIX = arm-none-linux-gnueabi-
+    PLATFORM        = armlinux
+endif
+
+CC  = $(CROSS_CC_PREFIX)gcc
+CXX = $(CROSS_CC_PREFIX)g++
+LINKING=$(CC)
+AR  = $(CROSS_CC_PREFIX)ar
+
+INCLUDES = -I./theoraparser/include -I./vpuapi -I./ffmpeg/include -I./sample/helper -I./vdi
+DEFINES += -DWAVE420
+
+
+CFLAGS  += -g -I. -Wno-implicit-function-declaration -Wno-format -Wl,--fatal-warning $(INCLUDES) $(DEFINES) $(PLATFORM_FLAGS)
+ARFLAGS += cru
+
+LDFLAGS  += $(PLATFORM_FLAGS) -L./theoraparser/
+LDLIBS   += -ltheoraparser
+
+
+ifeq ($(USE_FFMPEG), yes)
+LDLIBS  += -lavformat -lavcodec -lavutil
+LDFLAGS += -L./ffmpeg/lib/$(PLATFORM)
+ifneq ($(USE_32BIT), yes)
+LDLIBS  += -lz
+endif #USE_32BIT
+endif #USE_FFMPEG
+
+ifeq ($(USE_PTHREAD), yes)
+LDLIBS  += -lpthread
+endif
+LDLIBS  += -lm
+
+
+TARGET=w4_enc_test
+MAKEFILE=Wave420Enc.mak
+OBJDIR=obj
+ALLOBJS=*.o
+ALLDEPS=*.dep
+ALLLIBS=*.a
+RM=rm -f
+MKDIR=mkdir -p
+
+SOURCES = sample/main_w4_enc_test.c                    	    \
+          sample/helper/main_helper.c                       \
+          sample/helper/vpuhelper.c                         \
+          sample/helper/bitstream/bitstreamfeeder.c         \
+          sample/helper/bitstream/bitstreamreader.c         \
+          sample/helper/bitstream/binaryreader.c            \
+          sample/helper/bitstream/bsfeeder_fixedsize_impl.c \
+          sample/helper/bitstream/bsfeeder_framesize_impl.c \
+          sample/helper/bitstream/bsfeeder_size_plus_es_impl.c \
+          sample/helper/comparator/bin_comparator_impl.c    \
+          sample/helper/comparator/comparator.c             \
+          sample/helper/comparator/md5_comparator_impl.c    \
+          sample/helper/comparator/yuv_comparator_impl.c    \
+          sample/helper/display/fbdev_impl.c                \
+          sample/helper/display/hdmi_impl.c                 \
+          sample/helper/display/simplerenderer.c            \
+          sample/helper/misc/cfgParser.c                    \
+          sample/helper/misc/cnm_fpga.c                     \
+          sample/helper/misc/cnm_video_helper.c             \
+          sample/helper/misc/container.c                    \
+          sample/helper/misc/datastructure.c                \
+          sample/helper/misc/platform.c                     \
+          sample/helper/misc/pbu.c                          \
+          sample/helper/misc/debug.c                        \
+          sample/helper/yuv/yuvfeeder.c                     \
+          sample/helper/yuv/yuvLoaderfeeder.c               
+SOURCES += $(VDI_C)                                         \
+          $(VDI_OSAL_C)                                     \
+          $(MM_C)                                           \
+          vpuapi/product.c                                  \
+          vpuapi/vpuapifunc.c                               \
+          vpuapi/vpuapi.c                                   \
+          vpuapi/coda9/coda9.c                              \
+          vpuapi/wave/common/common.c                       \
+          vpuapi/wave/coda7q/coda7q.c                       \
+          vpuapi/wave/wave4/wave4.c                         \
+          vpuapi/wave/wave5/wave5.c
+
+
+OBJECTNAMES=$(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(SOURCES)))
+OBJECTPATHS=$(addprefix $(OBJDIR)/,$(notdir $(OBJECTNAMES)))
+
+$(TARGET): create_dir $(OBJECTPATHS) libtheoraparser.a
+	$(LINKING) -o $@ $(LDFLAGS) -Wl,-gc-section -Wl,--start-group $(OBJECTPATHS) $(LDLIBS) -Wl,--end-group
+
+-include $(OBJECTPATHS:.o=.dep)
+
+clean: 
+	$(RM) $(TARGET)
+	$(RM) $(OBJDIR)/$(ALLOBJS)
+	$(RM) $(OBJDIR)/$(ALLDEPS)
+	$(RM) theoraparser/$(ALLOBJS)
+	$(RM) theoraparser/$(ALLLIBS)
+	$(RM) theoraparser/$(ALLDEPS)
+
+libtheoraparser.a: force_dependency
+	cd theoraparser; make 
+
+$(OBJDIR)/main_w4_enc_test.o : sample/main_w4_enc_test.c $(MAKEFILE)
+	$(CC) $(CFLAGS) -Wall -Werror -c $< -o $@ -MD -MF $(@:.o=.dep)
+
+$(OBJDIR)/main_helper.o : sample/helper/main_helper.c $(MAKEFILE)
+	$(CC) $(CFLAGS) -Wall -Werror -c $< -o $@ -MD -MF $(@:.o=.dep)
+
+$(OBJDIR)/vpuhelper.o : sample/helper/vpuhelper.c $(MAKEFILE)
+	$(CC) $(CFLAGS) -Wall -Werror -c $< -o $@ -MD -MF $(@:.o=.dep)
+
+
+$(OBJDIR)/bitstreamfeeder.o : sample/helper/bitstream/bitstreamfeeder.c $(MAKEFILE)
+	$(CC) $(CFLAGS) -Wall -Werror -c $< -o $@ -MD -MF $(@:.o=.dep)
+
+$(OBJDIR)/bitstreamreader.o : sample/helper/bitstream/bitstreamreader.c $(MAKEFILE)
+	$(CC) $(CFLAGS) -Wall -Werror -c $< -o $@ -MD -MF $(@:.o=.dep)
+
+$(OBJDIR)/binaryreader.o : sample/helper/bitstream/binaryreader.c $(MAKEFILE)
+	$(CC) $(CFLAGS) -Wall -Werror -c $< -o $@ -MD -MF $(@:.o=.dep)
+
+$(OBJDIR)/bsfeeder_fixedsize_impl.o : sample/helper/bitstream/bsfeeder_fixedsize_impl.c $(MAKEFILE)
+	$(CC) $(CFLAGS) -Wall -Werror -c $< -o $@ -MD -MF $(@:.o=.dep)
+
+$(OBJDIR)/bsfeeder_framesize_impl.o : sample/helper/bitstream/bsfeeder_framesize_impl.c $(MAKEFILE)
+	$(CC) $(CFLAGS) -Wall -Werror -c $< -o $@ -MD -MF $(@:.o=.dep)
+
+$(OBJDIR)/bsfeeder_size_plus_es_impl.o : sample/helper/bitstream/bsfeeder_size_plus_es_impl.c $(MAKEFILE)
+	$(CC) $(CFLAGS) -Wall -Werror -c $< -o $@ -MD -MF $(@:.o=.dep)
+
+$(OBJDIR)/bin_comparator_impl.o : sample/helper/comparator/bin_comparator_impl.c $(MAKEFILE)
+	$(CC) $(CFLAGS) -Wall -Werror -c $< -o $@ -MD -MF $(@:.o=.dep)
+
+$(OBJDIR)/comparator.o : sample/helper/comparator/comparator.c $(MAKEFILE)
+	$(CC) $(CFLAGS) -Wall -Werror -c $< -o $@ -MD -MF $(@:.o=.dep)
+
+$(OBJDIR)/md5_comparator_impl.o : sample/helper/comparator/md5_comparator_impl.c $(MAKEFILE)
+	$(CC) $(CFLAGS) -Wall -Werror -c $< -o $@ -MD -MF $(@:.o=.dep)
+
+$(OBJDIR)/yuv_comparator_impl.o : sample/helper/comparator/yuv_comparator_impl.c $(MAKEFILE)
+	$(CC) $(CFLAGS) -Wall -Werror -c $< -o $@ -MD -MF $(@:.o=.dep)
+
+
+$(OBJDIR)/fbdev_impl.o : sample/helper/display/fbdev_impl.c $(MAKEFILE)
+	$(CC) $(CFLAGS) -Wall -Werror -c $< -o $@ -MD -MF $(@:.o=.dep)
+
+$(OBJDIR)/hdmi_impl.o : sample/helper/display/hdmi_impl.c $(MAKEFILE)
+	$(CC) $(CFLAGS) -Wall -Werror -c $< -o $@ -MD -MF $(@:.o=.dep)
+
+$(OBJDIR)/mixer.o : sample/helper/display/mixer.c $(MAKEFILE)
+	$(CC) $(CFLAGS) -Wall -Werror -c $< -o $@ -MD -MF $(@:.o=.dep)
+
+$(OBJDIR)/simplerenderer.o : sample/helper/display/simplerenderer.c $(MAKEFILE)
+	$(CC) $(CFLAGS) -Wall -Werror -c $< -o $@ -MD -MF $(@:.o=.dep)
+
+
+$(OBJDIR)/cfgParser.o : sample/helper/misc/cfgParser.c $(MAKEFILE)
+	$(CC) $(CFLAGS) -Wall -Werror -c $< -o $@ -MD -MF $(@:.o=.dep)
+
+$(OBJDIR)/cnm_fpga.o : sample/helper/misc/cnm_fpga.c $(MAKEFILE)
+	$(CC) $(CFLAGS) -Wall -Werror -c $< -o $@ -MD -MF $(@:.o=.dep)
+
+$(OBJDIR)/cnm_video_helper.o : sample/helper/misc/cnm_video_helper.c $(MAKEFILE)
+	$(CC) $(CFLAGS) -Wall -Werror -c $< -o $@ -MD -MF $(@:.o=.dep)
+
+$(OBJDIR)/container.o : sample/helper/misc/container.c $(MAKEFILE)
+	$(CC) $(CFLAGS) -Wall -Werror -c $< -o $@ -MD -MF $(@:.o=.dep)
+
+$(OBJDIR)/datastructure.o : sample/helper/misc/datastructure.c $(MAKEFILE)
+	$(CC) $(CFLAGS) -Wall -Werror -c $< -o $@ -MD -MF $(@:.o=.dep)
+
+$(OBJDIR)/platform.o : sample/helper/misc/platform.c $(MAKEFILE)
+	$(CC) $(CFLAGS) -Wall -Werror -c $< -o $@ -MD -MF $(@:.o=.dep)
+
+$(OBJDIR)/pbu.o : sample/helper/misc/pbu.c $(MAKEFILE)
+	$(CC) $(CFLAGS) -Wall -Werror -c $< -o $@ -MD -MF $(@:.o=.dep)
+
+$(OBJDIR)/yuvfeeder.o : sample/helper/yuv/yuvfeeder.c $(MAKEFILE)
+	$(CC) $(CFLAGS) -Wall -Werror -c $< -o $@ -MD -MF $(@:.o=.dep)
+
+$(OBJDIR)/yuvLoaderfeeder.o : sample/helper/yuv/yuvLoaderfeeder.c $(MAKEFILE)
+	$(CC) $(CFLAGS) -Wall -Werror -c $< -o $@ -MD -MF $(@:.o=.dep)
+
+$(OBJDIR)/debug.o : sample/helper/misc/debug.c $(MAKEFILE)
+	$(CC) $(CFLAGS) -Wall -Werror -c $< -o $@ -MD -MF $(@:.o=.dep)
+
+
+
+
+$(OBJDIR)/vdi.o : $(VDI_C) $(MAKEFILE)
+	$(CC) $(CFLAGS) -Wall -Werror -c $< -o $@ -MD -MF $(@:.o=.dep)
+
+$(OBJDIR)/vdi_osal.o : $(VDI_OSAL_C) $(MAKEFILE)
+	$(CC) $(CFLAGS) -Wall -Werror -c $< -o $@ -MD -MF $(@:.o=.dep)
+
+ifneq ("$(MM_C)", "")
+$(OBJDIR)/mm.o : $(MM_C) $(MAKEFILE)
+	$(CC) $(CFLAGS) -Wall -Werror -c $< -o $@ -MD -MF $(@:.o=.dep)
+endif
+
+$(OBJDIR)/product.o : vpuapi/product.c $(MAKEFILE)
+	$(CC) $(CFLAGS) -Wall -Werror -c $< -o $@ -MD -MF $(@:.o=.dep)
+
+$(OBJDIR)/vpuapifunc.o : vpuapi/vpuapifunc.c $(MAKEFILE)
+	$(CC) $(CFLAGS) -Wall -Werror -c $< -o $@ -MD -MF $(@:.o=.dep)
+
+$(OBJDIR)/vpuapi.o : vpuapi/vpuapi.c $(MAKEFILE)
+	$(CC) $(CFLAGS) -Wall -Werror -c $< -o $@ -MD -MF $(@:.o=.dep)
+
+$(OBJDIR)/coda9.o : vpuapi/coda9/coda9.c $(MAKEFILE)
+	$(CC) $(CFLAGS) -Wall -Werror -c $< -o $@ -MD -MF $(@:.o=.dep)
+
+$(OBJDIR)/common.o : vpuapi/wave/common/common.c $(MAKEFILE)
+	$(CC) $(CFLAGS) -Wall -Werror -c $< -o $@ -MD -MF $(@:.o=.dep)
+
+$(OBJDIR)/coda7q.o : vpuapi/wave/coda7q/coda7q.c $(MAKEFILE)
+	$(CC) $(CFLAGS) -Wall -Werror -c $< -o $@ -MD -MF $(@:.o=.dep)
+
+$(OBJDIR)/wave4.o : vpuapi/wave/wave4/wave4.c $(MAKEFILE)
+	$(CC) $(CFLAGS) -Wall -Werror -c $< -o $@ -MD -MF $(@:.o=.dep)
+
+$(OBJDIR)/wave5.o : vpuapi/wave/wave5/wave5.c $(MAKEFILE)
+	$(CC) $(CFLAGS) -Wall -Werror -c $< -o $@ -MD -MF $(@:.o=.dep)
+
+create_dir:
+ifeq (,$(findstring $(OBJDIR),$(wildcard $(OBJDIR) )))
+	-mkdir -p $(OBJDIR)
+endif
+
+force_dependency : 
+	true
+

+ 48 - 0
wave420l/code/cfg/rc_cu_1A_8b.cfg

@@ -0,0 +1,48 @@
+BitstreamFile : rc_cu_1A_8b.cfg.265
+InputFile : foreman_256x128.yuv
+SourceWidth : 256
+SourceHeight : 128
+InputBitDepth : 8
+FrameRate : 30
+FrameSkip : 0
+FramesToBeEncoded : 30
+IntraPeriod : 32
+DecodingRefreshType : 1
+DeriveLambdaWeight : 1
+GOPSize : 1
+Frame1: P 1 0 0.5 0 0
+EnIntraInInterSlice : 1
+ConstrainedIntraPred : 0
+IntraCtuRefreshMode : 0
+IntraCtuRefreshArg : 0
+EnCu8x8 : 1
+EnCu16x16 : 1
+MaxNumMerge : 2
+EnDynMerge : 0
+EnTemporalMVP : 1
+QP : 32
+ScalingList : 0
+IndeSliceMode : 0
+IndeSliceArg : 0
+DeSliceMode : 0
+DeSliceArg : 0
+EnDBK : 1
+LFCrossSliceBoundaryFlag : 1
+BetaOffsetDiv2 : 0
+TcOffsetDiv2 : 0
+WaveFrontSynchro : 0
+LosslessCoding : 0
+UsePresetEncTools : 0
+NumTemporalLayers : 1
+GopPreset : 0
+RateControl : 1
+EncBitrate : 33974000
+TransBitrate : 33974000
+InitialDelay : 500
+InitBufLevelx8 : 1
+CULevelRateControl : 1
+EnHvsQp : 1
+BitAllocMode : 0
+IntraQpOffset : 0
+EnRoi : 0
+RoiDeltaQP : 3

+ 46 - 0
wave420l/code/cfg/set1_001A.cfg

@@ -0,0 +1,46 @@
+BitstreamFile : set1_001A.cfg.265
+InputFile : foreman_256x128.yuv
+SourceWidth : 256
+SourceHeight : 128
+InputBitDepth : 8
+FrameRate : 30
+FrameSkip : 0
+FramesToBeEncoded : 30
+IntraPeriod : 1
+DecodingRefreshType : 0
+DeriveLambdaWeight : 0
+GOPSize : 1
+EnIntraInInterSlice : 1
+ConstrainedIntraPred : 0
+IntraCtuRefreshMode : 0
+IntraCtuRefreshArg : 0
+EnCu8x8 : 1
+EnCu16x16 : 1
+MaxNumMerge : 2
+EnDynMerge : 0
+EnTemporalMVP : 1
+QP : 20
+ScalingList : 0
+IndeSliceMode : 0
+IndeSliceArg : 0
+DeSliceMode : 0
+DeSliceArg : 0
+EnDBK : 1
+LFCrossSliceBoundaryFlag : 1
+BetaOffsetDiv2 : 0
+TcOffsetDiv2 : 0
+WaveFrontSynchro : 0
+LosslessCoding : 0
+UsePresetEncTools : 0
+NumTemporalLayers : 1
+GopPreset : 0
+RateControl : 0
+EncBitrate : 0
+TransBitrate : 0
+InitialDelay : 3000
+InitBufLevelx8 : 1
+CULevelRateControl : 1
+EnHvsQp : 1
+BitAllocMode : 0
+IntraQpOffset : 0
+NumRoi : 0

+ 2 - 0
wave420l/code/cmd/hevc_enc_test.cmd

@@ -0,0 +1,2 @@
+set1_001A.cfg
+rc_cu_1A_8b.cfg

+ 1685 - 0
wave420l/code/common.sh

@@ -0,0 +1,1685 @@
+###############################################################################
+# COMMON DATA
+###############################################################################
+ON_OFF=(
+    "OFF"
+    "ON"
+)
+
+readonly C_YUV_8B_P420=0
+readonly C_YUV_8B_P422=1
+readonly C_YUV_10B_MSB_P420=5
+readonly C_YUV_10B_LSB_P420=6
+readonly C_YUV_3P4B_MSB_P420=7          # each pixel 10bit
+readonly C_YUV_3P4B_LSB_P420=8          # each pixel 10bit
+readonly C_YUV_10B_MSB_P422=9
+readonly C_YUV_10B_LSB_P422=10
+readonly C_YUV_3P4B_MSB_P422=11         # each pixel 10bit
+readonly C_YUV_3P4B_LSB_P422=12         # each pixel 10bit
+
+readonly C_YUV_8B_YUYV=13         
+readonly C_YUV_10B_MSB_YUYV=14
+readonly C_YUV_10B_LSB_YUYV=15
+readonly C_YUV_3P4B_MSB_YUYV=16
+readonly C_YUV_3P4B_LSB_YUYV=17
+
+readonly C_YUV_8B_YVYU=18         
+readonly C_YUV_10B_MSB_YVYU=19
+readonly C_YUV_10B_LSB_YVYU=20
+readonly C_YUV_3P4B_MSB_YVYU=21
+readonly C_YUV_3P4B_LSB_YVYU=22
+
+readonly C_YUV_8B_UYVY=23 
+readonly C_YUV_10B_MSB_UYVY=24
+readonly C_YUV_10B_LSB_UYVY=25
+readonly C_YUV_3P4B_MSB_UYVY=26
+readonly C_YUV_3P4B_LSB_UYVY=27
+
+readonly C_YUV_8B_VYUY=28 
+readonly C_YUV_10B_MSB_VYUY=29
+readonly C_YUV_10B_LSB_VYUY=30
+readonly C_YUV_3P4B_MSB_VYUY=31
+readonly C_YUV_3P4B_LSB_VYUY=32
+
+readonly CODA_MIN_ENDIAN=0
+readonly CODA_MAX_ENDIAN=3
+readonly WAVE_MIN_ENDIAN=16
+readonly WAVE_MAX_ENDIAN=31
+
+readonly CODA_SEC_AXI_MAX=63
+readonly SCALER_SEC_AXI_MAX=15
+readonly BWB_SECONDARY_AXI_MAX=7
+
+YUV_FORMAT_LIST=(
+    "FORMAT_420"
+    "RESERVED"
+    "RESERVED"
+    "RESERVED"
+    "RESERVED"
+    "FORMAT_420_P10_16BIT_MSB"
+    "FORMAT_420_P10_16BIT_LSB"
+    "FORMAT_420_P10_32BIT_MSB"
+    "FORMAT_420_P10_32BIT_LSB"
+)
+
+YUV_FORMAT_LIST_8BIT=(
+    "FORMAT_420"
+)
+
+
+AFBCE_FORMAT_NAME=(
+    "NONE"
+    "AFBCE_FORMAT_8BIT"
+    "AFBCE_FORMAT_10BIT"
+)
+
+C9_ENDIAN_NAME=(
+    "VDI_64BIT_LE"
+    "VDI_64BIT_BE"
+    "VDI_32BIT_LE"
+    "VDI_32BIT_BE"
+)
+
+W4_ENDIAN_NAME=(
+    "VDI_128BIT_BIG_ENDIAN"
+    "VDI_128BIT_BE_BYTE_SWAP"
+    "VDI_128BIT_BE_WORD_SWAP"
+    "VDI_128BIT_BE_WORD_BYTE_SWAP"
+    "VDI_128BIT_BE_DWORD_SWAP"
+    "VDI_128BIT_BE_DWORD_BYTE_SWAP"
+    "VDI_128BIT_BE_DWORD_WORD_SWAP"
+    "VDI_128BIT_BE_DWORD_WORD_BYTE_SWAP"
+    "VDI_128BIT_LE_DWORD_WORD_BYTE_SWAP"
+    "VDI_128BIT_LE_DWORD_WORD_SWAP"
+    "VDI_128BIT_LE_DWORD_BYTE_SWAP"
+    "VDI_128BIT_LE_DWORD_SWAP"
+    "VDI_128BIT_LE_WORD_BYTE_SWAP"
+    "VDI_128BIT_LE_WORD_SWAP"
+    "VDI_128BIT_LE_BYTE_SWAP"
+    "VDI_128BIT_LITTLE_ENDIAN"
+)
+
+DEC_BSMODE_NAME=(
+    "Interrupt"
+    "Reserved"
+    "PicEnd"
+)
+
+ENC_BSMODE_NAME=(
+    "Ringbuffer"         
+    "Linebuffer"
+)
+
+ENC_WAVE_BSMODE_NAME=(
+    "Linebuffer"
+    "Ringbuffer, Wrap On"
+    "Ringbuffer, Wrap Off"
+)
+
+CODA980_MAPTYPE_NAME=(
+    "LINEAR_FRAME"
+    "TILED_FRAME_V"        
+    "TILED_FRAME_H"        
+    "TILED_FIELD_V"        
+    "TILED_MIXED_V"        
+    "TILED_FRAME_MB_RASTER"
+    "TILED_FIELD_MB_RASTER"
+    "TILED_FRAME_NO_BANK"  
+    "TILED_FIELD_NO_BANK"  
+)
+
+CODA960_MAPTYPE_NAME=(
+    "LINEAR_FRAME"
+    "TILED_FRAME_V"        
+    "TILED_FRAME_H"        
+    "TILED_FIELD_V"        
+    "TILED_MIXED_V"        
+    "TILED_FRAME_MB_RASTER"
+    "TILED_FIELD_MB_RASTER"
+)
+
+MIRROR_NAME=(
+    "NONE"
+    "VERTICAL"
+    "HORIZONTAL"
+    "BOTH"
+)
+
+CODEC_NAME=(
+    "H.264"
+    "VC-1"
+    "MPEG-2"
+    "MPEG-4"
+    "H.263"
+    "DIVX3"
+    "RV"
+    "AVS"
+    "NONE"
+    "THEORA"
+    "NONE"
+    "VP8"
+    "HEVC"
+    "VP9"
+    "AVS2"
+)
+
+
+PASS="PASS"
+FAIL="FAIL"
+
+###############################################################################
+# GLOBAL VARIABLES
+###############################################################################
+g_fpga_reset=0                       # 1 : reset fpga every time
+
+######################## COMMON VARAIABLES FOR DECODER ########################
+g_yuv_fmt_list=("${YUV_FORMAT_LIST[@]}")
+g_match_mode=1                        # 0 - nomatch, 1 - yuv, 2 - md5
+g_aclk_freq=20
+g_bclk_freq=20
+g_cclk_freq=20
+g_mclk_freq=20
+g_vclk_freq=20
+g_read_latency=0
+g_write_latency=0
+g_secondary_axi=0
+g_stream_endian=0
+g_source_endian=0
+g_frame_endian=0
+g_bsmode=0
+g_enable_thumbnail=0
+g_cbcr_interleave=0
+g_enable_nv21=0
+g_enable_wtl=1
+g_wtl_format=0
+g_multi_vcore=0
+g_num_cores=1
+g_bs_size=0
+g_codec_index=0
+#ifdef SUPPORT_CONF_TESET
+g_fake_test=0
+g_skip_test=0
+g_support_minipippen=0
+#endif /* SUPPORT_CONF_TEST */
+g_scaler=0
+g_force_bsmode=0
+g_revision=""
+########################## WAVE4xx DECODER VARAIABLES #########################
+g_tid_test=0
+g_bw_opt=1
+g_afbce=0               # WAVE412 Feature
+g_force_num_cores=0
+
+####################### CODA9&CODA7 DECODER VARAIABLES ########################
+g_maptype_index=0           # CODA9xx feature
+g_enable_tiled2linear=0
+g_enable_deblock=0
+g_enable_dering=0
+g_enable_mvc=0              # H.264 MVC
+g_mp4class=0
+g_maptype_num=1
+g_enable_ppu=1
+
+######################## VARAIABLES FOR WAVE4 ENCODER #########################
+g_subframe_sync=0
+g_packedFormat=0
+g_srcFormat3p4b=0
+######################## VARAIABLES FOR CODA9 ENCODER #########################
+g_enable_linear2tiled=0 
+g_linebuf_int=0
+
+########################## VARAIABLES FOR PPU #################################
+g_rotAngle=0
+g_mirDir=0
+
+
+###############################################################################
+# GLOBAL FUNCTIONS
+###############################################################################
+# ceiling function
+function ceiling {
+    local value=$1
+    local align=$2
+
+    echo "$(((($value+$align-1)/$align)*$align))"
+}
+
+# check_and_create_dir
+function check_and_create_dir {
+    CHECK_PATH=$1
+    if [ ! -d "$CHECK_PATH" ]; then
+        mkdir -p $CHECK_PATH
+        chmod 777 $CHECK_PATH
+        echo "create $CHECK_PATH"
+    else
+        echo "Already $CHECK_PATH Exist"
+    fi
+}
+
+# get_random start end
+# generate constraint random value with @start end @end.
+#
+function get_random {
+    start=$1
+    end=$2
+    size=$(($end - $start + 1))
+    val2=$RANDOM
+    val1=$(($val2 % size))
+    val=$(($start + $val1%$size))
+    echo "$val"
+}
+
+function get_random_min_max {
+    start=$1
+    end=$2
+
+    use_min_max_value=$(($RANDOM % 5))
+    size=$(($end - $start - 1))
+
+    if [ $use_min_max_value = 1 ] || [ $size -le 0 ]; then
+        val2=$RANDOM
+        val1=$(($val2 % 2))
+        if [ $val1 = 1 ]; then
+            val=$end
+        else
+            val=$start
+        fi
+    else
+        val2=$RANDOM
+        val1=$(($val2 % size))
+        val=$(($start + $val1%$size + 1))
+    fi
+
+    echo "$val"
+}
+
+# log_conf log_message log_file
+# write @log_message to @log_file
+#
+function log_conf {
+    echo "$1" | tee -a "$2"
+}
+
+# parse_streamset_file streamset_path *array
+# - parse streamset file and store data into @g_stream_file_array
+# 
+function parse_streamset_file {
+    local f="$1"
+    local index=0
+    local line=""
+    while read -r line || [ -n "$line" ]; do
+        line="${line#*( )}"         # remove front whitespace
+        line="${line%%[ $'\t']*}"   # remove start of whitespace
+        line="${line//\\//}"        # replace backslash to slash
+        line="${line/$'\r'/}"       # remove carriage return
+        firstchar=${line:0:1}
+        case "$firstchar" in
+            "@") break;;        # exit flag
+            "#") continue;;     # comment
+            ";") continue;;     # comment
+            "")  continue;;     # comment
+            *)
+        esac
+        eval $2[$index]="$line"
+        index=$(($index + 1))
+    done < $f
+}
+
+#ifdef SUPPORT_CONF_TESET
+function replace_byte {
+    printf "$(printf '\\x%02X' $3)" | dd of="$1" bs=1 seek=$2 count=1 conv=notrunc &> /dev/null
+}
+
+function get_byte_data {
+    ori_value=$(xxd -s $2 -l 1 $1 | cut -d' ' -f2) #get original value
+    ori_value=$((16#$ori_value))                     #hex to dec
+    echo "$ori_value"
+}
+
+function bit_toggle {
+    local ori_byte=$1
+    local bit_pos=$2
+
+    (($ori_byte&((1<<$bit_pos)))) && temp=1 || temp=0 #bit exist check
+
+    out=$(($ori_byte - ((1<<$bit_pos))))
+    if [ "$temp" == "1" ];then  #bit exist -> clear bit
+        out=$((1 << $bit_pos))
+        out=$(($ori_byte - $out))
+    else                        #bit not exit -> set bit
+        out=$((1 << $bit_pos))
+        out=$(($ori_byte + $out))
+    fi
+    echo "$out"
+}
+
+#make error_stream
+function make_error_stream {
+    local filename=$1
+    local byte_cnt=$2
+
+    if [ $codec == "hevc" ]; then
+        # 128KB. 
+        start_ofs_ori=131072
+    elif [ $codec == "vp9" ]; then
+        start_ofs_ori=4096
+    else
+        start_ofs_ori=4096
+    fi
+    start_ofs=$start_ofs_ori
+    four_MB_ofs=4194304 #4MB
+    size=$(stat -c%s "$filename") #get file size
+    echo "Size of $filename = $size bytes."
+    #get mininum between four_MB_ofs & file size
+    end_ofs=$([ $four_MB_ofs -le $size ] && echo "$four_MB_ofs" || echo "$size")
+
+    div=$(($end_ofs-$start_ofs))
+
+    echo "whole div=$div"
+    echo "end_ofs=$end_ofs"
+
+    cnt=$(($div / $byte_cnt))
+    echo "length div=$div"
+
+    echo "tot_change_byte_cnt=$cnt"
+
+#generating the random value array
+    for ((i=0;i<$cnt;i++)); do
+        start_ofs=$(($start_ofs_ori + $(($byte_cnt * $i))))
+        end_ofs=$(($start_ofs_ori + $(( $(($byte_cnt * $i)) + $byte_cnt )) ))
+
+        ofs[$i]=$(get_random $start_ofs $end_ofs)
+        ori_value[$i]=$(get_byte_data $filename $ofs[$i])
+        ch_val[$i]=$(get_random 0 255)
+
+        en_random_one_bit=$(get_random 0 1)
+        change_one_bit_pos=$(get_random 0 7)
+
+        if [ "$en_random_one_bit" == "1" ]; then
+            ch_val[$i]=$(bit_toggle ${ori_value[$i]} $change_one_bit_pos)
+        fi
+
+        echo "------------------------"
+        #echo "between=$start_ofs ~ $end_ofs"
+        #echo "en_random_one_bit=$en_random_one_bit"
+        #echo "change_one_bit_pos=$change_one_bit_pos"
+        printf "ofs=%d(0x%x) bitchange=%d\n" ${ofs[$i]} ${ofs[$i]} $en_random_one_bit
+        printf "val= %d(0x%x) -> %d(0x%x)\n" ${ori_value[$i]} ${ori_value[$i]} ${ch_val[$i]} ${ch_val[$i]}
+        echo "------------------------"
+    done
+
+#######################################
+# copy and paste array
+# copy the array log and paste it here
+#######################################
+
+#printf for regenerating array
+    printf "=============================================================\n"
+    printf "make random err array log start\n"
+    printf "copy below log data and paste it to the 'copy and paste area'\n"
+    printf "=============================================================\n"
+    printf "cnt=%d\n" $cnt
+    printf "ofs=("
+    for ((i=0;i<$cnt;i++)); do
+        if [ $(($i % 10))  == 0 ]; then
+            printf " %d %d %d %d %d %d %d %d %d %d\n" ${ofs[$i]} ${ofs[(($i+1))]} ${ofs[(($i+2))]} ${ofs[(($i+3))]} ${ofs[(($i+4))]}  ${ofs[(($i+5))]}  ${ofs[(($i+6))]}  ${ofs[(($i+7))]}  ${ofs[(($i+8))]}  ${ofs[(($i+9))]}
+        fi
+    done
+    printf ")\n"
+    printf "ch_val=("
+    for ((i=0;i<$cnt;i++)); do
+        if [ $(($i % 10))  == 0 ]; then
+            printf " %d %d %d %d %d %d %d %d %d %d\n" ${ch_val[$i]} ${ch_val[(($i+1))]} ${ch_val[(($i+2))]} ${ch_val[(($i+3))]} ${ch_val[(($i+4))]}  ${ch_val[(($i+5))]}  ${ch_val[(($i+6))]}  ${ch_val[(($i+7))]}  ${ch_val[(($i+8))]}  ${ch_val[(($i+9))]}
+        fi
+    done
+    printf ")\n"
+    printf "=============================================================\n"
+    printf "make random err array log end\n"
+    printf "=============================================================\n"
+
+#change the byte.
+    for ((i=0;i<$cnt;i++)); do
+        replace_byte $filename ${ofs[$i]} ${ch_val[$i]}
+    done
+}
+#endif /* SUPPORT_CONF_TEST */
+
+function gen_val {
+    local min_val=$1
+    local max_val=$2
+    local default_val=$3
+    local val
+
+    if [ -z "$default_val" ] || [ "$default_val" == "-99" ]; then
+        # Generate random value
+        val=$(get_random $min_val $max_val)
+    else
+        val=$default_val
+    fi
+    
+    echo "$val"
+}
+
+function gen_min_max_val {
+    local min_val=$1
+    local max_val=$2
+    local default_val=$3
+    local val
+
+    if [ -z "$default_val" ] || [ "$default_val" == "-99" ]; then
+        # Generate random value
+        val=$(get_random_min_max $min_val $max_val)
+    else
+        val=$default_val
+    fi
+
+    echo "$val"
+}
+
+
+# get_default_param(is_decoder)
+function get_default_param {
+    local is_decoder=$1
+    local g_product_name=$2
+
+    echo "default_opt=$default_opt"
+    if [ "$default_opt" = "0" ]; then
+        ##################################################
+        # make argv parameter from TestRunnerParamWaveXXXDec.txt
+        ##################################################
+        g_stream_endian=$(gen_val 16 31 $stream_endian_temp)
+        g_frame_endian=$(gen_val 16 31 $frame_endian_temp)
+
+        if [ "$g_product_name" = "wave4" ]; then
+            g_source_endian=$(gen_val 16 31 $source_endian_temp)
+        fi
+        if [ $g_force_bsmode -eq 0 ]; then
+            g_bsmode=$(gen_val 0 1 $bsmode_temp)
+        fi
+        if [ "$codec" = "vp9" ]; then 
+            g_bsmode=2;  #only support PIC_END MODE
+        fi
+        val=0
+        g_cbcr_interleave=0
+        g_enable_nv21=0
+        
+        
+        if [ $is_decoder -eq 1 ]; then
+            if [ $g_bsmode -eq 1 ]; then g_bsmode=2; fi
+            val=$(gen_val 0 2 $cbcr_mode_temp)
+            case $val in
+                0) g_cbcr_interleave=0;;      # separate YUV
+                1) g_cbcr_interleave=1        # NV12
+                   g_enable_nv21=0;;
+                2) g_cbcr_interleave=1        # NV21
+                   g_enable_nv21=1;;
+            esac
+            if [ "$codec" = "mp2" ] || [ "$codec" = "mp4" ]; then
+                g_enable_deblock=$(gen_val 0 1 $deblock_temp)
+            fi
+            if [ "$g_product_name" = "coda960" ] || [ "$g_product_name" = "coda980" ]; then
+                g_enable_dering=$(gen_val 0 1 $dering_temp)
+                val=$(gen_val 0 3 $rotAngle_temp)
+                if [ "$val" -le "3" ]; then
+                    g_rotAngle=$(expr $val \* 90)
+                else
+                    g_rotAngle=$val
+                fi
+                g_mirDir=$(gen_val 0 3 $mirDir_temp)
+                g_enable_tiled2linear=$(gen_val 0 1 $tiled2linear_temp)
+                g_maptype_index=$(gen_val 0 $(($g_maptype_num-1)) $maptype_temp)
+
+                if [ $g_maptype_index -gt 0 ]; then
+                    if [ $g_enable_wtl -eq 0 ] && [ $g_enable_tiled2linear -eq 0 ]; then
+                        g_enable_wtl=1
+                    fi
+                else
+                    # g_maptyp_index is LINEAR MAP.
+                    g_enable_wtl=0
+                    g_enable_tiled2linear=0
+                fi
+            fi
+            if [ "$disable_wtl_temp" != -99 ] && [ $disable_wtl_temp ]; then 
+                g_enable_wtl=1 
+                [ $disable_wtl_temp -eq 0 ] || g_enable_wtl=0
+            else 
+                g_enable_wtl=$(get_random 0 1) 
+            fi
+            if [ "$g_product_name" = "coda7q" ]; then
+                if [ "${codec}" != "hevc" ] && [ "${codec}" != "avc" ]; then
+                    g_enable_wtl=0
+                fi
+            fi
+            if [ "$codec" = "vp9" ]; then 
+                # WAVE412 specific
+                g_bsmode=2; 
+                g_rotAngle=0
+                g_mirDir=0
+            fi
+            if [ "$is_main10" = "" ]; then is_main10=0; fi
+            if [ $is_main10 -eq 0 ]; then
+                g_wtl_format=0
+            fi
+            if [ $g_enable_wtl -eq 1 ] && [ $is_main10 -eq 1 ]; then
+                if [ "$wtl_format_temp" != -99 ] && [ $wtl_format_temp ]; then 
+                    g_wtl_format=$wtl_format_temp; 
+                    if [ "$wtl_format_temp" == "-1" ]; then
+                        g_enable_wtl=0
+                        g_wtl_format=""
+                    fi
+                else
+                    while : ; do
+                        g_wtl_format=$(get_random 0 ${#g_yuv_fmt_list[@]}-1)
+
+                        if [ "${g_yuv_fmt_list[${g_wtl_format}]}" != "RESERVED" ]; then
+                            break
+                        fi
+                    done
+                fi
+            fi
+        else
+            # ENCODER
+            if [ "$g_product_name" = "coda960" ] || [ "$g_product_name" = "coda980" ] || [ "$g_product_name" = "coda7q" ]; then
+                val=$(gen_val 0 2 $cbcr_mode_temp)
+                case $val in
+                    0) g_cbcr_interleave=0;;      # separate YUV
+                    1) g_cbcr_interleave=1        # NV12
+                       g_enable_nv21=0;;
+                    2) g_cbcr_interleave=1        # NV21
+                       g_enable_nv21=1;;
+                esac
+                if [ "$g_product_name" != "coda7q" ]; then
+                    g_maptype_index=$(gen_val 0 $(($g_maptype_num -1)) $maptype_temp)
+                    g_enable_linear2tiled=$(gen_val 0 1 $linear2tiled_temp)
+                fi
+                g_linebuf_int=$(gen_val 0 3 $linebuf_int_temp)
+            else
+                g_packedFormat=0
+                g_srcFormat3p4b=$(gen_val 1 2 $srcFormat3p4b_temp)
+                val=$(gen_val 0 6 $yuv_src_mode_temp)
+                if [ "$val" == "1" ];   then #nv12
+                    g_cbcr_interleave=1
+                    g_enable_nv21=0
+                elif [ "$val" == "2" ]; then #nv21
+                    g_cbcr_interleave=1
+                    g_enable_nv21=1
+                elif [ $val -ge 3 ]; then #(packed) 3:YUYV, 4:YVYU, 5:UYVY, 6:VYUY
+                    g_packedFormat=$(expr $val - 2)
+                fi
+            fi
+            val=$(gen_val 0 3 $rotAngle_temp)
+            if [ "$val" -le "3" ]; then
+                g_rotAngle=$(expr $val \* 90)
+            else
+                g_rotAngle=$val
+            fi
+
+            g_mirDir=$(gen_val 0 3 $mirDir_temp)
+            if [ "$MODE_COMP_ENCODED_temp" != -99 ] &&  [ $MODE_COMP_ENCODED_temp ];   then MODE_COMP_ENCODED=$MODE_COMP_ENCODED_temp;   else MODE_COMP_ENCODED=1; fi
+        fi
+
+    else    
+        g_secondary_axi=0
+        g_stream_endian=0
+        g_source_endian=0
+        g_frame_endian=0
+        g_bsmode=0
+        g_cbcr_interleave=0
+        g_enable_nv21=0
+        if [ $is_decoder -eq 1 ]; then                
+            g_enable_thumbnail=0
+            g_enable_wtl=1
+            g_wtl_format=0
+            # CODA7Q & CODA9 features
+            g_enable_deblock=0
+            g_enable_dering=0
+            g_rotAngle=0
+            g_mirDir=0
+            g_maptype_index=0
+            if [ "$g_product_name" = "coda960" ] || [ "$g_product_name" = "coda980" ]; then g_enable_wtl=0; fi
+            if [ "$g_product_name" = "coda7q" ]; then
+                if [ "${codec}" != "hevc" ] && [ "${codec}" != "avc" ]; then
+                    g_enable_wtl=0
+                fi
+            fi
+            # END CODA7Q & CODA9
+        else
+            g_subframe_sync=0
+            g_packedFormat=0
+            g_subCtuMap=0
+            g_rotAngle=0
+            g_mirDir=0
+        fi
+    fi      
+}           
+
+function gen_wtl_format {
+    local main10=$1
+    local default_val=$2
+    local val
+
+    # g_yuv_fmt_list variable should be defined in TestRunnerXXX.sh
+
+    if [ -z $default_val ] || [ "$default_val" == "-99" ]; then
+        while : ; do
+            val=$(get_random 0 ${#g_yuv_fmt_list[@]}-1)
+            if [ "${g_yuv_fmt_list[$val]}" != "RESERVED" ]; then
+                break
+            fi
+        done
+    else
+        val=$default_val
+    fi
+    echo "$val"
+}
+
+function get_default_param_wave512 {
+    if [ "$default_opt" = "0" ]; then
+        ##################################################
+        # make argv parameter from TestRunnerParamWaveXXXDec.txt
+        ##################################################
+        g_stream_endian=$(gen_val 16 31 $stream_endian_temp)
+        g_frame_endian=$(gen_val 16 31 $frame_endian_temp)
+
+        if [ $g_force_bsmode -eq 0 ]; then
+            g_bsmode=$(gen_val 0 1 $bsmode_temp)
+        fi
+        # NV12 or NV21 
+        val=$(gen_val 0 2 $cbcr_mode_temp)
+        case $val in
+            0) g_cbcr_interleave=0;;      # separate YUV
+            1) g_cbcr_interleave=1        # NV12
+               g_enable_nv21=0;;
+            2) g_cbcr_interleave=1        # NV21
+               g_enable_nv21=1;;
+        esac
+
+        # WAVE512 has three output H/W modules.
+        # 0 - BWB, 1 - AFBCE, 2 - DOWN-SCALER, 3 - DISABLE-WTL
+        # BWB, AFBCE AND DOWNSCALER NEED WTL FUNCTION
+        g_enable_wtl=1
+        g_afbce=0
+        if [ "$g_scaler" = "1" ]; then
+            # DOWN SCALING TEST
+            val=2
+        else
+            val=$(gen_val 0 3 $g_output_hw_temp)
+        fi
+        case $val in
+        0) # BWB
+            if [ "$is_main10" == "1" ]; then
+                g_yuv_fmt_list=("${YUV_FORMAT_LIST[@]}")
+            else
+                g_yuv_fmt_list=("${YUV_FORMAT_LIST_8BIT[@]}")
+            fi
+            g_wtl_format=$(gen_wtl_format $wtl_format_temp)
+            ;;
+        1) 
+            g_wtl_format=0
+            ;;
+        2) 
+            g_wtl_format=0
+            ;;
+        3) # FBC
+            # FBC IS A COMPRESSED FRAMEBUFFER FORMAT. DISABLE NV12/21
+            g_enable_wtl=0
+            g_cbcr_interleave=0
+            g_enable_nv21=0
+            ;;
+        esac
+    else    
+        g_secondary_axi=0
+        g_stream_endian=0
+        g_frame_endian=0
+        g_bsmode=0
+        g_cbcr_interleave=0
+        g_enable_nv21=0
+        g_enable_thumbnail=0
+        g_enable_wtl=1
+        g_wtl_format=0
+    fi      
+}
+
+function build_test_param {
+    local is_decoder=$1
+    local param=""
+    local param2=""
+
+
+    if [ "$g_product_name" = "coda960" ] || [ "$g_product_name" = "coda980" ]; then
+        if [ $g_maptype_index -gt 0 ]; then
+            param2="$param2 --maptype=$g_maptype_index"
+        fi
+    else
+        if [ "$g_fbc_mode" == "" ]; then
+            pram="$param --fbc-mode=0x0c"
+        else
+            param="$param --fbc-mode=$g_fbc_mode"
+        fi
+    fi
+
+    param2="$param2 --stream-endian=$g_stream_endian"
+    param2="$param2 --frame-endian=$g_frame_endian"
+    if [ $is_decoder -eq 1 ]; then
+        param="$param --render 0 -c $g_match_mode"
+        param="$param --codec $g_codec_index"
+
+        # CODA7Q & CODA9 features.
+        if [ $g_codec_index -eq 3 ]; then
+            param="$param --mp4class=$g_mp4class"
+        fi
+
+        if [ $g_enable_deblock -eq 1 ]; then
+            param="$param --enable-deblock"
+        fi
+        if [ $g_enable_mvc -eq 1 ]; then
+            param="$param --enable-mvc"
+        fi
+        # END and CODA7Q & CODA9
+	
+        param="$param $param2"
+    
+        if [ $g_bsmode -gt 0 ]; then
+            param="$param --bsmode=$g_bsmode"
+        fi
+        if [ $g_enable_thumbnail -eq 1 ]; then
+            param="$param --enable-thumbnail"
+        fi
+
+        if [ $g_cbcr_interleave -eq 1 ]; then
+            param="$param --enable-cbcrinterleave"
+            if [ $g_enable_nv21 -eq 1 ]; then
+                param="$param --enable-nv21"
+            fi
+        fi
+    
+        if [ "$g_product_name" = "coda960" ] || [ "$g_product_name" = "coda980" ]; then
+            if [ $g_enable_dering -eq 1 ]; then
+                param="$param --enable-dering"
+            fi	
+            if [ $g_enable_wtl -eq 0 ] && [ $g_maptype_index -gt 0 ]; then
+                param="$param --disable-wtl"
+            fi
+            if [ $g_enable_tiled2linear -eq 1 ]; then
+                param="$param --enable-tiled2linear"
+            fi
+            if [ $g_rotAngle -gt 0 ]; then
+                param="$param --rotate=$g_rotAngle"
+            fi
+            if [ $g_mirDir -gt 0 ]; then
+                param="$param --mirror=$g_mirDir"
+            fi
+        else
+            if [ "$g_product_name" = "coda7q" ]; then
+                if [ "${codec}" != "hevc" ] && [ "${codec}" != "avc" ]; then
+                    g_enable_wtl=0
+                fi
+            fi
+            if [ $g_enable_wtl -eq 0 ]; then
+                    param="${param} --disable-wtl"
+            else
+                param="${param} --wtl-format=$g_wtl_format"
+            fi
+        fi
+
+    else
+        # ENCODER
+        if [ "$MODE_COMP_ENCODED" == "1" ];  then param="${param} -c"; fi
+        if [ "$MODE_COMP_RECON" == "1" ];    then param="${param} -r"; fi
+
+        param="$param $param2"
+    
+        if [ "$g_product_name" = "coda960" ] || [ "$g_product_name" = "coda980" ] ||  [ "$g_product_name" = "coda7q" ]; then
+            if [ $g_enable_linear2tiled -eq 1 ] && [ "$g_product_name" != "coda7q" ]; then
+                param="$param --enable-linear2tiled"
+            fi
+            if [ $g_bsmode -eq 0 ]; then
+                param="$param --enable-ringBuffer"
+            else
+                if [ $g_linebuf_int -eq 1 ]; then
+                    param="$param --enable-lineBufInt"
+                fi
+            fi
+            if [ $g_cbcr_interleave -eq 1 ]; then
+                param="$param --enable-cbcrInterleave"
+                if [ $g_enable_nv21 -eq 1 ]; then
+                    param="$param --enable-nv21"
+                fi
+            fi
+            param="$param --rotate=$g_rotAngle"
+            param="$param --mirror=$g_mirDir"
+        else
+            ### WAVE4xx ###
+            param="$param --source-endian=$g_source_endian"
+            param="$param --rotAngle=${g_rotAngle} --mirDir=${g_mirDir}"
+            if [ $g_bsmode -eq 0 ]; then
+                param="${param} --enable-ringBuffer"
+            fi
+            if  [ $g_packedFormat -ne 0 ]; then
+                param="${param} --packedFormat=${g_packedFormat}"
+            elif [ "$g_enable_nv21" == "0" ] && [ "$g_cbcr_interleave" == "1" ]; then
+                param="${param} --enable-cbcrInterleave --nv21=${g_enable_nv21}"
+            elif [ "$g_enable_nv21" == "1" ] && [ "$g_cbcr_interleave" == "1" ]; then
+                param="${param} --enable-cbcrInterleave --nv21=${g_enable_nv21}"
+            fi
+            param="${param} --srcFormat3p4b=${g_srcFormat3p4b}"
+
+        fi
+    fi
+
+    g_func_ret_str="$param"
+}
+
+function get_random_param {
+    local is_decoder=$1
+    g_secondary_axi=0
+    if [ "$g_product_name" != "coda7q" ]; then
+        g_maptype_index=$(get_random 0 $(($g_maptype_num-1)))
+    fi
+    if [ "$g_product_name" = "coda960" ] || [ "$g_product_name" = "coda980" ]; then
+        g_stream_endian=$(get_random 0 3)
+        g_frame_endian=$(get_random 0 3)
+    elif [ "$g_product_name" = "wave4" ]; then
+        g_stream_endian=$(get_random 16 31)
+        g_frame_endian=$(get_random 16 31)
+        g_source_endian=$(get_random 16 31)
+    else
+        g_stream_endian=$(get_random 16 31)
+        g_frame_endian=$(get_random 16 31)
+    fi
+
+
+    if [ $is_decoder -eq 1 ]; then
+        # TILED2LINEAR 
+        g_enable_wtl=0
+        g_enable_tiled2linear=0
+        if [ $g_maptype_index -gt 0 ]; then 
+            local val=$(get_random 0 1)
+            if [ $val -eq 0 ]; then
+                g_enable_tiled2linear=1
+            else
+                g_enable_wtl=1
+            fi
+        else
+            g_enable_tiled2linear=0
+            g_enable_wtl=0
+        fi
+
+        case $(get_random 0 2) in
+            0) g_cbcr_interleave=0;;      # separate YUV
+            1) g_cbcr_interleave=1        # NV12
+               g_enable_nv21=0;;
+            2) g_cbcr_interleave=1        # NV21
+               g_enable_nv21=1;;
+        esac
+        if [ "$g_product_name" != "coda960" ] && [ "$g_product_name" != "coda980" ]; then
+            g_enable_wtl=1
+        fi
+        g_wtl_format=0
+        if [ "$is_main10" = "" ]; then is_main10=0; fi
+        if [ $is_main10 -eq 1 ]; then
+            g_wtl_format=$(get_random 0 ${#g_yuv_fmt_list[@]}-1)
+            if [ 1 -le $g_wtl_format ] && [ $g_wtl_format -le 4 ]; then
+                g_wtl_format=$(($g_wtl_format + 4))
+            fi
+            if [ "${g_yuv_fmt_list[${g_wtl_format}]}" == "RESERVED" ]; then
+                g_wtl_format=5      # 16BIT_LSB_JUSTIFIED
+            else
+                g_enable_wtl=1
+            fi
+        fi
+        # WAVE4 Bandwidth optimization
+        if [[ $g_product_name =~ wave* ]] || [ "$g_product_name" = "coda7q" ]; then
+            g_bw_opt=$(get_random 0 1)
+            if [ $g_bw_opt -eq 1 ]; then
+                g_enable_wtl=1
+            fi
+        fi
+        # CODA7Q & CODA9 features
+        if [ "$g_product_name" = "coda960" ] || [ "$g_product_name" = "coda980" ]; then
+            g_rotAngle=$(($(get_random 0 3)*90))
+            g_mirDir=$(get_random 0 3)
+            g_enable_dering=$(get_random 0 1)
+            g_enable_deblock=$(get_random 0 1)
+        else
+            g_rotAngle=0
+            g_mirDir=0
+            g_enable_dering=0
+            g_enable_deblock=0
+        fi
+
+        if [ "$g_product_name" = "coda7q" ]; then
+            g_enable_deblock=$(get_random 0 1)
+            if [ "${codec}" != "hevc" ] && [ "${codec}" != "avc" ]; then
+                g_enable_wtl=0
+            fi
+        fi
+        # check combination of parameters
+        if [ $g_enable_wtl -eq 1 ] || [ $g_enable_ppu -eq 0 ]; then
+            g_rotAngle=0
+            g_mirDir=0
+            g_enable_dering=0
+        fi
+
+        if [ "${codec}" != "mp2" ] && [ "${codec}" != "mp4" ]; then
+            g_enable_deblock=0
+            g_enable_dering=0
+        fi
+        # END CODA7Q & CODA9
+        # VP9 constraint(PIC_END Mode)
+        if [ "$codec" = "vp9" ]; then 
+            g_bsmode=2 
+        fi
+    else
+        # encoder random options
+        if [ "$g_produc_name" = "wave4" ]; then
+            val=$(get_random 0 6)
+            g_cbcr_interleave=0
+            g_packedFormat=0
+            if [ "$val" == "1" ];   then #frm_format 2
+                g_cbcr_interleave=1
+                g_enable_nv21=0
+            elif [ "$val" == "2" ]; then #frm_format 3
+                g_cbcr_interleave=1
+                g_enable_nv21=1
+            elif [ "$val" -ge "3" ]; then #(packed) 3:YUYV, 4:YVYU, 5:UYVY, 6:VYUY
+                g_packedFormat=$(expr $val - 2)
+            fi
+            g_srcFormat3p4b=$(get_random 0 2)
+            MODE_COMP_ENCODED=1
+        else
+            g_linebuf_int=$(get_random 0 1)
+            if [ "$g_produc_name" != "coda7q" ]; then
+                g_enable_linear2tiled=$(get_random 0 1)
+            fi 
+            # cbcr-interleave
+            val=$(get_random 0 2)
+            case $val in
+                0) g_cbcr_interleave=0;;      # separate YUV
+                1) g_cbcr_interleave=1        # NV12
+                   g_enable_nv21=0;;
+                2) g_cbcr_interleave=1        # NV21
+                   g_enable_nv21=1;;
+            esac
+        fi
+        g_bsmode=$(get_random 0 1)
+        val=$(get_random 0 3 )
+        g_rotAngle=$(expr $val \* 90)
+        g_mirDir=$(get_random 0 3 )
+    fi
+
+    g_func_ret_str="$param"
+}
+
+function run_refc_dec_h265 {
+    local stream_path="$1"
+    local output_path="$2"
+    local wtl_mode_index=0
+    local skip_option=0
+    local max_frames=""
+    local color_format=""
+    local output_param=""
+    local file_ext=${stream_path##*.}
+    if [ "$file_ext" = "mp4" ] || [ "$file_ext" = "mkv" ] || [ "$file_ext" = "avi" ]; then
+        cp ${bin_dir}/../../../util/bin/Linux/vcp ${bin_dir} || echo ingore_err
+        ${bin_dir}/vcp -i $stream_path output.bin
+        stream_path="output.bin"
+    fi
+
+    if [ $g_enable_thumbnail -eq 1 ]; then
+        skip_option=1
+    fi
+
+    if [ "$g_product_name" = "wave412" ] || [ "$g_product_name" = "wave512" ] || [ "$g_product_name" = "wave515" ]; then
+        if [ $g_wtl_format -eq 0 ]; then 
+            wtl_mode_index=0
+            output_param="-o $output_path"
+        elif [ $g_wtl_format -eq 5 ]; then
+            wtl_mode_index=1
+            output_param="-o $output_path"
+        elif [ $g_wtl_format -eq 6 ]; then
+            wtl_mode_index=1
+            output_param="-o $output_path"
+        elif [ $g_wtl_format -eq 7 ]; then
+            wtl_mode_index=1
+            output_param="-o $output_path"
+        elif [ $g_wtl_format -eq 8 ]; then
+            wtl_mode_index=1
+            output_param="-o $output_path"
+        fi
+    else #if [ "$g_product_name" = "wave412" ];
+        if [ $g_wtl_format -eq 0 ]; then 
+            wtl_mode_index=0
+            output_param="-o $output_path"
+        elif [ $g_wtl_format -eq 5 ]; then
+            wtl_mode_index=1
+            output_param="-o $output_path"
+        elif [ $g_wtl_format -eq 6 ]; then
+            wtl_mode_index=5
+            output_param="-o $output_path"
+        elif [ $g_wtl_format -eq 7 ]; then
+            wtl_mode_index=2
+            output_param="-o $output_path"
+        elif [ $g_wtl_format -eq 8 ]; then
+            wtl_mode_index=6
+            output_param="-o $output_path"
+        fi
+    fi
+
+    if [ $g_match_mode -eq 2 ]; then
+        if [ $wtl_mode_index -ne 0 ]; then 
+            wtl_mode_index=1
+        fi
+        str_opt="-i ${stream_path} -c -5 -y ${wtl_mode_index} ${color_format} ${output_param} --skip ${skip_option} ${max_frames} $g_refc_frame_num"
+    else
+            str_opt="-i ${stream_path} -c -y ${wtl_mode_index} ${color_format} ${output_param} --skip ${skip_option} ${max_frames} $g_refc_frame_num"
+    fi
+
+
+    str_cmd="${bin_dir}/hevc_dec ${str_opt} --sbs 46080"
+    echo "${str_cmd}"
+    ${str_cmd}
+
+    if [ "$?" != "0" ]; then 
+        echo "Failed to ref-c"
+        return 1; 
+    fi
+    return 0
+}
+
+function run_refc_dec_vp9 {
+    local stream_path="$1"
+    local output_path="$2"
+    local arg_cci=""
+    local wtl_mode_index=0
+    local max_frames=""
+
+    if [ "$g_product_name" = "wave412" ] || [ "$g_product_name" = "wave512" ] || [ "$g_product_name" = "wave515" ]; then
+        if [ $g_wtl_format -eq 0 ]; then 
+            wtl_mode_index=0;
+        elif [ $g_wtl_format -eq 1 ]; then 
+            wtl_mode_index=0;
+        elif [ $g_wtl_format -eq 13 ]; then
+            wtl_mode_index=0;
+        elif [ $g_wtl_format -eq 18 ]; then
+            wtl_mode_index=0;
+        elif [ $g_wtl_format -eq 23 ]; then
+            wtl_mode_index=0;
+        elif [ $g_wtl_format -eq 28 ]; then
+            wtl_mode_index=0;
+        else 
+            wtl_mode_index=5;
+        fi
+    else #if [ "$g_product_name" = "wave412" ];
+        if [ $g_wtl_format -eq 0 ]; then 
+            wtl_mode_index=0
+            output_param="-o $output_path"
+
+        elif [ $g_wtl_format -eq 5 ]; then
+            wtl_mode_index=1
+            output_param="-o $output_path"
+        elif [ $g_wtl_format -eq 6 ]; then
+            wtl_mode_index=5
+            output_param="-o $output_path"
+        elif [ $g_wtl_format -eq 7 ]; then
+            wtl_mode_index=2
+            output_param="-o $output_path"
+        elif [ $g_wtl_format -eq 8 ]; then
+            wtl_mode_index=6
+            output_param="-o $output_path"
+    
+        fi
+    fi
+
+    if [ $g_match_mode -eq 2 ]; then
+        if [ $wtl_mode_index -ne 0 ]; then 
+            wtl_mode_index=5    # 16BIT MSB
+        fi
+        param="--input=${stream_path} --outmd5=${output_path} --render 0 --codec $g_codec_index --stream-endian=$g_stream_endian --frame-endian=$g_frame_endian --bsmode=$g_bsmode"
+    else
+            param="--input=${stream_path} --output=${output_path} --render 0 --codec $g_codec_index --stream-endian=$g_stream_endian --frame-endian=$g_frame_endian --bsmode=$g_bsmode"
+    fi
+
+
+    param="$param $g_frame_num "
+
+    if [ $g_bsmode -gt 0 ]; then
+        param="$param --bsmode=$g_bsmode"
+    fi
+    if [ $g_enable_thumbnail -eq 1 ]; then
+        param="$param --enable-thumbnail"
+    fi
+
+
+    if [ $g_enable_wtl -eq 0 ]; then
+        param="${param} --disable-wtl"
+    else
+        if [ "$g_product_name" = "wave412" ] || [ "$g_product_name" = "wave512" ] || [ "$g_product_name" = "wave515" ]; then
+            param="${param} --wtl-format=${wtl_mode_index}"
+        else
+            param="${param} --wtl-format=$g_wtl_format"
+        fi
+    fi
+
+    if [ $g_cbcr_interleave -eq 1 ]; then
+        param="${param} --enable-cbcrinterleave"
+        if [ $g_enable_nv21 -eq 1 ]; then
+            param="${param} --enable-nv21"
+        fi
+
+    fi
+
+    if [ "$g_product_name" = "wave412" ]; then
+        str_cmd="${bin_dir}/w412_refc_test ${param}"
+    else
+        str_cmd="${bin_dir}/w512_refc_test ${param}"
+    fi
+    echo "${str_cmd}"
+    ${str_cmd}
+
+    if [ "$?" != "0" ]; then 
+        echo "Failed to ref-c"
+        return 1; 
+    fi
+    return 0
+}
+
+# run_refc_dec_7l(stream_path, output_path, codec_name)
+function run_refc_dec_7l {
+    local stream_path="$1"
+    local output_path="$2"
+    local codec_name="$3"
+    local wtl_mode_index=0
+    local skip_option=0
+    local output_param="-o ${output_path}"
+    local str_opt=""
+    local str_cmd=""
+    local file_ext=${stream_path##*.}
+    local cmodel=""
+
+    if [ "$g_product_name" != "coda7q" ]; then 
+        if [ "$file_ext" = "mp4" ] || [ "$file_ext" = "mkv" ] || [ "$file_ext" = "avi" ]; then
+            ${bin_dir}/vcp -i $stream_path output.bin
+            stream_path="output.bin"
+        fi
+    else
+        if [ "$codec_name" = "mp4" ] && [ "$file_ext" = "avi" ]; then
+            cp ${bin_dir}/../../../util/bin/Linux/vcp ${bin_dir} || echo ingore_err
+            ${bin_dir}/vcp -i $stream_path output.bin
+            stream_path="output.bin"
+        fi
+    fi
+
+    if [ "$file_ext" = "rmvb" ]; then
+        stream_path=${stream_path%.*}.rvf
+    fi
+
+    str_opt="-i ${stream_path} -c"
+
+    shopt -s nocasematch
+    case "$codec_name" in
+        avc) if [ $g_enable_mvc -eq 1 ]; then
+                cmodel="mvc_dec"
+             else
+                cmodel="avc_dec"
+             fi
+             ;;
+        vc1) cmodel="vc1_dec";;
+        mp2) cmodel="mp2_dec"
+             if [ $g_enable_deblock -eq 1 ]; then
+                 str_opt="$str_opt -d"
+             fi	
+             ;;
+        h263) cmodel="mp4_dec";;
+        mp4) cmodel="mp4_dec"
+             str_opt="$str_opt -s $g_mp4class"
+             if [ $g_enable_deblock -eq 1 ]; then
+                 str_opt="$str_opt -d"
+             fi
+             ;;
+        avs) cmodel="avs_dec";;
+        dv3) cmodel="div_dec";;
+        rvx) cmodel="rvx_dec";;
+        vp8) cmodel="vp8_dec"
+             str_opt="$str_opt --std 2";;
+        *)    echo ""; return;;
+    esac
+    shopt -u nocasematch
+
+
+    str_cmd="${bin_dir}/${cmodel} ${str_opt} ${output_param}"
+    echo "${str_cmd}"
+    ${str_cmd}
+
+    if [ "$?" != "0" ]; then 
+        echo "Failed to ref-c"
+        return 1; 
+    fi
+    return 0
+}
+
+function run_refc_dec_coda9 {
+    local stream_path=$1
+    local output_yuv=$2
+    local ext=${stream_path##*.}
+
+    if [ "$ext" = "rmvb" ]; then
+        stream_path=${stream_path%.*}.rvf
+    fi
+
+    cmodel_param="-i $stream_path -o $output_yuv"
+    ext_param=""
+    shopt -s nocasematch
+    case "$codec" in
+        avc) if [ $g_enable_mvc -eq 1 ]; then
+                cmodel="RefMvcDec"
+             else
+                cmodel="RefAvcDec"
+             fi
+             ;;
+        vc1) cmodel="RefVc1Dec";;
+        mp2) cmodel="RefMp2Dec";;
+        mp4) cmodel="RefMp4Dec"
+             cmodel_param="$cmodel_param -s $g_mp4class";;
+        avs) cmodel="RefAvsDec";;
+        dv3) cmodel="RefDivDec"
+             cmodel_param="$cmodel_param -E host_div3_rtl_cmd.org"
+             if [ "$ext" = "ivf" ]; then
+                ext_param="-v"
+             fi
+             ;;
+        rvx) cmodel="RefRvxDec";;
+        vp8) cmodel="RefVpxDec"
+             cmodel_param="$cmodel_param --std 2";;
+        tho) cmodel="RefThoDec"
+             cmodel_param="$cmodel_param --make_stream --stream_filename temp/host_tho_rtl_cmd.org --stream_endian $g_stream_endian";;
+        *)    echo ""; return;;
+    esac
+    shopt -u nocasematch
+
+
+    ppu_option=0
+    if [ $g_match_mode -eq 1 ]; then
+        if [ $g_rotAngle -ne 0 ]; then
+            local index=$(($g_rotAngle/90))
+            ppu_option=$((0x10 | $index))
+        fi
+        if [ $g_mirDir -ne 0 ]; then
+            ppu_option=$(($ppu_option | 0x10 | ($g_mirDir<<2)))
+        fi
+        if [ $ppu_option -gt 0 ]; then
+            cmodel_param="$cmodel_param -g $ppu_option"
+        fi
+    fi
+    if [ $g_enable_dering -eq 1 ]; then
+        cmodel_param="$cmodel_param -p"
+    fi
+    if [ $g_enable_deblock -eq 1 ]; then
+        cmodel_param="$cmodel_param -d"
+    fi
+
+    exec_cmd="${bin_dir}/$cmodel $cmodel_param -l $ext_param -c"
+    echo "$exec_cmd"
+
+    $exec_cmd
+
+    return $?
+}
+
+function run_refc_enc_coda9 {
+    local val=0
+    local input=$1
+    local output=$2
+    local postfix=""
+
+    if [ "$g_product_name" = "coda980" ]; then
+        postfix="_980_rev"
+    fi
+
+    refc_exe="$bin_dir"
+    case $codec in
+    avc) 
+        if [ $g_enable_mvc -eq 0 ]; then
+            refc_exe="$refc_exe/RefAvcEnc$postfix"
+        else
+            refc_exe="$refc_exe/RefMvcEnc$postfix"
+        fi
+        ;;
+    mp4)
+        refc_exe="$refc_exe/RefMp4Enc$postfix" ;;
+    *)  
+        echo "run_refc_enc: Unknown codec $codec"
+        return 1;;
+    esac
+
+    refc_param="-i $input -o $output -p $yuv_dir/"
+
+    val=$(($g_rotAngle/90))
+    val=$(($val | ($g_mirDir<<2)))
+    if [ $val -ne 0 ]; then
+        refc_param="$refc_param -g $val"
+    fi
+
+    refc_param=$(echo $refc_param | sed -e 's/\\/\//g')
+
+    cmd="$refc_exe $refc_param"
+    echo $cmd
+    echo ""
+
+    $cmd
+
+    return $?
+}
+
+function run_refc_enc_coda7 {
+    local val=0
+    local input=$1
+    local output=$2
+
+    refc_exe="$bin_dir"
+    case $codec in
+    avc)
+        refc_exe="$refc_exe/avc_enc" ;;
+    mp4)
+        refc_exe="$refc_exe/mp4_enc" ;;
+    *)  
+        echo "run_refc_enc: Unknown codec $codec"
+        return 1;;
+    esac
+
+    refc_param="-i $input -o $output -p $yuv_dir/"
+
+    val=$(($g_rotAngle/90))
+    val=$(($val | ($g_mirDir<<2)))
+    if [ $val -ne 0 ]; then
+        refc_param="$refc_param -g $val"
+    fi
+
+    refc_param=$(echo $refc_param | sed -e 's/\\/\//g')
+
+    cmd="$refc_exe $refc_param"
+    echo $cmd
+    echo ""
+
+    $cmd
+
+    return $?
+}
+
+function generate_golden_data_path {
+    local codec=$1
+    local streamset=$2
+    local streamfile=$3
+
+    codec_dir=""
+    shopt -s nocasematch
+    case "$codec" in
+        vp9)  codec_dir="vp9dec";;
+        hevc) codec_dir="hvcdec";;
+        avc)  codec_dir="avcdec";;
+        vc1)  codec_dir="vc1dec";;
+        mp2)  codec_dir="mp2dec";;
+        mp4)  codec_dir="mp4dec";;
+        h263) codec_dir="mp4dec";;
+        avs)  codec_dir="avsdec";;
+        dv3)  codec_dir="dv3dec";;
+        rvx)  codec_dir="rvxdec";;
+        vp8)  codec_dir="vp8dec";;
+        tho)  codec_dir="thodec";;
+        *)    codec_dir="";;
+    esac
+    shopt -u nocasematch
+
+    if [ "$is_main10" = "" ]; then is_main10=0; fi
+    
+    yuvext=""
+    if [ "$g_enable_wtl" == "1" ]; then
+        case "$codec" in
+        hevc | vp9)
+            if [ $is_main10 -eq 1 ]; then
+                if [ $g_wtl_format -eq 0 ]; then
+                    yuvext="_bwb_8"
+                fi
+            fi
+            ;;
+        *) 
+            ;;
+        esac
+    elif [ $g_afbce -eq 1 ]; then
+        case "$codec" in
+        hevc | vp9)
+            if [ $is_main10 -eq 1 ]; then
+                yuvext="_bwb_8"
+            fi
+        esac
+    fi
+    
+    # CODA9xx & CODA7x features
+    local dering_str=""
+    if [ $g_enable_dering -eq 1 ]; then
+        dering_str="_dr"
+    fi
+    local deblk_str=""
+    if [ $g_enable_deblock -eq 1 ]; then
+        deblk_str="_dbk"
+    fi
+    # END CODA9xx & CODA7x
+
+    streamset_name=$(basename $streamset)
+    filename=$(basename $streamfile)
+
+    local target_base="$yuv_dir/$codec_dir"
+    local target_path=""
+    thumbnail_ext=""
+    if [ $g_enable_thumbnail -eq 1 ]; then
+        thumbnail_ext="_thumb"
+    fi
+
+    local wtl_format_ext=""
+    case $g_wtl_format in
+        0) wtl_format_ext="";;
+        5) wtl_format_ext="_16bit_msb";;
+        6) wtl_format_ext="_16bit_lsb";;
+        7) wtl_format_ext="_32bit_msb";;
+        8) wtl_format_ext="_32bit_lsb";;
+    esac
+
+    local rot_index=0
+    if [ $g_rotAngle -eq 0 ] && [ $g_mirDir -eq 0 ]; then
+        rot_index=0 
+    fi
+    if [ $g_rotAngle -eq 180 ] && [ $g_mirDir -eq 3 ]; then
+        rot_index=0
+    fi
+    if [ $g_rotAngle -eq 90 ] && [ $g_mirDir -eq 0 ]; then
+        rot_index=1
+    fi
+    if [ $g_rotAngle -eq 270 ] && [ $g_mirDir -eq 3 ]; then 
+        rot_index=1
+    fi
+    if [ $g_rotAngle -eq 180 ] && [ $g_mirDir -eq 0 ]; then
+        rot_index=2
+    fi
+    if [ $g_rotAngle -eq 0 ] && [ $g_mirDir -eq 3 ]; then 
+        rot_index=2
+    fi
+    if [ $g_rotAngle -eq 270 ] && [ $g_mirDir -eq 0 ]; then
+        rot_index=3
+    fi
+    if [ $g_rotAngle -eq 90 ] && [ $g_mirDir -eq 3 ]; then
+        rot_index=3
+    fi
+    if [ $g_mirDir -eq 1 ] && [ $g_rotAngle -eq 0 ]; then
+        rot_index=4
+    fi
+    if [ $g_rotAngle -eq 180 ] && [ $g_mirDir -eq 2 ]; then 
+        rot_index=4
+    fi
+    if [ $g_mirDir -eq 1 ] && [ $g_rotAngle -eq 90 ]; then
+        rot_index=5
+    fi
+    if [ $g_mirDir -eq 2 ] && [ $g_rotAngle -eq 270 ]; then
+        rot_index=5
+    fi
+    if [ $g_mirDir -eq 1 ] && [ $g_rotAngle -eq 180 ]; then
+        rot_index=6
+    fi
+    if [ $g_mirDir -eq 2 ] && [ $g_rotAngle -eq 0 ]; then
+        rot_index=6
+    fi
+    if [ $g_mirDir -eq 1 ] && [ $g_rotAngle -eq 270 ]; then
+        rot_index=7
+    fi
+    if [ $g_mirDir -eq 2 ] && [ $g_rotAngle -eq 90 ]; then
+        rot_index=7
+    fi
+ 
+    local target_ext="yuv"
+
+    if [ "$streamset_name" = "" ]; then
+        target_path="${target_base}/${filename}${wtl_format_ext}${deblk_str}${thumbnail_ext}${yuvext}_${rot_index}.$target_ext"
+    else
+        # ex) xxxx_01.cmd -> xxxx.cmd
+        temp=`expr match "$streamset_name" '.*\(_[0-9]*\.cmd\)'`
+        if [ "$temp" != "" ]; then
+            streamset_name="${streamset_name%_[0-9]*\.cmd}.cmd"
+        fi
+        target_base="${target_base}/${streamset_name}"
+        target_path="${target_base}/${filename}${wtl_format_ext}${deblk_str}${dering_str}${thumbnail_ext}${yuvext}_${rot_index}.$target_ext"
+    fi
+
+    if [ ! -d $target_base ]; then
+        mkdir -p $target_base
+    fi
+
+    g_func_ret_str="$target_path"
+}
+
+# execute the ref-c program to get the decoded image or md5
+# generate_yuv(stream_path, output_yuv_path)
+function generate_yuv {
+    local src=$1
+    local output=$2
+
+    case "$codec" in
+        vp9)
+            echo "run_refc_dec_vp9 $src $output"
+            run_refc_dec_vp9 $src $output;;
+        hevc)
+            echo "run_refc_dec_h265 $src $output"
+            run_refc_dec_h265 $src $output;;
+        *)    
+            if [ "$g_product_name" = "coda960" ] || [ "$g_product_name" = "coda980" ]; then
+                echo "run_refc_dec_coda9 $src $output $codec"
+                run_refc_dec_coda9 $src $output $codec
+            else
+                echo "run_refc_dec_7l $src $output $codec"
+                run_refc_dec_7l $src $output $codec
+            fi
+            ;;
+    esac
+    if [ $? != 0 ]; then 
+        return 1; 
+    fi
+}
+
+
+# int get_product_id(test_prog)
+# \test_prog    -   test program (ex, w4_dec_test)
+# \return       -   It returns product id.
+function get_product_id {
+    local prog=$1
+    local version=""
+    local productId=0
+    local count=0
+
+    if [ ! -e $prog ] ; then
+        echo " $prog doesn't exist"; 
+        return 255
+    fi
+
+    str=`$prog -v ${fw_path}`
+    count=0
+    arr=()
+    oldIFS=$IFS
+    IFS=$'\n'
+    for f in ${str}; do
+        result=$(echo $f | grep 'VERSION\|REVISION\|PRODUCT_ID')
+        echo "result -> $result"
+        if [ "$result" != "" ]; then
+            f="${f/$'\r'/}"     # remove carriage return
+            arr[$count]=$f
+            count=$(($count+1))
+        fi
+    done
+    IFS=$oldIFS
+    version=$(echo ${arr[0]} | cut -d'=' -f2)
+    g_revision=$(echo ${arr[1]} | cut -d'=' -f2)
+    productId=$(echo ${arr[2]} | cut -d'=' -f2)
+    echo "F/W revision: ${g_revision} PRODUCT_ID: ${productId} "
+    return $productId
+}
+
+
+###############################################################################
+# ENCODER FUNCTIONS 
+###############################################################################
+# void c9_parse_cfg(cfg_path, &w, &h, &field_flag)
+# desc: parse cfg file to get width, height and field_flag information
+function c9_parse_cfg {
+    local _cfg_path="$1"
+    local _width=$2
+    local _height=$3
+    local _is_field=$4
+    local _name=""
+    local _firstchar=""
+
+    shopt -s nocasematch 
+    while read line; do
+    _firstchar=${line:0:1}
+    case "$_firstchar" in
+        "#") continue;;     # comment
+        ";") continue;;     # comment
+        "")  continue;;
+    esac
+    name=$(echo $line | cut -d' ' -f1)
+    if [ "$name" = "PICTURE_WIDTH" ]; then
+        eval $_width=$(echo $line | cut -d' ' -f2)
+    elif [ "$name" = "PICTURE_HEIGHT" ]; then
+        eval $_height=$(echo $line | cut -d' ' -f2)
+    elif [ "$name" = "INTERLACED_PIC" ]; then
+        eval $_is_field=$(echo $line | cut -d' ' -f2)
+    fi
+    done < $_cfg_path
+    shopt -u nocasematch 
+}
+
+# void c7_parse_cfg(cfg_path, &w, &h)
+# desc: parse cfg file to get width, height information
+function c7_parse_cfg {
+    local _cfg_path="$1"
+    local _width=$2
+    local _height=$3
+    local _name=""
+    local _firstchar=""
+
+    shopt -s nocasematch 
+    while read line; do
+    _firstchar=${line:0:1}
+    case "$_firstchar" in
+        "#") continue;;     # comment
+        ";") continue;;     # commen
+        "")  continue;;
+    esac
+    name=$(echo $line | cut -d' ' -f1)
+    if [ "$name" = "PICTURE_WIDTH" ]; then
+        eval $_width=$(echo $line | cut -d' ' -f2)
+    elif [ "$name" = "PICTURE_HEIGHT" ]; then
+        eval $_height=$(echo $line | cut -d' ' -f2)
+    fi
+    done < $_cfg_path
+    shopt -u nocasematch 
+}
+
+
+ 

+ 79 - 0
wave420l/code/config.h

@@ -0,0 +1,79 @@
+//------------------------------------------------------------------------------
+// File: config.h
+//
+// Copyright (c) 2006, Chips & Media.  All rights reserved.
+// This file should be modified by some developers of C&M according to product version.
+//------------------------------------------------------------------------------
+#ifndef __CONFIG_H__
+#define __CONFIG_H__
+
+#if defined(_WIN32) || defined(__WIN32__) || defined(_WIN64) || defined(WIN32) || defined(__MINGW32__)
+#	define PLATFORM_WIN32
+#elif defined(linux) || defined(__linux) || defined(ANDROID)
+#	define PLATFORM_LINUX
+#elif defined(unix) || defined(__unix)
+#   define PLATFORM_QNX
+#else
+#	define PLATFORM_NON_OS
+#endif
+
+#if defined(_MSC_VER)
+#	include <windows.h>
+#	define inline _inline
+#elif defined(__GNUC__)
+#elif defined(__ARMCC__)
+#else
+#  error "Unknown compiler."
+#endif
+
+#define API_VERSION_MAJOR       5
+#define API_VERSION_MINOR       5
+#define API_VERSION_PATCH       34
+#define API_VERSION             ((API_VERSION_MAJOR<<16) | (API_VERSION_MINOR<<8) | API_VERSION_PATCH)
+
+#if defined(PLATFORM_NON_OS) || defined (ANDROID) || defined(MFHMFT_EXPORTS) || defined(PLATFORM_QNX)
+//#define SUPPORT_FFMPEG_DEMUX
+#else
+#define SUPPORT_FFMPEG_DEMUX
+#endif
+
+//------------------------------------------------------------------------------
+// COMMON
+//------------------------------------------------------------------------------
+
+
+// do not define BIT_CODE_FILE_PATH in case of multiple product support. because wave410 and coda980 has different firmware binary format.
+#define CORE_0_BIT_CODE_FILE_PATH   "cezzane.bin"     // for wave420
+#define CORE_1_BIT_CODE_FILE_PATH   "coda980.out"     // for coda980
+#define CORE_2_BIT_CODE_FILE_PATH   "pissarro.bin"    // for wave412
+#define CORE_3_BIT_CODE_FILE_PATH   "michelangel.bin" // for wave410
+#define CORE_4_BIT_CODE_FILE_PATH   "coda960.out"     // for coda960
+#define CORE_5_BIT_CODE_FILE_PATH   "monet.bin"       // for wave420L
+#define CORE_6_BIT_CODE_FILE_PATH   "mondrian.bin"    // for wave510
+#define CORE_7_BIT_CODE_FILE_PATH   "picasso.bin"     // for wave510
+#define CORE_8_BIT_CODE_FILE_PATH   "kepler.bin"      // for wave515
+#define CORE_9_BIT_CODE_FILE_PATH   "millet.bin"      // for wave520
+
+//------------------------------------------------------------------------------
+// OMX
+//------------------------------------------------------------------------------
+
+
+
+
+
+//------------------------------------------------------------------------------
+// WAVE420
+//------------------------------------------------------------------------------
+//#define SUPPORT_ENCODE_CUSTOM_HEADER    // to make VUI/HRD/SEI data
+#ifdef SUPPORT_ENCODE_CUSTOM_HEADER
+//#define TEST_ENCODE_CUSTOM_HEADER
+#endif
+
+
+
+
+
+
+#endif /* __CONFIG_H__ */
+ 

+ 5029 - 0
wave420l/code/ffmpeg/include/libavcodec/avcodec.h

@@ -0,0 +1,5029 @@
+/*
+ * copyright (c) 2001 Fabrice Bellard
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_AVCODEC_H
+#define AVCODEC_AVCODEC_H
+
+/**
+ * @file
+ * @ingroup libavc
+ * Libavcodec external API header
+ */
+
+#include <errno.h>
+#include "libavutil/samplefmt.h"
+#include "libavutil/attributes.h"
+#include "libavutil/avutil.h"
+#include "libavutil/buffer.h"
+#include "libavutil/cpu.h"
+#include "libavutil/channel_layout.h"
+#include "libavutil/dict.h"
+#include "libavutil/frame.h"
+#include "libavutil/log.h"
+#include "libavutil/pixfmt.h"
+#include "libavutil/rational.h"
+
+#include "version.h"
+
+/**
+ * @defgroup libavc Encoding/Decoding Library
+ * @{
+ *
+ * @defgroup lavc_decoding Decoding
+ * @{
+ * @}
+ *
+ * @defgroup lavc_encoding Encoding
+ * @{
+ * @}
+ *
+ * @defgroup lavc_codec Codecs
+ * @{
+ * @defgroup lavc_codec_native Native Codecs
+ * @{
+ * @}
+ * @defgroup lavc_codec_wrappers External library wrappers
+ * @{
+ * @}
+ * @defgroup lavc_codec_hwaccel Hardware Accelerators bridge
+ * @{
+ * @}
+ * @}
+ * @defgroup lavc_internal Internal
+ * @{
+ * @}
+ * @}
+ *
+ */
+
+/**
+ * @defgroup lavc_core Core functions/structures.
+ * @ingroup libavc
+ *
+ * Basic definitions, functions for querying libavcodec capabilities,
+ * allocating core structures, etc.
+ * @{
+ */
+
+
+/**
+ * Identify the syntax and semantics of the bitstream.
+ * The principle is roughly:
+ * Two decoders with the same ID can decode the same streams.
+ * Two encoders with the same ID can encode compatible streams.
+ * There may be slight deviations from the principle due to implementation
+ * details.
+ *
+ * If you add a codec ID to this list, add it so that
+ * 1. no value of a existing codec ID changes (that would break ABI),
+ * 2. Give it a value which when taken as ASCII is recognized uniquely by a human as this specific codec.
+ *    This ensures that 2 forks can independently add AVCodecIDs without producing conflicts.
+ *
+ * After adding new codec IDs, do not forget to add an entry to the codec
+ * descriptor list and bump libavcodec minor version.
+ */
+enum AVCodecID {
+    AV_CODEC_ID_NONE,
+
+    /* video codecs */
+    AV_CODEC_ID_MPEG1VIDEO,
+    AV_CODEC_ID_MPEG2VIDEO, ///< preferred ID for MPEG-1/2 video decoding
+    AV_CODEC_ID_MPEG2VIDEO_XVMC,
+    AV_CODEC_ID_H261,
+    AV_CODEC_ID_H263,
+    AV_CODEC_ID_RV10,
+    AV_CODEC_ID_RV20,
+    AV_CODEC_ID_MJPEG,
+    AV_CODEC_ID_MJPEGB,
+    AV_CODEC_ID_LJPEG,
+    AV_CODEC_ID_SP5X,
+    AV_CODEC_ID_JPEGLS,
+    AV_CODEC_ID_MPEG4,
+    AV_CODEC_ID_RAWVIDEO,
+    AV_CODEC_ID_MSMPEG4V1,
+    AV_CODEC_ID_MSMPEG4V2,
+    AV_CODEC_ID_MSMPEG4V3,
+    AV_CODEC_ID_WMV1,
+    AV_CODEC_ID_WMV2,
+    AV_CODEC_ID_H263P,
+    AV_CODEC_ID_H263I,
+    AV_CODEC_ID_FLV1,
+    AV_CODEC_ID_SVQ1,
+    AV_CODEC_ID_SVQ3,
+    AV_CODEC_ID_DVVIDEO,
+    AV_CODEC_ID_HUFFYUV,
+    AV_CODEC_ID_CYUV,
+    AV_CODEC_ID_H264,
+    AV_CODEC_ID_INDEO3,
+    AV_CODEC_ID_VP3,
+    AV_CODEC_ID_THEORA,
+    AV_CODEC_ID_ASV1,
+    AV_CODEC_ID_ASV2,
+    AV_CODEC_ID_FFV1,
+    AV_CODEC_ID_4XM,
+    AV_CODEC_ID_VCR1,
+    AV_CODEC_ID_CLJR,
+    AV_CODEC_ID_MDEC,
+    AV_CODEC_ID_ROQ,
+    AV_CODEC_ID_INTERPLAY_VIDEO,
+    AV_CODEC_ID_XAN_WC3,
+    AV_CODEC_ID_XAN_WC4,
+    AV_CODEC_ID_RPZA,
+    AV_CODEC_ID_CINEPAK,
+    AV_CODEC_ID_WS_VQA,
+    AV_CODEC_ID_MSRLE,
+    AV_CODEC_ID_MSVIDEO1,
+    AV_CODEC_ID_IDCIN,
+    AV_CODEC_ID_8BPS,
+    AV_CODEC_ID_SMC,
+    AV_CODEC_ID_FLIC,
+    AV_CODEC_ID_TRUEMOTION1,
+    AV_CODEC_ID_VMDVIDEO,
+    AV_CODEC_ID_MSZH,
+    AV_CODEC_ID_ZLIB,
+    AV_CODEC_ID_QTRLE,
+    AV_CODEC_ID_TSCC,
+    AV_CODEC_ID_ULTI,
+    AV_CODEC_ID_QDRAW,
+    AV_CODEC_ID_VIXL,
+    AV_CODEC_ID_QPEG,
+    AV_CODEC_ID_PNG,
+    AV_CODEC_ID_PPM,
+    AV_CODEC_ID_PBM,
+    AV_CODEC_ID_PGM,
+    AV_CODEC_ID_PGMYUV,
+    AV_CODEC_ID_PAM,
+    AV_CODEC_ID_FFVHUFF,
+    AV_CODEC_ID_RV30,
+    AV_CODEC_ID_RV40,
+    AV_CODEC_ID_VC1,
+    AV_CODEC_ID_WMV3,
+    AV_CODEC_ID_LOCO,
+    AV_CODEC_ID_WNV1,
+    AV_CODEC_ID_AASC,
+    AV_CODEC_ID_INDEO2,
+    AV_CODEC_ID_FRAPS,
+    AV_CODEC_ID_TRUEMOTION2,
+    AV_CODEC_ID_BMP,
+    AV_CODEC_ID_CSCD,
+    AV_CODEC_ID_MMVIDEO,
+    AV_CODEC_ID_ZMBV,
+    AV_CODEC_ID_AVS,
+    AV_CODEC_ID_SMACKVIDEO,
+    AV_CODEC_ID_NUV,
+    AV_CODEC_ID_KMVC,
+    AV_CODEC_ID_FLASHSV,
+    AV_CODEC_ID_CAVS,
+    AV_CODEC_ID_JPEG2000,
+    AV_CODEC_ID_VMNC,
+    AV_CODEC_ID_VP5,
+    AV_CODEC_ID_VP6,
+    AV_CODEC_ID_VP6F,
+    AV_CODEC_ID_TARGA,
+    AV_CODEC_ID_DSICINVIDEO,
+    AV_CODEC_ID_TIERTEXSEQVIDEO,
+    AV_CODEC_ID_TIFF,
+    AV_CODEC_ID_GIF,
+    AV_CODEC_ID_DXA,
+    AV_CODEC_ID_DNXHD,
+    AV_CODEC_ID_THP,
+    AV_CODEC_ID_SGI,
+    AV_CODEC_ID_C93,
+    AV_CODEC_ID_BETHSOFTVID,
+    AV_CODEC_ID_PTX,
+    AV_CODEC_ID_TXD,
+    AV_CODEC_ID_VP6A,
+    AV_CODEC_ID_AMV,
+    AV_CODEC_ID_VB,
+    AV_CODEC_ID_PCX,
+    AV_CODEC_ID_SUNRAST,
+    AV_CODEC_ID_INDEO4,
+    AV_CODEC_ID_INDEO5,
+    AV_CODEC_ID_MIMIC,
+    AV_CODEC_ID_RL2,
+    AV_CODEC_ID_ESCAPE124,
+    AV_CODEC_ID_DIRAC,
+    AV_CODEC_ID_BFI,
+    AV_CODEC_ID_CMV,
+    AV_CODEC_ID_MOTIONPIXELS,
+    AV_CODEC_ID_TGV,
+    AV_CODEC_ID_TGQ,
+    AV_CODEC_ID_TQI,
+    AV_CODEC_ID_AURA,
+    AV_CODEC_ID_AURA2,
+    AV_CODEC_ID_V210X,
+    AV_CODEC_ID_TMV,
+    AV_CODEC_ID_V210,
+    AV_CODEC_ID_DPX,
+    AV_CODEC_ID_MAD,
+    AV_CODEC_ID_FRWU,
+    AV_CODEC_ID_FLASHSV2,
+    AV_CODEC_ID_CDGRAPHICS,
+    AV_CODEC_ID_R210,
+    AV_CODEC_ID_ANM,
+    AV_CODEC_ID_BINKVIDEO,
+    AV_CODEC_ID_IFF_ILBM,
+    AV_CODEC_ID_IFF_BYTERUN1,
+    AV_CODEC_ID_KGV1,
+    AV_CODEC_ID_YOP,
+    AV_CODEC_ID_VP8,
+    AV_CODEC_ID_PICTOR,
+    AV_CODEC_ID_ANSI,
+    AV_CODEC_ID_A64_MULTI,
+    AV_CODEC_ID_A64_MULTI5,
+    AV_CODEC_ID_R10K,
+    AV_CODEC_ID_MXPEG,
+    AV_CODEC_ID_LAGARITH,
+    AV_CODEC_ID_PRORES,
+    AV_CODEC_ID_JV,
+    AV_CODEC_ID_DFA,
+    AV_CODEC_ID_WMV3IMAGE,
+    AV_CODEC_ID_VC1IMAGE,
+    AV_CODEC_ID_UTVIDEO,
+    AV_CODEC_ID_BMV_VIDEO,
+    AV_CODEC_ID_VBLE,
+    AV_CODEC_ID_DXTORY,
+    AV_CODEC_ID_V410,
+    AV_CODEC_ID_XWD,
+    AV_CODEC_ID_CDXL,
+    AV_CODEC_ID_XBM,
+    AV_CODEC_ID_ZEROCODEC,
+    AV_CODEC_ID_MSS1,
+    AV_CODEC_ID_MSA1,
+    AV_CODEC_ID_TSCC2,
+    AV_CODEC_ID_MTS2,
+    AV_CODEC_ID_CLLC,
+    AV_CODEC_ID_MSS2,
+    AV_CODEC_ID_VP9,
+    AV_CODEC_ID_AIC,
+    AV_CODEC_ID_ESCAPE130_DEPRECATED,
+    AV_CODEC_ID_G2M_DEPRECATED,
+    AV_CODEC_ID_WEBP_DEPRECATED,
+
+    AV_CODEC_ID_BRENDER_PIX= MKBETAG('B','P','I','X'),
+    AV_CODEC_ID_Y41P       = MKBETAG('Y','4','1','P'),
+    AV_CODEC_ID_ESCAPE130  = MKBETAG('E','1','3','0'),
+    AV_CODEC_ID_EXR        = MKBETAG('0','E','X','R'),
+    AV_CODEC_ID_AVRP       = MKBETAG('A','V','R','P'),
+
+    AV_CODEC_ID_012V       = MKBETAG('0','1','2','V'),
+    AV_CODEC_ID_G2M        = MKBETAG( 0 ,'G','2','M'),
+    AV_CODEC_ID_AVUI       = MKBETAG('A','V','U','I'),
+    AV_CODEC_ID_AYUV       = MKBETAG('A','Y','U','V'),
+    AV_CODEC_ID_TARGA_Y216 = MKBETAG('T','2','1','6'),
+    AV_CODEC_ID_V308       = MKBETAG('V','3','0','8'),
+    AV_CODEC_ID_V408       = MKBETAG('V','4','0','8'),
+    AV_CODEC_ID_YUV4       = MKBETAG('Y','U','V','4'),
+    AV_CODEC_ID_SANM       = MKBETAG('S','A','N','M'),
+    AV_CODEC_ID_PAF_VIDEO  = MKBETAG('P','A','F','V'),
+    AV_CODEC_ID_AVRN       = MKBETAG('A','V','R','n'),
+    AV_CODEC_ID_CPIA       = MKBETAG('C','P','I','A'),
+    AV_CODEC_ID_XFACE      = MKBETAG('X','F','A','C'),
+    AV_CODEC_ID_SGIRLE     = MKBETAG('S','G','I','R'),
+    AV_CODEC_ID_MVC1       = MKBETAG('M','V','C','1'),
+    AV_CODEC_ID_MVC2       = MKBETAG('M','V','C','2'),
+    AV_CODEC_ID_SNOW       = MKBETAG('S','N','O','W'),
+    AV_CODEC_ID_WEBP       = MKBETAG('W','E','B','P'),
+    AV_CODEC_ID_SMVJPEG    = MKBETAG('S','M','V','J'),
+    AV_CODEC_ID_HEVC       = MKBETAG('H','2','6','5'),
+#define AV_CODEC_ID_H265 AV_CODEC_ID_HEVC
+
+    /* various PCM "codecs" */
+    AV_CODEC_ID_FIRST_AUDIO = 0x10000,     ///< A dummy id pointing at the start of audio codecs
+    AV_CODEC_ID_PCM_S16LE = 0x10000,
+    AV_CODEC_ID_PCM_S16BE,
+    AV_CODEC_ID_PCM_U16LE,
+    AV_CODEC_ID_PCM_U16BE,
+    AV_CODEC_ID_PCM_S8,
+    AV_CODEC_ID_PCM_U8,
+    AV_CODEC_ID_PCM_MULAW,
+    AV_CODEC_ID_PCM_ALAW,
+    AV_CODEC_ID_PCM_S32LE,
+    AV_CODEC_ID_PCM_S32BE,
+    AV_CODEC_ID_PCM_U32LE,
+    AV_CODEC_ID_PCM_U32BE,
+    AV_CODEC_ID_PCM_S24LE,
+    AV_CODEC_ID_PCM_S24BE,
+    AV_CODEC_ID_PCM_U24LE,
+    AV_CODEC_ID_PCM_U24BE,
+    AV_CODEC_ID_PCM_S24DAUD,
+    AV_CODEC_ID_PCM_ZORK,
+    AV_CODEC_ID_PCM_S16LE_PLANAR,
+    AV_CODEC_ID_PCM_DVD,
+    AV_CODEC_ID_PCM_F32BE,
+    AV_CODEC_ID_PCM_F32LE,
+    AV_CODEC_ID_PCM_F64BE,
+    AV_CODEC_ID_PCM_F64LE,
+    AV_CODEC_ID_PCM_BLURAY,
+    AV_CODEC_ID_PCM_LXF,
+    AV_CODEC_ID_S302M,
+    AV_CODEC_ID_PCM_S8_PLANAR,
+    AV_CODEC_ID_PCM_S24LE_PLANAR_DEPRECATED,
+    AV_CODEC_ID_PCM_S32LE_PLANAR_DEPRECATED,
+    AV_CODEC_ID_PCM_S24LE_PLANAR = MKBETAG(24,'P','S','P'),
+    AV_CODEC_ID_PCM_S32LE_PLANAR = MKBETAG(32,'P','S','P'),
+    AV_CODEC_ID_PCM_S16BE_PLANAR = MKBETAG('P','S','P',16),
+
+    /* various ADPCM codecs */
+    AV_CODEC_ID_ADPCM_IMA_QT = 0x11000,
+    AV_CODEC_ID_ADPCM_IMA_WAV,
+    AV_CODEC_ID_ADPCM_IMA_DK3,
+    AV_CODEC_ID_ADPCM_IMA_DK4,
+    AV_CODEC_ID_ADPCM_IMA_WS,
+    AV_CODEC_ID_ADPCM_IMA_SMJPEG,
+    AV_CODEC_ID_ADPCM_MS,
+    AV_CODEC_ID_ADPCM_4XM,
+    AV_CODEC_ID_ADPCM_XA,
+    AV_CODEC_ID_ADPCM_ADX,
+    AV_CODEC_ID_ADPCM_EA,
+    AV_CODEC_ID_ADPCM_G726,
+    AV_CODEC_ID_ADPCM_CT,
+    AV_CODEC_ID_ADPCM_SWF,
+    AV_CODEC_ID_ADPCM_YAMAHA,
+    AV_CODEC_ID_ADPCM_SBPRO_4,
+    AV_CODEC_ID_ADPCM_SBPRO_3,
+    AV_CODEC_ID_ADPCM_SBPRO_2,
+    AV_CODEC_ID_ADPCM_THP,
+    AV_CODEC_ID_ADPCM_IMA_AMV,
+    AV_CODEC_ID_ADPCM_EA_R1,
+    AV_CODEC_ID_ADPCM_EA_R3,
+    AV_CODEC_ID_ADPCM_EA_R2,
+    AV_CODEC_ID_ADPCM_IMA_EA_SEAD,
+    AV_CODEC_ID_ADPCM_IMA_EA_EACS,
+    AV_CODEC_ID_ADPCM_EA_XAS,
+    AV_CODEC_ID_ADPCM_EA_MAXIS_XA,
+    AV_CODEC_ID_ADPCM_IMA_ISS,
+    AV_CODEC_ID_ADPCM_G722,
+    AV_CODEC_ID_ADPCM_IMA_APC,
+    AV_CODEC_ID_VIMA       = MKBETAG('V','I','M','A'),
+    AV_CODEC_ID_ADPCM_AFC  = MKBETAG('A','F','C',' '),
+    AV_CODEC_ID_ADPCM_IMA_OKI = MKBETAG('O','K','I',' '),
+    AV_CODEC_ID_ADPCM_DTK  = MKBETAG('D','T','K',' '),
+    AV_CODEC_ID_ADPCM_IMA_RAD = MKBETAG('R','A','D',' '),
+    AV_CODEC_ID_ADPCM_G726LE = MKBETAG('6','2','7','G'),
+
+    /* AMR */
+    AV_CODEC_ID_AMR_NB = 0x12000,
+    AV_CODEC_ID_AMR_WB,
+
+    /* RealAudio codecs*/
+    AV_CODEC_ID_RA_144 = 0x13000,
+    AV_CODEC_ID_RA_288,
+
+    /* various DPCM codecs */
+    AV_CODEC_ID_ROQ_DPCM = 0x14000,
+    AV_CODEC_ID_INTERPLAY_DPCM,
+    AV_CODEC_ID_XAN_DPCM,
+    AV_CODEC_ID_SOL_DPCM,
+
+    /* audio codecs */
+    AV_CODEC_ID_MP2 = 0x15000,
+    AV_CODEC_ID_MP3, ///< preferred ID for decoding MPEG audio layer 1, 2 or 3
+    AV_CODEC_ID_AAC,
+    AV_CODEC_ID_AC3,
+    AV_CODEC_ID_DTS,
+    AV_CODEC_ID_VORBIS,
+    AV_CODEC_ID_DVAUDIO,
+    AV_CODEC_ID_WMAV1,
+    AV_CODEC_ID_WMAV2,
+    AV_CODEC_ID_MACE3,
+    AV_CODEC_ID_MACE6,
+    AV_CODEC_ID_VMDAUDIO,
+    AV_CODEC_ID_FLAC,
+    AV_CODEC_ID_MP3ADU,
+    AV_CODEC_ID_MP3ON4,
+    AV_CODEC_ID_SHORTEN,
+    AV_CODEC_ID_ALAC,
+    AV_CODEC_ID_WESTWOOD_SND1,
+    AV_CODEC_ID_GSM, ///< as in Berlin toast format
+    AV_CODEC_ID_QDM2,
+    AV_CODEC_ID_COOK,
+    AV_CODEC_ID_TRUESPEECH,
+    AV_CODEC_ID_TTA,
+    AV_CODEC_ID_SMACKAUDIO,
+    AV_CODEC_ID_QCELP,
+    AV_CODEC_ID_WAVPACK,
+    AV_CODEC_ID_DSICINAUDIO,
+    AV_CODEC_ID_IMC,
+    AV_CODEC_ID_MUSEPACK7,
+    AV_CODEC_ID_MLP,
+    AV_CODEC_ID_GSM_MS, /* as found in WAV */
+    AV_CODEC_ID_ATRAC3,
+#if FF_API_VOXWARE
+    AV_CODEC_ID_VOXWARE,
+#endif
+    AV_CODEC_ID_APE,
+    AV_CODEC_ID_NELLYMOSER,
+    AV_CODEC_ID_MUSEPACK8,
+    AV_CODEC_ID_SPEEX,
+    AV_CODEC_ID_WMAVOICE,
+    AV_CODEC_ID_WMAPRO,
+    AV_CODEC_ID_WMALOSSLESS,
+    AV_CODEC_ID_ATRAC3P,
+    AV_CODEC_ID_EAC3,
+    AV_CODEC_ID_SIPR,
+    AV_CODEC_ID_MP1,
+    AV_CODEC_ID_TWINVQ,
+    AV_CODEC_ID_TRUEHD,
+    AV_CODEC_ID_MP4ALS,
+    AV_CODEC_ID_ATRAC1,
+    AV_CODEC_ID_BINKAUDIO_RDFT,
+    AV_CODEC_ID_BINKAUDIO_DCT,
+    AV_CODEC_ID_AAC_LATM,
+    AV_CODEC_ID_QDMC,
+    AV_CODEC_ID_CELT,
+    AV_CODEC_ID_G723_1,
+    AV_CODEC_ID_G729,
+    AV_CODEC_ID_8SVX_EXP,
+    AV_CODEC_ID_8SVX_FIB,
+    AV_CODEC_ID_BMV_AUDIO,
+    AV_CODEC_ID_RALF,
+    AV_CODEC_ID_IAC,
+    AV_CODEC_ID_ILBC,
+    AV_CODEC_ID_OPUS_DEPRECATED,
+    AV_CODEC_ID_COMFORT_NOISE,
+    AV_CODEC_ID_TAK_DEPRECATED,
+    AV_CODEC_ID_METASOUND,
+    AV_CODEC_ID_FFWAVESYNTH = MKBETAG('F','F','W','S'),
+    AV_CODEC_ID_SONIC       = MKBETAG('S','O','N','C'),
+    AV_CODEC_ID_SONIC_LS    = MKBETAG('S','O','N','L'),
+    AV_CODEC_ID_PAF_AUDIO   = MKBETAG('P','A','F','A'),
+    AV_CODEC_ID_OPUS        = MKBETAG('O','P','U','S'),
+    AV_CODEC_ID_TAK         = MKBETAG('t','B','a','K'),
+    AV_CODEC_ID_EVRC        = MKBETAG('s','e','v','c'),
+    AV_CODEC_ID_SMV         = MKBETAG('s','s','m','v'),
+
+    /* subtitle codecs */
+    AV_CODEC_ID_FIRST_SUBTITLE = 0x17000,          ///< A dummy ID pointing at the start of subtitle codecs.
+    AV_CODEC_ID_DVD_SUBTITLE = 0x17000,
+    AV_CODEC_ID_DVB_SUBTITLE,
+    AV_CODEC_ID_TEXT,  ///< raw UTF-8 text
+    AV_CODEC_ID_XSUB,
+    AV_CODEC_ID_SSA,
+    AV_CODEC_ID_MOV_TEXT,
+    AV_CODEC_ID_HDMV_PGS_SUBTITLE,
+    AV_CODEC_ID_DVB_TELETEXT,
+    AV_CODEC_ID_SRT,
+    AV_CODEC_ID_MICRODVD   = MKBETAG('m','D','V','D'),
+    AV_CODEC_ID_EIA_608    = MKBETAG('c','6','0','8'),
+    AV_CODEC_ID_JACOSUB    = MKBETAG('J','S','U','B'),
+    AV_CODEC_ID_SAMI       = MKBETAG('S','A','M','I'),
+    AV_CODEC_ID_REALTEXT   = MKBETAG('R','T','X','T'),
+    AV_CODEC_ID_SUBVIEWER1 = MKBETAG('S','b','V','1'),
+    AV_CODEC_ID_SUBVIEWER  = MKBETAG('S','u','b','V'),
+    AV_CODEC_ID_SUBRIP     = MKBETAG('S','R','i','p'),
+    AV_CODEC_ID_WEBVTT     = MKBETAG('W','V','T','T'),
+    AV_CODEC_ID_MPL2       = MKBETAG('M','P','L','2'),
+    AV_CODEC_ID_VPLAYER    = MKBETAG('V','P','l','r'),
+    AV_CODEC_ID_PJS        = MKBETAG('P','h','J','S'),
+    AV_CODEC_ID_ASS        = MKBETAG('A','S','S',' '),  ///< ASS as defined in Matroska
+
+    /* other specific kind of codecs (generally used for attachments) */
+    AV_CODEC_ID_FIRST_UNKNOWN = 0x18000,           ///< A dummy ID pointing at the start of various fake codecs.
+    AV_CODEC_ID_TTF = 0x18000,
+    AV_CODEC_ID_BINTEXT    = MKBETAG('B','T','X','T'),
+    AV_CODEC_ID_XBIN       = MKBETAG('X','B','I','N'),
+    AV_CODEC_ID_IDF        = MKBETAG( 0 ,'I','D','F'),
+    AV_CODEC_ID_OTF        = MKBETAG( 0 ,'O','T','F'),
+    AV_CODEC_ID_SMPTE_KLV  = MKBETAG('K','L','V','A'),
+    AV_CODEC_ID_DVD_NAV    = MKBETAG('D','N','A','V'),
+
+
+    AV_CODEC_ID_PROBE = 0x19000, ///< codec_id is not known (like AV_CODEC_ID_NONE) but lavf should attempt to identify it
+
+    AV_CODEC_ID_MPEG2TS = 0x20000, /**< _FAKE_ codec to indicate a raw MPEG-2 TS
+                                * stream (only used by libavformat) */
+    AV_CODEC_ID_MPEG4SYSTEMS = 0x20001, /**< _FAKE_ codec to indicate a MPEG-4 Systems
+                                * stream (only used by libavformat) */
+    AV_CODEC_ID_FFMETADATA = 0x21000,   ///< Dummy codec for streams containing only metadata information.
+
+#if FF_API_CODEC_ID
+#include "old_codec_ids.h"
+#endif
+};
+
+/**
+ * This struct describes the properties of a single codec described by an
+ * AVCodecID.
+ * @see avcodec_get_descriptor()
+ */
+typedef struct AVCodecDescriptor {
+    enum AVCodecID     id;
+    enum AVMediaType type;
+    /**
+     * Name of the codec described by this descriptor. It is non-empty and
+     * unique for each codec descriptor. It should contain alphanumeric
+     * characters and '_' only.
+     */
+    const char      *name;
+    /**
+     * A more descriptive name for this codec. May be NULL.
+     */
+    const char *long_name;
+    /**
+     * Codec properties, a combination of AV_CODEC_PROP_* flags.
+     */
+    int             props;
+} AVCodecDescriptor;
+
+/**
+ * Codec uses only intra compression.
+ * Video codecs only.
+ */
+#define AV_CODEC_PROP_INTRA_ONLY    (1 << 0)
+/**
+ * Codec supports lossy compression. Audio and video codecs only.
+ * @note a codec may support both lossy and lossless
+ * compression modes
+ */
+#define AV_CODEC_PROP_LOSSY         (1 << 1)
+/**
+ * Codec supports lossless compression. Audio and video codecs only.
+ */
+#define AV_CODEC_PROP_LOSSLESS      (1 << 2)
+/**
+ * Subtitle codec is bitmap based
+ * Decoded AVSubtitle data can be read from the AVSubtitleRect->pict field.
+ */
+#define AV_CODEC_PROP_BITMAP_SUB    (1 << 16)
+/**
+ * Subtitle codec is text based.
+ * Decoded AVSubtitle data can be read from the AVSubtitleRect->ass field.
+ */
+#define AV_CODEC_PROP_TEXT_SUB      (1 << 17)
+
+/**
+ * @ingroup lavc_decoding
+ * Required number of additionally allocated bytes at the end of the input bitstream for decoding.
+ * This is mainly needed because some optimized bitstream readers read
+ * 32 or 64 bit at once and could read over the end.<br>
+ * Note: If the first 23 bits of the additional bytes are not 0, then damaged
+ * MPEG bitstreams could cause overread and segfault.
+ */
+#define FF_INPUT_BUFFER_PADDING_SIZE 16
+
+/**
+ * @ingroup lavc_encoding
+ * minimum encoding buffer size
+ * Used to avoid some checks during header writing.
+ */
+#define FF_MIN_BUFFER_SIZE 16384
+
+
+/**
+ * @ingroup lavc_encoding
+ * motion estimation type.
+ */
+enum Motion_Est_ID {
+    ME_ZERO = 1,    ///< no search, that is use 0,0 vector whenever one is needed
+    ME_FULL,
+    ME_LOG,
+    ME_PHODS,
+    ME_EPZS,        ///< enhanced predictive zonal search
+    ME_X1,          ///< reserved for experiments
+    ME_HEX,         ///< hexagon based search
+    ME_UMH,         ///< uneven multi-hexagon search
+    ME_TESA,        ///< transformed exhaustive search algorithm
+    ME_ITER=50,     ///< iterative search
+};
+
+/**
+ * @ingroup lavc_decoding
+ */
+enum AVDiscard{
+    /* We leave some space between them for extensions (drop some
+     * keyframes for intra-only or drop just some bidir frames). */
+    AVDISCARD_NONE    =-16, ///< discard nothing
+    AVDISCARD_DEFAULT =  0, ///< discard useless packets like 0 size packets in avi
+    AVDISCARD_NONREF  =  8, ///< discard all non reference
+    AVDISCARD_BIDIR   = 16, ///< discard all bidirectional frames
+    AVDISCARD_NONKEY  = 32, ///< discard all frames except keyframes
+    AVDISCARD_ALL     = 48, ///< discard all
+};
+
+enum AVColorPrimaries{
+    AVCOL_PRI_BT709       = 1, ///< also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP177 Annex B
+    AVCOL_PRI_UNSPECIFIED = 2,
+    AVCOL_PRI_BT470M      = 4,
+    AVCOL_PRI_BT470BG     = 5, ///< also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM
+    AVCOL_PRI_SMPTE170M   = 6, ///< also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
+    AVCOL_PRI_SMPTE240M   = 7, ///< functionally identical to above
+    AVCOL_PRI_FILM        = 8,
+    AVCOL_PRI_NB             , ///< Not part of ABI
+};
+
+enum AVColorTransferCharacteristic{
+    AVCOL_TRC_BT709       = 1, ///< also ITU-R BT1361
+    AVCOL_TRC_UNSPECIFIED = 2,
+    AVCOL_TRC_GAMMA22     = 4, ///< also ITU-R BT470M / ITU-R BT1700 625 PAL & SECAM
+    AVCOL_TRC_GAMMA28     = 5, ///< also ITU-R BT470BG
+    AVCOL_TRC_SMPTE240M   = 7,
+    AVCOL_TRC_NB             , ///< Not part of ABI
+};
+
+/**
+ *  X   X      3 4 X      X are luma samples,
+ *             1 2        1-6 are possible chroma positions
+ *  X   X      5 6 X      0 is undefined/unknown position
+ */
+enum AVChromaLocation{
+    AVCHROMA_LOC_UNSPECIFIED = 0,
+    AVCHROMA_LOC_LEFT        = 1, ///< mpeg2/4, h264 default
+    AVCHROMA_LOC_CENTER      = 2, ///< mpeg1, jpeg, h263
+    AVCHROMA_LOC_TOPLEFT     = 3, ///< DV
+    AVCHROMA_LOC_TOP         = 4,
+    AVCHROMA_LOC_BOTTOMLEFT  = 5,
+    AVCHROMA_LOC_BOTTOM      = 6,
+    AVCHROMA_LOC_NB             , ///< Not part of ABI
+};
+
+enum AVAudioServiceType {
+    AV_AUDIO_SERVICE_TYPE_MAIN              = 0,
+    AV_AUDIO_SERVICE_TYPE_EFFECTS           = 1,
+    AV_AUDIO_SERVICE_TYPE_VISUALLY_IMPAIRED = 2,
+    AV_AUDIO_SERVICE_TYPE_HEARING_IMPAIRED  = 3,
+    AV_AUDIO_SERVICE_TYPE_DIALOGUE          = 4,
+    AV_AUDIO_SERVICE_TYPE_COMMENTARY        = 5,
+    AV_AUDIO_SERVICE_TYPE_EMERGENCY         = 6,
+    AV_AUDIO_SERVICE_TYPE_VOICE_OVER        = 7,
+    AV_AUDIO_SERVICE_TYPE_KARAOKE           = 8,
+    AV_AUDIO_SERVICE_TYPE_NB                   , ///< Not part of ABI
+};
+
+/**
+ * @ingroup lavc_encoding
+ */
+typedef struct RcOverride{
+    int start_frame;
+    int end_frame;
+    int qscale; // If this is 0 then quality_factor will be used instead.
+    float quality_factor;
+} RcOverride;
+
+#define FF_MAX_B_FRAMES 16
+
+/* encoding support
+   These flags can be passed in AVCodecContext.flags before initialization.
+   Note: Not everything is supported yet.
+*/
+
+/**
+ * Allow decoders to produce frames with data planes that are not aligned
+ * to CPU requirements (e.g. due to cropping).
+ */
+#define CODEC_FLAG_UNALIGNED 0x0001
+#define CODEC_FLAG_QSCALE 0x0002  ///< Use fixed qscale.
+#define CODEC_FLAG_4MV    0x0004  ///< 4 MV per MB allowed / advanced prediction for H.263.
+#define CODEC_FLAG_QPEL   0x0010  ///< Use qpel MC.
+#define CODEC_FLAG_GMC    0x0020  ///< Use GMC.
+#define CODEC_FLAG_MV0    0x0040  ///< Always try a MB with MV=<0,0>.
+/**
+ * The parent program guarantees that the input for B-frames containing
+ * streams is not written to for at least s->max_b_frames+1 frames, if
+ * this is not set the input will be copied.
+ */
+#define CODEC_FLAG_INPUT_PRESERVED 0x0100
+#define CODEC_FLAG_PASS1           0x0200   ///< Use internal 2pass ratecontrol in first pass mode.
+#define CODEC_FLAG_PASS2           0x0400   ///< Use internal 2pass ratecontrol in second pass mode.
+#define CODEC_FLAG_GRAY            0x2000   ///< Only decode/encode grayscale.
+#define CODEC_FLAG_EMU_EDGE        0x4000   ///< Don't draw edges.
+#define CODEC_FLAG_PSNR            0x8000   ///< error[?] variables will be set during encoding.
+#define CODEC_FLAG_TRUNCATED       0x00010000 /** Input bitstream might be truncated at a random
+                                                  location instead of only at frame boundaries. */
+#define CODEC_FLAG_NORMALIZE_AQP  0x00020000 ///< Normalize adaptive quantization.
+#define CODEC_FLAG_INTERLACED_DCT 0x00040000 ///< Use interlaced DCT.
+#define CODEC_FLAG_LOW_DELAY      0x00080000 ///< Force low delay.
+#define CODEC_FLAG_GLOBAL_HEADER  0x00400000 ///< Place global headers in extradata instead of every keyframe.
+#define CODEC_FLAG_BITEXACT       0x00800000 ///< Use only bitexact stuff (except (I)DCT).
+/* Fx : Flag for h263+ extra options */
+#define CODEC_FLAG_AC_PRED        0x01000000 ///< H.263 advanced intra coding / MPEG-4 AC prediction
+#define CODEC_FLAG_LOOP_FILTER    0x00000800 ///< loop filter
+#define CODEC_FLAG_INTERLACED_ME  0x20000000 ///< interlaced motion estimation
+#define CODEC_FLAG_CLOSED_GOP     0x80000000
+#define CODEC_FLAG2_FAST          0x00000001 ///< Allow non spec compliant speedup tricks.
+#define CODEC_FLAG2_NO_OUTPUT     0x00000004 ///< Skip bitstream encoding.
+#define CODEC_FLAG2_LOCAL_HEADER  0x00000008 ///< Place global headers at every keyframe instead of in extradata.
+#define CODEC_FLAG2_DROP_FRAME_TIMECODE 0x00002000 ///< timecode is in drop frame format. DEPRECATED!!!!
+#define CODEC_FLAG2_IGNORE_CROP   0x00010000 ///< Discard cropping information from SPS.
+
+#define CODEC_FLAG2_CHUNKS        0x00008000 ///< Input bitstream might be truncated at a packet boundaries instead of only at frame boundaries.
+#define CODEC_FLAG2_SHOW_ALL      0x00400000 ///< Show all frames before the first keyframe
+
+/* Unsupported options :
+ *              Syntax Arithmetic coding (SAC)
+ *              Reference Picture Selection
+ *              Independent Segment Decoding */
+/* /Fx */
+/* codec capabilities */
+
+#define CODEC_CAP_DRAW_HORIZ_BAND 0x0001 ///< Decoder can use draw_horiz_band callback.
+/**
+ * Codec uses get_buffer() for allocating buffers and supports custom allocators.
+ * If not set, it might not use get_buffer() at all or use operations that
+ * assume the buffer was allocated by avcodec_default_get_buffer.
+ */
+#define CODEC_CAP_DR1             0x0002
+#define CODEC_CAP_TRUNCATED       0x0008
+/* Codec can export data for HW decoding (XvMC). */
+#define CODEC_CAP_HWACCEL         0x0010
+/**
+ * Encoder or decoder requires flushing with NULL input at the end in order to
+ * give the complete and correct output.
+ *
+ * NOTE: If this flag is not set, the codec is guaranteed to never be fed with
+ *       with NULL data. The user can still send NULL data to the public encode
+ *       or decode function, but libavcodec will not pass it along to the codec
+ *       unless this flag is set.
+ *
+ * Decoders:
+ * The decoder has a non-zero delay and needs to be fed with avpkt->data=NULL,
+ * avpkt->size=0 at the end to get the delayed data until the decoder no longer
+ * returns frames.
+ *
+ * Encoders:
+ * The encoder needs to be fed with NULL data at the end of encoding until the
+ * encoder no longer returns data.
+ *
+ * NOTE: For encoders implementing the AVCodec.encode2() function, setting this
+ *       flag also means that the encoder must set the pts and duration for
+ *       each output packet. If this flag is not set, the pts and duration will
+ *       be determined by libavcodec from the input frame.
+ */
+#define CODEC_CAP_DELAY           0x0020
+/**
+ * Codec can be fed a final frame with a smaller size.
+ * This can be used to prevent truncation of the last audio samples.
+ */
+#define CODEC_CAP_SMALL_LAST_FRAME 0x0040
+#if FF_API_CAP_VDPAU
+/**
+ * Codec can export data for HW decoding (VDPAU).
+ */
+#define CODEC_CAP_HWACCEL_VDPAU    0x0080
+#endif
+/**
+ * Codec can output multiple frames per AVPacket
+ * Normally demuxers return one frame at a time, demuxers which do not do
+ * are connected to a parser to split what they return into proper frames.
+ * This flag is reserved to the very rare category of codecs which have a
+ * bitstream that cannot be split into frames without timeconsuming
+ * operations like full decoding. Demuxers carring such bitstreams thus
+ * may return multiple frames in a packet. This has many disadvantages like
+ * prohibiting stream copy in many cases thus it should only be considered
+ * as a last resort.
+ */
+#define CODEC_CAP_SUBFRAMES        0x0100
+/**
+ * Codec is experimental and is thus avoided in favor of non experimental
+ * encoders
+ */
+#define CODEC_CAP_EXPERIMENTAL     0x0200
+/**
+ * Codec should fill in channel configuration and samplerate instead of container
+ */
+#define CODEC_CAP_CHANNEL_CONF     0x0400
+
+/**
+ * Codec is able to deal with negative linesizes
+ */
+#define CODEC_CAP_NEG_LINESIZES    0x0800
+
+/**
+ * Codec supports frame-level multithreading.
+ */
+#define CODEC_CAP_FRAME_THREADS    0x1000
+/**
+ * Codec supports slice-based (or partition-based) multithreading.
+ */
+#define CODEC_CAP_SLICE_THREADS    0x2000
+/**
+ * Codec supports changed parameters at any point.
+ */
+#define CODEC_CAP_PARAM_CHANGE     0x4000
+/**
+ * Codec supports avctx->thread_count == 0 (auto).
+ */
+#define CODEC_CAP_AUTO_THREADS     0x8000
+/**
+ * Audio encoder supports receiving a different number of samples in each call.
+ */
+#define CODEC_CAP_VARIABLE_FRAME_SIZE 0x10000
+/**
+ * Codec is intra only.
+ */
+#define CODEC_CAP_INTRA_ONLY       0x40000000
+/**
+ * Codec is lossless.
+ */
+#define CODEC_CAP_LOSSLESS         0x80000000
+
+//The following defines may change, don't expect compatibility if you use them.
+#define MB_TYPE_INTRA4x4   0x0001
+#define MB_TYPE_INTRA16x16 0x0002 //FIXME H.264-specific
+#define MB_TYPE_INTRA_PCM  0x0004 //FIXME H.264-specific
+#define MB_TYPE_16x16      0x0008
+#define MB_TYPE_16x8       0x0010
+#define MB_TYPE_8x16       0x0020
+#define MB_TYPE_8x8        0x0040
+#define MB_TYPE_INTERLACED 0x0080
+#define MB_TYPE_DIRECT2    0x0100 //FIXME
+#define MB_TYPE_ACPRED     0x0200
+#define MB_TYPE_GMC        0x0400
+#define MB_TYPE_SKIP       0x0800
+#define MB_TYPE_P0L0       0x1000
+#define MB_TYPE_P1L0       0x2000
+#define MB_TYPE_P0L1       0x4000
+#define MB_TYPE_P1L1       0x8000
+#define MB_TYPE_L0         (MB_TYPE_P0L0 | MB_TYPE_P1L0)
+#define MB_TYPE_L1         (MB_TYPE_P0L1 | MB_TYPE_P1L1)
+#define MB_TYPE_L0L1       (MB_TYPE_L0   | MB_TYPE_L1)
+#define MB_TYPE_QUANT      0x00010000
+#define MB_TYPE_CBP        0x00020000
+//Note bits 24-31 are reserved for codec specific use (h264 ref0, mpeg1 0mv, ...)
+
+/**
+ * Pan Scan area.
+ * This specifies the area which should be displayed.
+ * Note there may be multiple such areas for one frame.
+ */
+typedef struct AVPanScan{
+    /**
+     * id
+     * - encoding: Set by user.
+     * - decoding: Set by libavcodec.
+     */
+    int id;
+
+    /**
+     * width and height in 1/16 pel
+     * - encoding: Set by user.
+     * - decoding: Set by libavcodec.
+     */
+    int width;
+    int height;
+
+    /**
+     * position of the top left corner in 1/16 pel for up to 3 fields/frames
+     * - encoding: Set by user.
+     * - decoding: Set by libavcodec.
+     */
+    int16_t position[3][2];
+}AVPanScan;
+
+#define FF_QSCALE_TYPE_MPEG1 0
+#define FF_QSCALE_TYPE_MPEG2 1
+#define FF_QSCALE_TYPE_H264  2
+#define FF_QSCALE_TYPE_VP56  3
+
+#if FF_API_GET_BUFFER
+#define FF_BUFFER_TYPE_INTERNAL 1
+#define FF_BUFFER_TYPE_USER     2 ///< direct rendering buffers (image is (de)allocated by user)
+#define FF_BUFFER_TYPE_SHARED   4 ///< Buffer from somewhere else; don't deallocate image (data/base), all other tables are not shared.
+#define FF_BUFFER_TYPE_COPY     8 ///< Just a (modified) copy of some other buffer, don't deallocate anything.
+
+#define FF_BUFFER_HINTS_VALID    0x01 // Buffer hints value is meaningful (if 0 ignore).
+#define FF_BUFFER_HINTS_READABLE 0x02 // Codec will read from buffer.
+#define FF_BUFFER_HINTS_PRESERVE 0x04 // User must not alter buffer content.
+#define FF_BUFFER_HINTS_REUSABLE 0x08 // Codec will reuse the buffer (update).
+#endif
+
+/**
+ * The decoder will keep a reference to the frame and may reuse it later.
+ */
+#define AV_GET_BUFFER_FLAG_REF (1 << 0)
+
+/**
+ * @defgroup lavc_packet AVPacket
+ *
+ * Types and functions for working with AVPacket.
+ * @{
+ */
+enum AVPacketSideDataType {
+    AV_PKT_DATA_PALETTE,
+    AV_PKT_DATA_NEW_EXTRADATA,
+
+    /**
+     * An AV_PKT_DATA_PARAM_CHANGE side data packet is laid out as follows:
+     * @code
+     * u32le param_flags
+     * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT)
+     *     s32le channel_count
+     * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT)
+     *     u64le channel_layout
+     * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE)
+     *     s32le sample_rate
+     * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS)
+     *     s32le width
+     *     s32le height
+     * @endcode
+     */
+    AV_PKT_DATA_PARAM_CHANGE,
+
+    /**
+     * An AV_PKT_DATA_H263_MB_INFO side data packet contains a number of
+     * structures with info about macroblocks relevant to splitting the
+     * packet into smaller packets on macroblock edges (e.g. as for RFC 2190).
+     * That is, it does not necessarily contain info about all macroblocks,
+     * as long as the distance between macroblocks in the info is smaller
+     * than the target payload size.
+     * Each MB info structure is 12 bytes, and is laid out as follows:
+     * @code
+     * u32le bit offset from the start of the packet
+     * u8    current quantizer at the start of the macroblock
+     * u8    GOB number
+     * u16le macroblock address within the GOB
+     * u8    horizontal MV predictor
+     * u8    vertical MV predictor
+     * u8    horizontal MV predictor for block number 3
+     * u8    vertical MV predictor for block number 3
+     * @endcode
+     */
+    AV_PKT_DATA_H263_MB_INFO,
+
+    /**
+     * Recommmends skipping the specified number of samples
+     * @code
+     * u32le number of samples to skip from start of this packet
+     * u32le number of samples to skip from end of this packet
+     * u8    reason for start skip
+     * u8    reason for end   skip (0=padding silence, 1=convergence)
+     * @endcode
+     */
+    AV_PKT_DATA_SKIP_SAMPLES=70,
+
+    /**
+     * An AV_PKT_DATA_JP_DUALMONO side data packet indicates that
+     * the packet may contain "dual mono" audio specific to Japanese DTV
+     * and if it is true, recommends only the selected channel to be used.
+     * @code
+     * u8    selected channels (0=mail/left, 1=sub/right, 2=both)
+     * @endcode
+     */
+    AV_PKT_DATA_JP_DUALMONO,
+
+    /**
+     * A list of zero terminated key/value strings. There is no end marker for
+     * the list, so it is required to rely on the side data size to stop.
+     */
+    AV_PKT_DATA_STRINGS_METADATA,
+
+    /**
+     * Subtitle event position
+     * @code
+     * u32le x1
+     * u32le y1
+     * u32le x2
+     * u32le y2
+     * @endcode
+     */
+    AV_PKT_DATA_SUBTITLE_POSITION,
+
+    /**
+     * Data found in BlockAdditional element of matroska container. There is
+     * no end marker for the data, so it is required to rely on the side data
+     * size to recognize the end. 8 byte id (as found in BlockAddId) followed
+     * by data.
+     */
+    AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL,
+
+    /**
+     * The optional first identifier line of a WebVTT cue.
+     */
+    AV_PKT_DATA_WEBVTT_IDENTIFIER,
+
+    /**
+     * The optional settings (rendering instructions) that immediately
+     * follow the timestamp specifier of a WebVTT cue.
+     */
+    AV_PKT_DATA_WEBVTT_SETTINGS,
+};
+
+/**
+ * This structure stores compressed data. It is typically exported by demuxers
+ * and then passed as input to decoders, or received as output from encoders and
+ * then passed to muxers.
+ *
+ * For video, it should typically contain one compressed frame. For audio it may
+ * contain several compressed frames.
+ *
+ * AVPacket is one of the few structs in FFmpeg, whose size is a part of public
+ * ABI. Thus it may be allocated on stack and no new fields can be added to it
+ * without libavcodec and libavformat major bump.
+ *
+ * The semantics of data ownership depends on the buf or destruct (deprecated)
+ * fields. If either is set, the packet data is dynamically allocated and is
+ * valid indefinitely until av_free_packet() is called (which in turn calls
+ * av_buffer_unref()/the destruct callback to free the data). If neither is set,
+ * the packet data is typically backed by some static buffer somewhere and is
+ * only valid for a limited time (e.g. until the next read call when demuxing).
+ *
+ * The side data is always allocated with av_malloc() and is freed in
+ * av_free_packet().
+ */
+typedef struct AVPacket {
+    /**
+     * A reference to the reference-counted buffer where the packet data is
+     * stored.
+     * May be NULL, then the packet data is not reference-counted.
+     */
+    AVBufferRef *buf;
+    /**
+     * Presentation timestamp in AVStream->time_base units; the time at which
+     * the decompressed packet will be presented to the user.
+     * Can be AV_NOPTS_VALUE if it is not stored in the file.
+     * pts MUST be larger or equal to dts as presentation cannot happen before
+     * decompression, unless one wants to view hex dumps. Some formats misuse
+     * the terms dts and pts/cts to mean something different. Such timestamps
+     * must be converted to true pts/dts before they are stored in AVPacket.
+     */
+    int64_t pts;
+    /**
+     * Decompression timestamp in AVStream->time_base units; the time at which
+     * the packet is decompressed.
+     * Can be AV_NOPTS_VALUE if it is not stored in the file.
+     */
+    int64_t dts;
+    uint8_t *data;
+    int   size;
+    int   stream_index;
+    /**
+     * A combination of AV_PKT_FLAG values
+     */
+    int   flags;
+    /**
+     * Additional packet data that can be provided by the container.
+     * Packet can contain several types of side information.
+     */
+    struct {
+        uint8_t *data;
+        int      size;
+        enum AVPacketSideDataType type;
+    } *side_data;
+    int side_data_elems;
+
+    /**
+     * Duration of this packet in AVStream->time_base units, 0 if unknown.
+     * Equals next_pts - this_pts in presentation order.
+     */
+    int   duration;
+#if FF_API_DESTRUCT_PACKET
+    attribute_deprecated
+    void  (*destruct)(struct AVPacket *);
+    attribute_deprecated
+    void  *priv;
+#endif
+    int64_t pos;                            ///< byte position in stream, -1 if unknown
+
+    /**
+     * Time difference in AVStream->time_base units from the pts of this
+     * packet to the point at which the output from the decoder has converged
+     * independent from the availability of previous frames. That is, the
+     * frames are virtually identical no matter if decoding started from
+     * the very first frame or from this keyframe.
+     * Is AV_NOPTS_VALUE if unknown.
+     * This field is not the display duration of the current packet.
+     * This field has no meaning if the packet does not have AV_PKT_FLAG_KEY
+     * set.
+     *
+     * The purpose of this field is to allow seeking in streams that have no
+     * keyframes in the conventional sense. It corresponds to the
+     * recovery point SEI in H.264 and match_time_delta in NUT. It is also
+     * essential for some types of subtitle streams to ensure that all
+     * subtitles are correctly displayed after seeking.
+     */
+    int64_t convergence_duration;
+} AVPacket;
+#define AV_PKT_FLAG_KEY     0x0001 ///< The packet contains a keyframe
+#define AV_PKT_FLAG_CORRUPT 0x0002 ///< The packet content is corrupted
+
+enum AVSideDataParamChangeFlags {
+    AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT  = 0x0001,
+    AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT = 0x0002,
+    AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE    = 0x0004,
+    AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS     = 0x0008,
+};
+/**
+ * @}
+ */
+
+struct AVCodecInternal;
+
+enum AVFieldOrder {
+    AV_FIELD_UNKNOWN,
+    AV_FIELD_PROGRESSIVE,
+    AV_FIELD_TT,          //< Top coded_first, top displayed first
+    AV_FIELD_BB,          //< Bottom coded first, bottom displayed first
+    AV_FIELD_TB,          //< Top coded first, bottom displayed first
+    AV_FIELD_BT,          //< Bottom coded first, top displayed first
+};
+
+/**
+ * main external API structure.
+ * New fields can be added to the end with minor version bumps.
+ * Removal, reordering and changes to existing fields require a major
+ * version bump.
+ * Please use AVOptions (av_opt* / av_set/get*()) to access these fields from user
+ * applications.
+ * sizeof(AVCodecContext) must not be used outside libav*.
+ */
+typedef struct AVCodecContext {
+    /**
+     * information on struct for av_log
+     * - set by avcodec_alloc_context3
+     */
+    const AVClass *av_class;
+    int log_level_offset;
+
+    enum AVMediaType codec_type; /* see AVMEDIA_TYPE_xxx */
+    const struct AVCodec  *codec;
+    char             codec_name[32];
+    enum AVCodecID     codec_id; /* see AV_CODEC_ID_xxx */
+
+    /**
+     * fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
+     * This is used to work around some encoder bugs.
+     * A demuxer should set this to what is stored in the field used to identify the codec.
+     * If there are multiple such fields in a container then the demuxer should choose the one
+     * which maximizes the information about the used codec.
+     * If the codec tag field in a container is larger than 32 bits then the demuxer should
+     * remap the longer ID to 32 bits with a table or other structure. Alternatively a new
+     * extra_codec_tag + size could be added but for this a clear advantage must be demonstrated
+     * first.
+     * - encoding: Set by user, if not then the default based on codec_id will be used.
+     * - decoding: Set by user, will be converted to uppercase by libavcodec during init.
+     */
+    unsigned int codec_tag;
+
+    /**
+     * fourcc from the AVI stream header (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
+     * This is used to work around some encoder bugs.
+     * - encoding: unused
+     * - decoding: Set by user, will be converted to uppercase by libavcodec during init.
+     */
+    unsigned int stream_codec_tag;
+
+    void *priv_data;
+
+    /**
+     * Private context used for internal data.
+     *
+     * Unlike priv_data, this is not codec-specific. It is used in general
+     * libavcodec functions.
+     */
+    struct AVCodecInternal *internal;
+
+    /**
+     * Private data of the user, can be used to carry app specific stuff.
+     * - encoding: Set by user.
+     * - decoding: Set by user.
+     */
+    void *opaque;
+
+    /**
+     * the average bitrate
+     * - encoding: Set by user; unused for constant quantizer encoding.
+     * - decoding: Set by libavcodec. 0 or some bitrate if this info is available in the stream.
+     */
+    int bit_rate;
+
+    /**
+     * number of bits the bitstream is allowed to diverge from the reference.
+     *           the reference can be CBR (for CBR pass1) or VBR (for pass2)
+     * - encoding: Set by user; unused for constant quantizer encoding.
+     * - decoding: unused
+     */
+    int bit_rate_tolerance;
+
+    /**
+     * Global quality for codecs which cannot change it per frame.
+     * This should be proportional to MPEG-1/2/4 qscale.
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int global_quality;
+
+    /**
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int compression_level;
+#define FF_COMPRESSION_DEFAULT -1
+
+    /**
+     * CODEC_FLAG_*.
+     * - encoding: Set by user.
+     * - decoding: Set by user.
+     */
+    int flags;
+
+    /**
+     * CODEC_FLAG2_*
+     * - encoding: Set by user.
+     * - decoding: Set by user.
+     */
+    int flags2;
+
+    /**
+     * some codecs need / can use extradata like Huffman tables.
+     * mjpeg: Huffman tables
+     * rv10: additional flags
+     * mpeg4: global headers (they can be in the bitstream or here)
+     * The allocated memory should be FF_INPUT_BUFFER_PADDING_SIZE bytes larger
+     * than extradata_size to avoid problems if it is read with the bitstream reader.
+     * The bytewise contents of extradata must not depend on the architecture or CPU endianness.
+     * - encoding: Set/allocated/freed by libavcodec.
+     * - decoding: Set/allocated/freed by user.
+     */
+    uint8_t *extradata;
+    int extradata_size;
+
+    /**
+     * This is the fundamental unit of time (in seconds) in terms
+     * of which frame timestamps are represented. For fixed-fps content,
+     * timebase should be 1/framerate and timestamp increments should be
+     * identically 1.
+     * - encoding: MUST be set by user.
+     * - decoding: Set by libavcodec.
+     */
+    AVRational time_base;
+
+    /**
+     * For some codecs, the time base is closer to the field rate than the frame rate.
+     * Most notably, H.264 and MPEG-2 specify time_base as half of frame duration
+     * if no telecine is used ...
+     *
+     * Set to time_base ticks per frame. Default 1, e.g., H.264/MPEG-2 set it to 2.
+     */
+    int ticks_per_frame;
+
+    /**
+     * Codec delay.
+     *
+     * Encoding: Number of frames delay there will be from the encoder input to
+     *           the decoder output. (we assume the decoder matches the spec)
+     * Decoding: Number of frames delay in addition to what a standard decoder
+     *           as specified in the spec would produce.
+     *
+     * Video:
+     *   Number of frames the decoded output will be delayed relative to the
+     *   encoded input.
+     *
+     * Audio:
+     *   For encoding, this is the number of "priming" samples added to the
+     *   beginning of the stream. The decoded output will be delayed by this
+     *   many samples relative to the input to the encoder. Note that this
+     *   field is purely informational and does not directly affect the pts
+     *   output by the encoder, which should always be based on the actual
+     *   presentation time, including any delay.
+     *   For decoding, this is the number of samples the decoder needs to
+     *   output before the decoder's output is valid. When seeking, you should
+     *   start decoding this many samples prior to your desired seek point.
+     *
+     * - encoding: Set by libavcodec.
+     * - decoding: Set by libavcodec.
+     */
+    int delay;
+
+
+    /* video only */
+    /**
+     * picture width / height.
+     * - encoding: MUST be set by user.
+     * - decoding: May be set by the user before opening the decoder if known e.g.
+     *             from the container. Some decoders will require the dimensions
+     *             to be set by the caller. During decoding, the decoder may
+     *             overwrite those values as required.
+     */
+    int width, height;
+
+    /**
+     * Bitstream width / height, may be different from width/height e.g. when
+     * the decoded frame is cropped before being output or lowres is enabled.
+     * - encoding: unused
+     * - decoding: May be set by the user before opening the decoder if known
+     *             e.g. from the container. During decoding, the decoder may
+     *             overwrite those values as required.
+     */
+    int coded_width, coded_height;
+
+#define FF_ASPECT_EXTENDED 15
+
+    /**
+     * the number of pictures in a group of pictures, or 0 for intra_only
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int gop_size;
+
+    /**
+     * Pixel format, see AV_PIX_FMT_xxx.
+     * May be set by the demuxer if known from headers.
+     * May be overridden by the decoder if it knows better.
+     * - encoding: Set by user.
+     * - decoding: Set by user if known, overridden by libavcodec if known
+     */
+    enum AVPixelFormat pix_fmt;
+
+    /**
+     * Motion estimation algorithm used for video coding.
+     * 1 (zero), 2 (full), 3 (log), 4 (phods), 5 (epzs), 6 (x1), 7 (hex),
+     * 8 (umh), 9 (iter), 10 (tesa) [7, 8, 10 are x264 specific, 9 is snow specific]
+     * - encoding: MUST be set by user.
+     * - decoding: unused
+     */
+    int me_method;
+
+    /**
+     * If non NULL, 'draw_horiz_band' is called by the libavcodec
+     * decoder to draw a horizontal band. It improves cache usage. Not
+     * all codecs can do that. You must check the codec capabilities
+     * beforehand.
+     * When multithreading is used, it may be called from multiple threads
+     * at the same time; threads might draw different parts of the same AVFrame,
+     * or multiple AVFrames, and there is no guarantee that slices will be drawn
+     * in order.
+     * The function is also used by hardware acceleration APIs.
+     * It is called at least once during frame decoding to pass
+     * the data needed for hardware render.
+     * In that mode instead of pixel data, AVFrame points to
+     * a structure specific to the acceleration API. The application
+     * reads the structure and can change some fields to indicate progress
+     * or mark state.
+     * - encoding: unused
+     * - decoding: Set by user.
+     * @param height the height of the slice
+     * @param y the y position of the slice
+     * @param type 1->top field, 2->bottom field, 3->frame
+     * @param offset offset into the AVFrame.data from which the slice should be read
+     */
+    void (*draw_horiz_band)(struct AVCodecContext *s,
+                            const AVFrame *src, int offset[AV_NUM_DATA_POINTERS],
+                            int y, int type, int height);
+
+    /**
+     * callback to negotiate the pixelFormat
+     * @param fmt is the list of formats which are supported by the codec,
+     * it is terminated by -1 as 0 is a valid format, the formats are ordered by quality.
+     * The first is always the native one.
+     * @return the chosen format
+     * - encoding: unused
+     * - decoding: Set by user, if not set the native format will be chosen.
+     */
+    enum AVPixelFormat (*get_format)(struct AVCodecContext *s, const enum AVPixelFormat * fmt);
+
+    /**
+     * maximum number of B-frames between non-B-frames
+     * Note: The output will be delayed by max_b_frames+1 relative to the input.
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int max_b_frames;
+
+    /**
+     * qscale factor between IP and B-frames
+     * If > 0 then the last P-frame quantizer will be used (q= lastp_q*factor+offset).
+     * If < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset).
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    float b_quant_factor;
+
+    /** obsolete FIXME remove */
+    int rc_strategy;
+#define FF_RC_STRATEGY_XVID 1
+
+    int b_frame_strategy;
+
+    /**
+     * qscale offset between IP and B-frames
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    float b_quant_offset;
+
+    /**
+     * Size of the frame reordering buffer in the decoder.
+     * For MPEG-2 it is 1 IPB or 0 low delay IP.
+     * - encoding: Set by libavcodec.
+     * - decoding: Set by libavcodec.
+     */
+    int has_b_frames;
+
+    /**
+     * 0-> h263 quant 1-> mpeg quant
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int mpeg_quant;
+
+    /**
+     * qscale factor between P and I-frames
+     * If > 0 then the last p frame quantizer will be used (q= lastp_q*factor+offset).
+     * If < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset).
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    float i_quant_factor;
+
+    /**
+     * qscale offset between P and I-frames
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    float i_quant_offset;
+
+    /**
+     * luminance masking (0-> disabled)
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    float lumi_masking;
+
+    /**
+     * temporary complexity masking (0-> disabled)
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    float temporal_cplx_masking;
+
+    /**
+     * spatial complexity masking (0-> disabled)
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    float spatial_cplx_masking;
+
+    /**
+     * p block masking (0-> disabled)
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    float p_masking;
+
+    /**
+     * darkness masking (0-> disabled)
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    float dark_masking;
+
+    /**
+     * slice count
+     * - encoding: Set by libavcodec.
+     * - decoding: Set by user (or 0).
+     */
+    int slice_count;
+    /**
+     * prediction method (needed for huffyuv)
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+     int prediction_method;
+#define FF_PRED_LEFT   0
+#define FF_PRED_PLANE  1
+#define FF_PRED_MEDIAN 2
+
+    /**
+     * slice offsets in the frame in bytes
+     * - encoding: Set/allocated by libavcodec.
+     * - decoding: Set/allocated by user (or NULL).
+     */
+    int *slice_offset;
+
+    /**
+     * sample aspect ratio (0 if unknown)
+     * That is the width of a pixel divided by the height of the pixel.
+     * Numerator and denominator must be relatively prime and smaller than 256 for some video standards.
+     * - encoding: Set by user.
+     * - decoding: Set by libavcodec.
+     */
+    AVRational sample_aspect_ratio;
+
+    /**
+     * motion estimation comparison function
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int me_cmp;
+    /**
+     * subpixel motion estimation comparison function
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int me_sub_cmp;
+    /**
+     * macroblock comparison function (not supported yet)
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int mb_cmp;
+    /**
+     * interlaced DCT comparison function
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int ildct_cmp;
+#define FF_CMP_SAD    0
+#define FF_CMP_SSE    1
+#define FF_CMP_SATD   2
+#define FF_CMP_DCT    3
+#define FF_CMP_PSNR   4
+#define FF_CMP_BIT    5
+#define FF_CMP_RD     6
+#define FF_CMP_ZERO   7
+#define FF_CMP_VSAD   8
+#define FF_CMP_VSSE   9
+#define FF_CMP_NSSE   10
+#define FF_CMP_W53    11
+#define FF_CMP_W97    12
+#define FF_CMP_DCTMAX 13
+#define FF_CMP_DCT264 14
+#define FF_CMP_CHROMA 256
+
+    /**
+     * ME diamond size & shape
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int dia_size;
+
+    /**
+     * amount of previous MV predictors (2a+1 x 2a+1 square)
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int last_predictor_count;
+
+    /**
+     * prepass for motion estimation
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int pre_me;
+
+    /**
+     * motion estimation prepass comparison function
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int me_pre_cmp;
+
+    /**
+     * ME prepass diamond size & shape
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int pre_dia_size;
+
+    /**
+     * subpel ME quality
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int me_subpel_quality;
+
+    /**
+     * DTG active format information (additional aspect ratio
+     * information only used in DVB MPEG-2 transport streams)
+     * 0 if not set.
+     *
+     * - encoding: unused
+     * - decoding: Set by decoder.
+     */
+    int dtg_active_format;
+#define FF_DTG_AFD_SAME         8
+#define FF_DTG_AFD_4_3          9
+#define FF_DTG_AFD_16_9         10
+#define FF_DTG_AFD_14_9         11
+#define FF_DTG_AFD_4_3_SP_14_9  13
+#define FF_DTG_AFD_16_9_SP_14_9 14
+#define FF_DTG_AFD_SP_4_3       15
+
+    /**
+     * maximum motion estimation search range in subpel units
+     * If 0 then no limit.
+     *
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int me_range;
+
+    /**
+     * intra quantizer bias
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int intra_quant_bias;
+#define FF_DEFAULT_QUANT_BIAS 999999
+
+    /**
+     * inter quantizer bias
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int inter_quant_bias;
+
+    /**
+     * slice flags
+     * - encoding: unused
+     * - decoding: Set by user.
+     */
+    int slice_flags;
+#define SLICE_FLAG_CODED_ORDER    0x0001 ///< draw_horiz_band() is called in coded order instead of display
+#define SLICE_FLAG_ALLOW_FIELD    0x0002 ///< allow draw_horiz_band() with field slices (MPEG2 field pics)
+#define SLICE_FLAG_ALLOW_PLANE    0x0004 ///< allow draw_horiz_band() with 1 component at a time (SVQ1)
+
+    /**
+     * XVideo Motion Acceleration
+     * - encoding: forbidden
+     * - decoding: set by decoder
+     */
+    int xvmc_acceleration;
+
+    /**
+     * macroblock decision mode
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int mb_decision;
+#define FF_MB_DECISION_SIMPLE 0        ///< uses mb_cmp
+#define FF_MB_DECISION_BITS   1        ///< chooses the one which needs the fewest bits
+#define FF_MB_DECISION_RD     2        ///< rate distortion
+
+    /**
+     * custom intra quantization matrix
+     * - encoding: Set by user, can be NULL.
+     * - decoding: Set by libavcodec.
+     */
+    uint16_t *intra_matrix;
+
+    /**
+     * custom inter quantization matrix
+     * - encoding: Set by user, can be NULL.
+     * - decoding: Set by libavcodec.
+     */
+    uint16_t *inter_matrix;
+
+    /**
+     * scene change detection threshold
+     * 0 is default, larger means fewer detected scene changes.
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int scenechange_threshold;
+
+    /**
+     * noise reduction strength
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int noise_reduction;
+
+    /**
+     * Motion estimation threshold below which no motion estimation is
+     * performed, but instead the user specified motion vectors are used.
+     *
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int me_threshold;
+
+    /**
+     * Macroblock threshold below which the user specified macroblock types will be used.
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int mb_threshold;
+
+    /**
+     * precision of the intra DC coefficient - 8
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int intra_dc_precision;
+
+    /**
+     * Number of macroblock rows at the top which are skipped.
+     * - encoding: unused
+     * - decoding: Set by user.
+     */
+    int skip_top;
+
+    /**
+     * Number of macroblock rows at the bottom which are skipped.
+     * - encoding: unused
+     * - decoding: Set by user.
+     */
+    int skip_bottom;
+
+    /**
+     * Border processing masking, raises the quantizer for mbs on the borders
+     * of the picture.
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    float border_masking;
+
+    /**
+     * minimum MB lagrange multipler
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int mb_lmin;
+
+    /**
+     * maximum MB lagrange multipler
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int mb_lmax;
+
+    /**
+     *
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int me_penalty_compensation;
+
+    /**
+     *
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int bidir_refine;
+
+    /**
+     *
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int brd_scale;
+
+    /**
+     * minimum GOP size
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int keyint_min;
+
+    /**
+     * number of reference frames
+     * - encoding: Set by user.
+     * - decoding: Set by lavc.
+     */
+    int refs;
+
+    /**
+     * chroma qp offset from luma
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int chromaoffset;
+
+    /**
+     * Multiplied by qscale for each frame and added to scene_change_score.
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int scenechange_factor;
+
+    /**
+     *
+     * Note: Value depends upon the compare function used for fullpel ME.
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int mv0_threshold;
+
+    /**
+     * Adjust sensitivity of b_frame_strategy 1.
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int b_sensitivity;
+
+    /**
+     * Chromaticity coordinates of the source primaries.
+     * - encoding: Set by user
+     * - decoding: Set by libavcodec
+     */
+    enum AVColorPrimaries color_primaries;
+
+    /**
+     * Color Transfer Characteristic.
+     * - encoding: Set by user
+     * - decoding: Set by libavcodec
+     */
+    enum AVColorTransferCharacteristic color_trc;
+
+    /**
+     * YUV colorspace type.
+     * - encoding: Set by user
+     * - decoding: Set by libavcodec
+     */
+    enum AVColorSpace colorspace;
+
+    /**
+     * MPEG vs JPEG YUV range.
+     * - encoding: Set by user
+     * - decoding: Set by libavcodec
+     */
+    enum AVColorRange color_range;
+
+    /**
+     * This defines the location of chroma samples.
+     * - encoding: Set by user
+     * - decoding: Set by libavcodec
+     */
+    enum AVChromaLocation chroma_sample_location;
+
+    /**
+     * Number of slices.
+     * Indicates number of picture subdivisions. Used for parallelized
+     * decoding.
+     * - encoding: Set by user
+     * - decoding: unused
+     */
+    int slices;
+
+    /** Field order
+     * - encoding: set by libavcodec
+     * - decoding: Set by user.
+     */
+    enum AVFieldOrder field_order;
+
+    /* audio only */
+    int sample_rate; ///< samples per second
+    int channels;    ///< number of audio channels
+
+    /**
+     * audio sample format
+     * - encoding: Set by user.
+     * - decoding: Set by libavcodec.
+     */
+    enum AVSampleFormat sample_fmt;  ///< sample format
+
+    /* The following data should not be initialized. */
+    /**
+     * Number of samples per channel in an audio frame.
+     *
+     * - encoding: set by libavcodec in avcodec_open2(). Each submitted frame
+     *   except the last must contain exactly frame_size samples per channel.
+     *   May be 0 when the codec has CODEC_CAP_VARIABLE_FRAME_SIZE set, then the
+     *   frame size is not restricted.
+     * - decoding: may be set by some decoders to indicate constant frame size
+     */
+    int frame_size;
+
+    /**
+     * Frame counter, set by libavcodec.
+     *
+     * - decoding: total number of frames returned from the decoder so far.
+     * - encoding: total number of frames passed to the encoder so far.
+     *
+     *   @note the counter is not incremented if encoding/decoding resulted in
+     *   an error.
+     */
+    int frame_number;
+
+    /**
+     * number of bytes per packet if constant and known or 0
+     * Used by some WAV based audio codecs.
+     */
+    int block_align;
+
+    /**
+     * Audio cutoff bandwidth (0 means "automatic")
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int cutoff;
+
+#if FF_API_REQUEST_CHANNELS
+    /**
+     * Decoder should decode to this many channels if it can (0 for default)
+     * - encoding: unused
+     * - decoding: Set by user.
+     * @deprecated Deprecated in favor of request_channel_layout.
+     */
+    attribute_deprecated int request_channels;
+#endif
+
+    /**
+     * Audio channel layout.
+     * - encoding: set by user.
+     * - decoding: set by user, may be overwritten by libavcodec.
+     */
+    uint64_t channel_layout;
+
+    /**
+     * Request decoder to use this channel layout if it can (0 for default)
+     * - encoding: unused
+     * - decoding: Set by user.
+     */
+    uint64_t request_channel_layout;
+
+    /**
+     * Type of service that the audio stream conveys.
+     * - encoding: Set by user.
+     * - decoding: Set by libavcodec.
+     */
+    enum AVAudioServiceType audio_service_type;
+
+    /**
+     * desired sample format
+     * - encoding: Not used.
+     * - decoding: Set by user.
+     * Decoder will decode to this format if it can.
+     */
+    enum AVSampleFormat request_sample_fmt;
+
+#if FF_API_GET_BUFFER
+    /**
+     * Called at the beginning of each frame to get a buffer for it.
+     *
+     * The function will set AVFrame.data[], AVFrame.linesize[].
+     * AVFrame.extended_data[] must also be set, but it should be the same as
+     * AVFrame.data[] except for planar audio with more channels than can fit
+     * in AVFrame.data[]. In that case, AVFrame.data[] shall still contain as
+     * many data pointers as it can hold.
+     *
+     * if CODEC_CAP_DR1 is not set then get_buffer() must call
+     * avcodec_default_get_buffer() instead of providing buffers allocated by
+     * some other means.
+     *
+     * AVFrame.data[] should be 32- or 16-byte-aligned unless the CPU doesn't
+     * need it. avcodec_default_get_buffer() aligns the output buffer properly,
+     * but if get_buffer() is overridden then alignment considerations should
+     * be taken into account.
+     *
+     * @see avcodec_default_get_buffer()
+     *
+     * Video:
+     *
+     * If pic.reference is set then the frame will be read later by libavcodec.
+     * avcodec_align_dimensions2() should be used to find the required width and
+     * height, as they normally need to be rounded up to the next multiple of 16.
+     *
+     * If frame multithreading is used and thread_safe_callbacks is set,
+     * it may be called from a different thread, but not from more than one at
+     * once. Does not need to be reentrant.
+     *
+     * @see release_buffer(), reget_buffer()
+     * @see avcodec_align_dimensions2()
+     *
+     * Audio:
+     *
+     * Decoders request a buffer of a particular size by setting
+     * AVFrame.nb_samples prior to calling get_buffer(). The decoder may,
+     * however, utilize only part of the buffer by setting AVFrame.nb_samples
+     * to a smaller value in the output frame.
+     *
+     * Decoders cannot use the buffer after returning from
+     * avcodec_decode_audio4(), so they will not call release_buffer(), as it
+     * is assumed to be released immediately upon return. In some rare cases,
+     * a decoder may need to call get_buffer() more than once in a single
+     * call to avcodec_decode_audio4(). In that case, when get_buffer() is
+     * called again after it has already been called once, the previously
+     * acquired buffer is assumed to be released at that time and may not be
+     * reused by the decoder.
+     *
+     * As a convenience, av_samples_get_buffer_size() and
+     * av_samples_fill_arrays() in libavutil may be used by custom get_buffer()
+     * functions to find the required data size and to fill data pointers and
+     * linesize. In AVFrame.linesize, only linesize[0] may be set for audio
+     * since all planes must be the same size.
+     *
+     * @see av_samples_get_buffer_size(), av_samples_fill_arrays()
+     *
+     * - encoding: unused
+     * - decoding: Set by libavcodec, user can override.
+     *
+     * @deprecated use get_buffer2()
+     */
+    attribute_deprecated
+    int (*get_buffer)(struct AVCodecContext *c, AVFrame *pic);
+
+    /**
+     * Called to release buffers which were allocated with get_buffer.
+     * A released buffer can be reused in get_buffer().
+     * pic.data[*] must be set to NULL.
+     * May be called from a different thread if frame multithreading is used,
+     * but not by more than one thread at once, so does not need to be reentrant.
+     * - encoding: unused
+     * - decoding: Set by libavcodec, user can override.
+     *
+     * @deprecated custom freeing callbacks should be set from get_buffer2()
+     */
+    attribute_deprecated
+    void (*release_buffer)(struct AVCodecContext *c, AVFrame *pic);
+
+    /**
+     * Called at the beginning of a frame to get cr buffer for it.
+     * Buffer type (size, hints) must be the same. libavcodec won't check it.
+     * libavcodec will pass previous buffer in pic, function should return
+     * same buffer or new buffer with old frame "painted" into it.
+     * If pic.data[0] == NULL must behave like get_buffer().
+     * if CODEC_CAP_DR1 is not set then reget_buffer() must call
+     * avcodec_default_reget_buffer() instead of providing buffers allocated by
+     * some other means.
+     * - encoding: unused
+     * - decoding: Set by libavcodec, user can override.
+     */
+    attribute_deprecated
+    int (*reget_buffer)(struct AVCodecContext *c, AVFrame *pic);
+#endif
+
+    /**
+     * This callback is called at the beginning of each frame to get data
+     * buffer(s) for it. There may be one contiguous buffer for all the data or
+     * there may be a buffer per each data plane or anything in between. What
+     * this means is, you may set however many entries in buf[] you feel necessary.
+     * Each buffer must be reference-counted using the AVBuffer API (see description
+     * of buf[] below).
+     *
+     * The following fields will be set in the frame before this callback is
+     * called:
+     * - format
+     * - width, height (video only)
+     * - sample_rate, channel_layout, nb_samples (audio only)
+     * Their values may differ from the corresponding values in
+     * AVCodecContext. This callback must use the frame values, not the codec
+     * context values, to calculate the required buffer size.
+     *
+     * This callback must fill the following fields in the frame:
+     * - data[]
+     * - linesize[]
+     * - extended_data:
+     *   * if the data is planar audio with more than 8 channels, then this
+     *     callback must allocate and fill extended_data to contain all pointers
+     *     to all data planes. data[] must hold as many pointers as it can.
+     *     extended_data must be allocated with av_malloc() and will be freed in
+     *     av_frame_unref().
+     *   * otherwise exended_data must point to data
+     * - buf[] must contain one or more pointers to AVBufferRef structures. Each of
+     *   the frame's data and extended_data pointers must be contained in these. That
+     *   is, one AVBufferRef for each allocated chunk of memory, not necessarily one
+     *   AVBufferRef per data[] entry. See: av_buffer_create(), av_buffer_alloc(),
+     *   and av_buffer_ref().
+     * - extended_buf and nb_extended_buf must be allocated with av_malloc() by
+     *   this callback and filled with the extra buffers if there are more
+     *   buffers than buf[] can hold. extended_buf will be freed in
+     *   av_frame_unref().
+     *
+     * If CODEC_CAP_DR1 is not set then get_buffer2() must call
+     * avcodec_default_get_buffer2() instead of providing buffers allocated by
+     * some other means.
+     *
+     * Each data plane must be aligned to the maximum required by the target
+     * CPU.
+     *
+     * @see avcodec_default_get_buffer2()
+     *
+     * Video:
+     *
+     * If AV_GET_BUFFER_FLAG_REF is set in flags then the frame may be reused
+     * (read and/or written to if it is writable) later by libavcodec.
+     *
+     * If CODEC_FLAG_EMU_EDGE is not set in s->flags, the buffer must contain an
+     * edge of the size returned by avcodec_get_edge_width() on all sides.
+     *
+     * avcodec_align_dimensions2() should be used to find the required width and
+     * height, as they normally need to be rounded up to the next multiple of 16.
+     *
+     * If frame multithreading is used and thread_safe_callbacks is set,
+     * this callback may be called from a different thread, but not from more
+     * than one at once. Does not need to be reentrant.
+     *
+     * @see avcodec_align_dimensions2()
+     *
+     * Audio:
+     *
+     * Decoders request a buffer of a particular size by setting
+     * AVFrame.nb_samples prior to calling get_buffer2(). The decoder may,
+     * however, utilize only part of the buffer by setting AVFrame.nb_samples
+     * to a smaller value in the output frame.
+     *
+     * As a convenience, av_samples_get_buffer_size() and
+     * av_samples_fill_arrays() in libavutil may be used by custom get_buffer2()
+     * functions to find the required data size and to fill data pointers and
+     * linesize. In AVFrame.linesize, only linesize[0] may be set for audio
+     * since all planes must be the same size.
+     *
+     * @see av_samples_get_buffer_size(), av_samples_fill_arrays()
+     *
+     * - encoding: unused
+     * - decoding: Set by libavcodec, user can override.
+     */
+    int (*get_buffer2)(struct AVCodecContext *s, AVFrame *frame, int flags);
+
+    /**
+     * If non-zero, the decoded audio and video frames returned from
+     * avcodec_decode_video2() and avcodec_decode_audio4() are reference-counted
+     * and are valid indefinitely. The caller must free them with
+     * av_frame_unref() when they are not needed anymore.
+     * Otherwise, the decoded frames must not be freed by the caller and are
+     * only valid until the next decode call.
+     *
+     * - encoding: unused
+     * - decoding: set by the caller before avcodec_open2().
+     */
+    int refcounted_frames;
+
+    /* - encoding parameters */
+    float qcompress;  ///< amount of qscale change between easy & hard scenes (0.0-1.0)
+    float qblur;      ///< amount of qscale smoothing over time (0.0-1.0)
+
+    /**
+     * minimum quantizer
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int qmin;
+
+    /**
+     * maximum quantizer
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int qmax;
+
+    /**
+     * maximum quantizer difference between frames
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int max_qdiff;
+
+    /**
+     * ratecontrol qmin qmax limiting method
+     * 0-> clipping, 1-> use a nice continuous function to limit qscale wthin qmin/qmax.
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    float rc_qsquish;
+
+    float rc_qmod_amp;
+    int rc_qmod_freq;
+
+    /**
+     * decoder bitstream buffer size
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int rc_buffer_size;
+
+    /**
+     * ratecontrol override, see RcOverride
+     * - encoding: Allocated/set/freed by user.
+     * - decoding: unused
+     */
+    int rc_override_count;
+    RcOverride *rc_override;
+
+    /**
+     * rate control equation
+     * - encoding: Set by user
+     * - decoding: unused
+     */
+    const char *rc_eq;
+
+    /**
+     * maximum bitrate
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int rc_max_rate;
+
+    /**
+     * minimum bitrate
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int rc_min_rate;
+
+    float rc_buffer_aggressivity;
+
+    /**
+     * initial complexity for pass1 ratecontrol
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    float rc_initial_cplx;
+
+    /**
+     * Ratecontrol attempt to use, at maximum, <value> of what can be used without an underflow.
+     * - encoding: Set by user.
+     * - decoding: unused.
+     */
+    float rc_max_available_vbv_use;
+
+    /**
+     * Ratecontrol attempt to use, at least, <value> times the amount needed to prevent a vbv overflow.
+     * - encoding: Set by user.
+     * - decoding: unused.
+     */
+    float rc_min_vbv_overflow_use;
+
+    /**
+     * Number of bits which should be loaded into the rc buffer before decoding starts.
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int rc_initial_buffer_occupancy;
+
+#define FF_CODER_TYPE_VLC       0
+#define FF_CODER_TYPE_AC        1
+#define FF_CODER_TYPE_RAW       2
+#define FF_CODER_TYPE_RLE       3
+#define FF_CODER_TYPE_DEFLATE   4
+    /**
+     * coder type
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int coder_type;
+
+    /**
+     * context model
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int context_model;
+
+    /**
+     * minimum Lagrange multipler
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int lmin;
+
+    /**
+     * maximum Lagrange multipler
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int lmax;
+
+    /**
+     * frame skip threshold
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int frame_skip_threshold;
+
+    /**
+     * frame skip factor
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int frame_skip_factor;
+
+    /**
+     * frame skip exponent
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int frame_skip_exp;
+
+    /**
+     * frame skip comparison function
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int frame_skip_cmp;
+
+    /**
+     * trellis RD quantization
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int trellis;
+
+    /**
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int min_prediction_order;
+
+    /**
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int max_prediction_order;
+
+    /**
+     * GOP timecode frame start number
+     * - encoding: Set by user, in non drop frame format
+     * - decoding: Set by libavcodec (timecode in the 25 bits format, -1 if unset)
+     */
+    int64_t timecode_frame_start;
+
+    /* The RTP callback: This function is called    */
+    /* every time the encoder has a packet to send. */
+    /* It depends on the encoder if the data starts */
+    /* with a Start Code (it should). H.263 does.   */
+    /* mb_nb contains the number of macroblocks     */
+    /* encoded in the RTP payload.                  */
+    void (*rtp_callback)(struct AVCodecContext *avctx, void *data, int size, int mb_nb);
+
+    int rtp_payload_size;   /* The size of the RTP payload: the coder will  */
+                            /* do its best to deliver a chunk with size     */
+                            /* below rtp_payload_size, the chunk will start */
+                            /* with a start code on some codecs like H.263. */
+                            /* This doesn't take account of any particular  */
+                            /* headers inside the transmitted RTP payload.  */
+
+    /* statistics, used for 2-pass encoding */
+    int mv_bits;
+    int header_bits;
+    int i_tex_bits;
+    int p_tex_bits;
+    int i_count;
+    int p_count;
+    int skip_count;
+    int misc_bits;
+
+    /**
+     * number of bits used for the previously encoded frame
+     * - encoding: Set by libavcodec.
+     * - decoding: unused
+     */
+    int frame_bits;
+
+    /**
+     * pass1 encoding statistics output buffer
+     * - encoding: Set by libavcodec.
+     * - decoding: unused
+     */
+    char *stats_out;
+
+    /**
+     * pass2 encoding statistics input buffer
+     * Concatenated stuff from stats_out of pass1 should be placed here.
+     * - encoding: Allocated/set/freed by user.
+     * - decoding: unused
+     */
+    char *stats_in;
+
+    /**
+     * Work around bugs in encoders which sometimes cannot be detected automatically.
+     * - encoding: Set by user
+     * - decoding: Set by user
+     */
+    int workaround_bugs;
+#define FF_BUG_AUTODETECT       1  ///< autodetection
+#define FF_BUG_OLD_MSMPEG4      2
+#define FF_BUG_XVID_ILACE       4
+#define FF_BUG_UMP4             8
+#define FF_BUG_NO_PADDING       16
+#define FF_BUG_AMV              32
+#define FF_BUG_AC_VLC           0  ///< Will be removed, libavcodec can now handle these non-compliant files by default.
+#define FF_BUG_QPEL_CHROMA      64
+#define FF_BUG_STD_QPEL         128
+#define FF_BUG_QPEL_CHROMA2     256
+#define FF_BUG_DIRECT_BLOCKSIZE 512
+#define FF_BUG_EDGE             1024
+#define FF_BUG_HPEL_CHROMA      2048
+#define FF_BUG_DC_CLIP          4096
+#define FF_BUG_MS               8192 ///< Work around various bugs in Microsoft's broken decoders.
+#define FF_BUG_TRUNCATED       16384
+
+    /**
+     * strictly follow the standard (MPEG4, ...).
+     * - encoding: Set by user.
+     * - decoding: Set by user.
+     * Setting this to STRICT or higher means the encoder and decoder will
+     * generally do stupid things, whereas setting it to unofficial or lower
+     * will mean the encoder might produce output that is not supported by all
+     * spec-compliant decoders. Decoders don't differentiate between normal,
+     * unofficial and experimental (that is, they always try to decode things
+     * when they can) unless they are explicitly asked to behave stupidly
+     * (=strictly conform to the specs)
+     */
+    int strict_std_compliance;
+#define FF_COMPLIANCE_VERY_STRICT   2 ///< Strictly conform to an older more strict version of the spec or reference software.
+#define FF_COMPLIANCE_STRICT        1 ///< Strictly conform to all the things in the spec no matter what consequences.
+#define FF_COMPLIANCE_NORMAL        0
+#define FF_COMPLIANCE_UNOFFICIAL   -1 ///< Allow unofficial extensions
+#define FF_COMPLIANCE_EXPERIMENTAL -2 ///< Allow nonstandardized experimental things.
+
+    /**
+     * error concealment flags
+     * - encoding: unused
+     * - decoding: Set by user.
+     */
+    int error_concealment;
+#define FF_EC_GUESS_MVS   1
+#define FF_EC_DEBLOCK     2
+
+    /**
+     * debug
+     * - encoding: Set by user.
+     * - decoding: Set by user.
+     */
+    int debug;
+#define FF_DEBUG_PICT_INFO   1
+#define FF_DEBUG_RC          2
+#define FF_DEBUG_BITSTREAM   4
+#define FF_DEBUG_MB_TYPE     8
+#define FF_DEBUG_QP          16
+#define FF_DEBUG_MV          32
+#define FF_DEBUG_DCT_COEFF   0x00000040
+#define FF_DEBUG_SKIP        0x00000080
+#define FF_DEBUG_STARTCODE   0x00000100
+#define FF_DEBUG_PTS         0x00000200
+#define FF_DEBUG_ER          0x00000400
+#define FF_DEBUG_MMCO        0x00000800
+#define FF_DEBUG_BUGS        0x00001000
+#define FF_DEBUG_VIS_QP      0x00002000
+#define FF_DEBUG_VIS_MB_TYPE 0x00004000
+#define FF_DEBUG_BUFFERS     0x00008000
+#define FF_DEBUG_THREADS     0x00010000
+
+    /**
+     * debug
+     * - encoding: Set by user.
+     * - decoding: Set by user.
+     */
+    int debug_mv;
+#define FF_DEBUG_VIS_MV_P_FOR  0x00000001 //visualize forward predicted MVs of P frames
+#define FF_DEBUG_VIS_MV_B_FOR  0x00000002 //visualize forward predicted MVs of B frames
+#define FF_DEBUG_VIS_MV_B_BACK 0x00000004 //visualize backward predicted MVs of B frames
+
+    /**
+     * Error recognition; may misdetect some more or less valid parts as errors.
+     * - encoding: unused
+     * - decoding: Set by user.
+     */
+    int err_recognition;
+#define AV_EF_CRCCHECK  (1<<0)          ///< verify embedded CRCs
+#define AV_EF_BITSTREAM (1<<1)          ///< detect bitstream specification deviations
+#define AV_EF_BUFFER    (1<<2)          ///< detect improper bitstream length
+#define AV_EF_EXPLODE   (1<<3)          ///< abort decoding on minor error detection
+
+#define AV_EF_CAREFUL    (1<<16)        ///< consider things that violate the spec, are fast to calculate and have not been seen in the wild as errors
+#define AV_EF_COMPLIANT  (1<<17)        ///< consider all spec non compliancies as errors
+#define AV_EF_AGGRESSIVE (1<<18)        ///< consider things that a sane encoder should not do as an error
+
+
+    /**
+     * opaque 64bit number (generally a PTS) that will be reordered and
+     * output in AVFrame.reordered_opaque
+     * @deprecated in favor of pkt_pts
+     * - encoding: unused
+     * - decoding: Set by user.
+     */
+    int64_t reordered_opaque;
+
+    /**
+     * Hardware accelerator in use
+     * - encoding: unused.
+     * - decoding: Set by libavcodec
+     */
+    struct AVHWAccel *hwaccel;
+
+    /**
+     * Hardware accelerator context.
+     * For some hardware accelerators, a global context needs to be
+     * provided by the user. In that case, this holds display-dependent
+     * data FFmpeg cannot instantiate itself. Please refer to the
+     * FFmpeg HW accelerator documentation to know how to fill this
+     * is. e.g. for VA API, this is a struct vaapi_context.
+     * - encoding: unused
+     * - decoding: Set by user
+     */
+    void *hwaccel_context;
+
+    /**
+     * error
+     * - encoding: Set by libavcodec if flags&CODEC_FLAG_PSNR.
+     * - decoding: unused
+     */
+    uint64_t error[AV_NUM_DATA_POINTERS];
+
+    /**
+     * DCT algorithm, see FF_DCT_* below
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int dct_algo;
+#define FF_DCT_AUTO    0
+#define FF_DCT_FASTINT 1
+#define FF_DCT_INT     2
+#define FF_DCT_MMX     3
+#define FF_DCT_ALTIVEC 5
+#define FF_DCT_FAAN    6
+
+    /**
+     * IDCT algorithm, see FF_IDCT_* below.
+     * - encoding: Set by user.
+     * - decoding: Set by user.
+     */
+    int idct_algo;
+#define FF_IDCT_AUTO          0
+#define FF_IDCT_INT           1
+#define FF_IDCT_SIMPLE        2
+#define FF_IDCT_SIMPLEMMX     3
+#define FF_IDCT_ARM           7
+#define FF_IDCT_ALTIVEC       8
+#define FF_IDCT_SH4           9
+#define FF_IDCT_SIMPLEARM     10
+#define FF_IDCT_IPP           13
+#define FF_IDCT_XVIDMMX       14
+#define FF_IDCT_SIMPLEARMV5TE 16
+#define FF_IDCT_SIMPLEARMV6   17
+#define FF_IDCT_SIMPLEVIS     18
+#define FF_IDCT_FAAN          20
+#define FF_IDCT_SIMPLENEON    22
+#define FF_IDCT_SIMPLEALPHA   23
+
+    /**
+     * bits per sample/pixel from the demuxer (needed for huffyuv).
+     * - encoding: Set by libavcodec.
+     * - decoding: Set by user.
+     */
+     int bits_per_coded_sample;
+
+    /**
+     * Bits per sample/pixel of internal libavcodec pixel/sample format.
+     * - encoding: set by user.
+     * - decoding: set by libavcodec.
+     */
+    int bits_per_raw_sample;
+
+#if FF_API_LOWRES
+    /**
+     * low resolution decoding, 1-> 1/2 size, 2->1/4 size
+     * - encoding: unused
+     * - decoding: Set by user.
+     * Code outside libavcodec should access this field using:
+     * av_codec_{get,set}_lowres(avctx)
+     */
+     int lowres;
+#endif
+
+    /**
+     * the picture in the bitstream
+     * - encoding: Set by libavcodec.
+     * - decoding: Set by libavcodec.
+     */
+    AVFrame *coded_frame;
+
+    /**
+     * thread count
+     * is used to decide how many independent tasks should be passed to execute()
+     * - encoding: Set by user.
+     * - decoding: Set by user.
+     */
+    int thread_count;
+
+    /**
+     * Which multithreading methods to use.
+     * Use of FF_THREAD_FRAME will increase decoding delay by one frame per thread,
+     * so clients which cannot provide future frames should not use it.
+     *
+     * - encoding: Set by user, otherwise the default is used.
+     * - decoding: Set by user, otherwise the default is used.
+     */
+    int thread_type;
+#define FF_THREAD_FRAME   1 ///< Decode more than one frame at once
+#define FF_THREAD_SLICE   2 ///< Decode more than one part of a single frame at once
+
+    /**
+     * Which multithreading methods are in use by the codec.
+     * - encoding: Set by libavcodec.
+     * - decoding: Set by libavcodec.
+     */
+    int active_thread_type;
+
+    /**
+     * Set by the client if its custom get_buffer() callback can be called
+     * synchronously from another thread, which allows faster multithreaded decoding.
+     * draw_horiz_band() will be called from other threads regardless of this setting.
+     * Ignored if the default get_buffer() is used.
+     * - encoding: Set by user.
+     * - decoding: Set by user.
+     */
+    int thread_safe_callbacks;
+
+    /**
+     * The codec may call this to execute several independent things.
+     * It will return only after finishing all tasks.
+     * The user may replace this with some multithreaded implementation,
+     * the default implementation will execute the parts serially.
+     * @param count the number of things to execute
+     * - encoding: Set by libavcodec, user can override.
+     * - decoding: Set by libavcodec, user can override.
+     */
+    int (*execute)(struct AVCodecContext *c, int (*func)(struct AVCodecContext *c2, void *arg), void *arg2, int *ret, int count, int size);
+
+    /**
+     * The codec may call this to execute several independent things.
+     * It will return only after finishing all tasks.
+     * The user may replace this with some multithreaded implementation,
+     * the default implementation will execute the parts serially.
+     * Also see avcodec_thread_init and e.g. the --enable-pthread configure option.
+     * @param c context passed also to func
+     * @param count the number of things to execute
+     * @param arg2 argument passed unchanged to func
+     * @param ret return values of executed functions, must have space for "count" values. May be NULL.
+     * @param func function that will be called count times, with jobnr from 0 to count-1.
+     *             threadnr will be in the range 0 to c->thread_count-1 < MAX_THREADS and so that no
+     *             two instances of func executing at the same time will have the same threadnr.
+     * @return always 0 currently, but code should handle a future improvement where when any call to func
+     *         returns < 0 no further calls to func may be done and < 0 is returned.
+     * - encoding: Set by libavcodec, user can override.
+     * - decoding: Set by libavcodec, user can override.
+     */
+    int (*execute2)(struct AVCodecContext *c, int (*func)(struct AVCodecContext *c2, void *arg, int jobnr, int threadnr), void *arg2, int *ret, int count);
+
+    /**
+     * thread opaque
+     * Can be used by execute() to store some per AVCodecContext stuff.
+     * - encoding: set by execute()
+     * - decoding: set by execute()
+     */
+    void *thread_opaque;
+
+    /**
+     * noise vs. sse weight for the nsse comparsion function
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+     int nsse_weight;
+
+    /**
+     * profile
+     * - encoding: Set by user.
+     * - decoding: Set by libavcodec.
+     */
+     int profile;
+#define FF_PROFILE_UNKNOWN -99
+#define FF_PROFILE_RESERVED -100
+
+#define FF_PROFILE_AAC_MAIN 0
+#define FF_PROFILE_AAC_LOW  1
+#define FF_PROFILE_AAC_SSR  2
+#define FF_PROFILE_AAC_LTP  3
+#define FF_PROFILE_AAC_HE   4
+#define FF_PROFILE_AAC_HE_V2 28
+#define FF_PROFILE_AAC_LD   22
+#define FF_PROFILE_AAC_ELD  38
+#define FF_PROFILE_MPEG2_AAC_LOW 128
+#define FF_PROFILE_MPEG2_AAC_HE  131
+
+#define FF_PROFILE_DTS         20
+#define FF_PROFILE_DTS_ES      30
+#define FF_PROFILE_DTS_96_24   40
+#define FF_PROFILE_DTS_HD_HRA  50
+#define FF_PROFILE_DTS_HD_MA   60
+
+#define FF_PROFILE_MPEG2_422    0
+#define FF_PROFILE_MPEG2_HIGH   1
+#define FF_PROFILE_MPEG2_SS     2
+#define FF_PROFILE_MPEG2_SNR_SCALABLE  3
+#define FF_PROFILE_MPEG2_MAIN   4
+#define FF_PROFILE_MPEG2_SIMPLE 5
+
+#define FF_PROFILE_H264_CONSTRAINED  (1<<9)  // 8+1; constraint_set1_flag
+#define FF_PROFILE_H264_INTRA        (1<<11) // 8+3; constraint_set3_flag
+
+#define FF_PROFILE_H264_BASELINE             66
+#define FF_PROFILE_H264_CONSTRAINED_BASELINE (66|FF_PROFILE_H264_CONSTRAINED)
+#define FF_PROFILE_H264_MAIN                 77
+#define FF_PROFILE_H264_EXTENDED             88
+#define FF_PROFILE_H264_HIGH                 100
+#define FF_PROFILE_H264_HIGH_10              110
+#define FF_PROFILE_H264_HIGH_10_INTRA        (110|FF_PROFILE_H264_INTRA)
+#define FF_PROFILE_H264_HIGH_422             122
+#define FF_PROFILE_H264_HIGH_422_INTRA       (122|FF_PROFILE_H264_INTRA)
+#define FF_PROFILE_H264_HIGH_444             144
+#define FF_PROFILE_H264_HIGH_444_PREDICTIVE  244
+#define FF_PROFILE_H264_HIGH_444_INTRA       (244|FF_PROFILE_H264_INTRA)
+#define FF_PROFILE_H264_CAVLC_444            44
+
+#define FF_PROFILE_VC1_SIMPLE   0
+#define FF_PROFILE_VC1_MAIN     1
+#define FF_PROFILE_VC1_COMPLEX  2
+#define FF_PROFILE_VC1_ADVANCED 3
+
+#define FF_PROFILE_MPEG4_SIMPLE                     0
+#define FF_PROFILE_MPEG4_SIMPLE_SCALABLE            1
+#define FF_PROFILE_MPEG4_CORE                       2
+#define FF_PROFILE_MPEG4_MAIN                       3
+#define FF_PROFILE_MPEG4_N_BIT                      4
+#define FF_PROFILE_MPEG4_SCALABLE_TEXTURE           5
+#define FF_PROFILE_MPEG4_SIMPLE_FACE_ANIMATION      6
+#define FF_PROFILE_MPEG4_BASIC_ANIMATED_TEXTURE     7
+#define FF_PROFILE_MPEG4_HYBRID                     8
+#define FF_PROFILE_MPEG4_ADVANCED_REAL_TIME         9
+#define FF_PROFILE_MPEG4_CORE_SCALABLE             10
+#define FF_PROFILE_MPEG4_ADVANCED_CODING           11
+#define FF_PROFILE_MPEG4_ADVANCED_CORE             12
+#define FF_PROFILE_MPEG4_ADVANCED_SCALABLE_TEXTURE 13
+#define FF_PROFILE_MPEG4_SIMPLE_STUDIO             14
+#define FF_PROFILE_MPEG4_ADVANCED_SIMPLE           15
+
+#define FF_PROFILE_JPEG2000_CSTREAM_RESTRICTION_0   0
+#define FF_PROFILE_JPEG2000_CSTREAM_RESTRICTION_1   1
+#define FF_PROFILE_JPEG2000_CSTREAM_NO_RESTRICTION  2
+#define FF_PROFILE_JPEG2000_DCINEMA_2K              3
+#define FF_PROFILE_JPEG2000_DCINEMA_4K              4
+
+    /**
+     * level
+     * - encoding: Set by user.
+     * - decoding: Set by libavcodec.
+     */
+     int level;
+#define FF_LEVEL_UNKNOWN -99
+
+    /**
+     * Skip loop filtering for selected frames.
+     * - encoding: unused
+     * - decoding: Set by user.
+     */
+    enum AVDiscard skip_loop_filter;
+
+    /**
+     * Skip IDCT/dequantization for selected frames.
+     * - encoding: unused
+     * - decoding: Set by user.
+     */
+    enum AVDiscard skip_idct;
+
+    /**
+     * Skip decoding for selected frames.
+     * - encoding: unused
+     * - decoding: Set by user.
+     */
+    enum AVDiscard skip_frame;
+
+    /**
+     * Header containing style information for text subtitles.
+     * For SUBTITLE_ASS subtitle type, it should contain the whole ASS
+     * [Script Info] and [V4+ Styles] section, plus the [Events] line and
+     * the Format line following. It shouldn't include any Dialogue line.
+     * - encoding: Set/allocated/freed by user (before avcodec_open2())
+     * - decoding: Set/allocated/freed by libavcodec (by avcodec_open2())
+     */
+    uint8_t *subtitle_header;
+    int subtitle_header_size;
+
+    /**
+     * Simulates errors in the bitstream to test error concealment.
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+    int error_rate;
+
+    /**
+     * Current packet as passed into the decoder, to avoid having
+     * to pass the packet into every function. Currently only valid
+     * inside lavc and get/release_buffer callbacks.
+     * - decoding: set by avcodec_decode_*, read by get_buffer() for setting pkt_pts
+     * - encoding: unused
+     */
+    AVPacket *pkt;
+
+    /**
+     * VBV delay coded in the last frame (in periods of a 27 MHz clock).
+     * Used for compliant TS muxing.
+     * - encoding: Set by libavcodec.
+     * - decoding: unused.
+     */
+    uint64_t vbv_delay;
+
+    /**
+     * Timebase in which pkt_dts/pts and AVPacket.dts/pts are.
+     * Code outside libavcodec should access this field using:
+     * av_codec_{get,set}_pkt_timebase(avctx)
+     * - encoding unused.
+     * - decoding set by user.
+     */
+    AVRational pkt_timebase;
+
+    /**
+     * AVCodecDescriptor
+     * Code outside libavcodec should access this field using:
+     * av_codec_{get,set}_codec_descriptor(avctx)
+     * - encoding: unused.
+     * - decoding: set by libavcodec.
+     */
+    const AVCodecDescriptor *codec_descriptor;
+
+#if !FF_API_LOWRES
+    /**
+     * low resolution decoding, 1-> 1/2 size, 2->1/4 size
+     * - encoding: unused
+     * - decoding: Set by user.
+     * Code outside libavcodec should access this field using:
+     * av_codec_{get,set}_lowres(avctx)
+     */
+     int lowres;
+#endif
+
+    /**
+     * Current statistics for PTS correction.
+     * - decoding: maintained and used by libavcodec, not intended to be used by user apps
+     * - encoding: unused
+     */
+    int64_t pts_correction_num_faulty_pts; /// Number of incorrect PTS values so far
+    int64_t pts_correction_num_faulty_dts; /// Number of incorrect DTS values so far
+    int64_t pts_correction_last_pts;       /// PTS of the last frame
+    int64_t pts_correction_last_dts;       /// DTS of the last frame
+
+    /**
+     * Character encoding of the input subtitles file.
+     * - decoding: set by user
+     * - encoding: unused
+     */
+    char *sub_charenc;
+
+    /**
+     * Subtitles character encoding mode. Formats or codecs might be adjusting
+     * this setting (if they are doing the conversion themselves for instance).
+     * - decoding: set by libavcodec
+     * - encoding: unused
+     */
+    int sub_charenc_mode;
+#define FF_SUB_CHARENC_MODE_DO_NOTHING  -1  ///< do nothing (demuxer outputs a stream supposed to be already in UTF-8, or the codec is bitmap for instance)
+#define FF_SUB_CHARENC_MODE_AUTOMATIC    0  ///< libavcodec will select the mode itself
+#define FF_SUB_CHARENC_MODE_PRE_DECODER  1  ///< the AVPacket data needs to be recoded to UTF-8 before being fed to the decoder, requires iconv
+
+    /**
+     * Skip processing alpha if supported by codec.
+     * Note that if the format uses pre-multiplied alpha (common with VP6,
+     * and recommended due to better video quality/compression)
+     * the image will look as if alpha-blended onto a black background.
+     * However for formats that do not use pre-multiplied alpha
+     * there might be serious artefacts (though e.g. libswscale currently
+     * assumes pre-multiplied alpha anyway).
+     * Code outside libavcodec should access this field using AVOptions
+     *
+     * - decoding: set by user
+     * - encoding: unused
+     */
+    int skip_alpha;
+
+    /**
+     * Number of samples to skip after a discontinuity
+     * - decoding: unused
+     * - encoding: set by libavcodec
+     */
+    int seek_preroll;
+} AVCodecContext;
+
+AVRational av_codec_get_pkt_timebase         (const AVCodecContext *avctx);
+void       av_codec_set_pkt_timebase         (AVCodecContext *avctx, AVRational val);
+
+const AVCodecDescriptor *av_codec_get_codec_descriptor(const AVCodecContext *avctx);
+void                     av_codec_set_codec_descriptor(AVCodecContext *avctx, const AVCodecDescriptor *desc);
+
+int  av_codec_get_lowres(const AVCodecContext *avctx);
+void av_codec_set_lowres(AVCodecContext *avctx, int val);
+
+int  av_codec_get_seek_preroll(const AVCodecContext *avctx);
+void av_codec_set_seek_preroll(AVCodecContext *avctx, int val);
+
+/**
+ * AVProfile.
+ */
+typedef struct AVProfile {
+    int profile;
+    const char *name; ///< short name for the profile
+} AVProfile;
+
+typedef struct AVCodecDefault AVCodecDefault;
+
+struct AVSubtitle;
+
+/**
+ * AVCodec.
+ */
+typedef struct AVCodec {
+    /**
+     * Name of the codec implementation.
+     * The name is globally unique among encoders and among decoders (but an
+     * encoder and a decoder can share the same name).
+     * This is the primary way to find a codec from the user perspective.
+     */
+    const char *name;
+    /**
+     * Descriptive name for the codec, meant to be more human readable than name.
+     * You should use the NULL_IF_CONFIG_SMALL() macro to define it.
+     */
+    const char *long_name;
+    enum AVMediaType type;
+    enum AVCodecID id;
+    /**
+     * Codec capabilities.
+     * see CODEC_CAP_*
+     */
+    int capabilities;
+    const AVRational *supported_framerates; ///< array of supported framerates, or NULL if any, array is terminated by {0,0}
+    const enum AVPixelFormat *pix_fmts;     ///< array of supported pixel formats, or NULL if unknown, array is terminated by -1
+    const int *supported_samplerates;       ///< array of supported audio samplerates, or NULL if unknown, array is terminated by 0
+    const enum AVSampleFormat *sample_fmts; ///< array of supported sample formats, or NULL if unknown, array is terminated by -1
+    const uint64_t *channel_layouts;         ///< array of support channel layouts, or NULL if unknown. array is terminated by 0
+#if FF_API_LOWRES
+    uint8_t max_lowres;                     ///< maximum value for lowres supported by the decoder, no direct access, use av_codec_get_max_lowres()
+#endif
+    const AVClass *priv_class;              ///< AVClass for the private context
+    const AVProfile *profiles;              ///< array of recognized profiles, or NULL if unknown, array is terminated by {FF_PROFILE_UNKNOWN}
+
+    /*****************************************************************
+     * No fields below this line are part of the public API. They
+     * may not be used outside of libavcodec and can be changed and
+     * removed at will.
+     * New public fields should be added right above.
+     *****************************************************************
+     */
+    int priv_data_size;
+    struct AVCodec *next;
+    /**
+     * @name Frame-level threading support functions
+     * @{
+     */
+    /**
+     * If defined, called on thread contexts when they are created.
+     * If the codec allocates writable tables in init(), re-allocate them here.
+     * priv_data will be set to a copy of the original.
+     */
+    int (*init_thread_copy)(AVCodecContext *);
+    /**
+     * Copy necessary context variables from a previous thread context to the current one.
+     * If not defined, the next thread will start automatically; otherwise, the codec
+     * must call ff_thread_finish_setup().
+     *
+     * dst and src will (rarely) point to the same context, in which case memcpy should be skipped.
+     */
+    int (*update_thread_context)(AVCodecContext *dst, const AVCodecContext *src);
+    /** @} */
+
+    /**
+     * Private codec-specific defaults.
+     */
+    const AVCodecDefault *defaults;
+
+    /**
+     * Initialize codec static data, called from avcodec_register().
+     */
+    void (*init_static_data)(struct AVCodec *codec);
+
+    int (*init)(AVCodecContext *);
+    int (*encode_sub)(AVCodecContext *, uint8_t *buf, int buf_size,
+                      const struct AVSubtitle *sub);
+    /**
+     * Encode data to an AVPacket.
+     *
+     * @param      avctx          codec context
+     * @param      avpkt          output AVPacket (may contain a user-provided buffer)
+     * @param[in]  frame          AVFrame containing the raw data to be encoded
+     * @param[out] got_packet_ptr encoder sets to 0 or 1 to indicate that a
+     *                            non-empty packet was returned in avpkt.
+     * @return 0 on success, negative error code on failure
+     */
+    int (*encode2)(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame,
+                   int *got_packet_ptr);
+    int (*decode)(AVCodecContext *, void *outdata, int *outdata_size, AVPacket *avpkt);
+    int (*close)(AVCodecContext *);
+    /**
+     * Flush buffers.
+     * Will be called when seeking
+     */
+    void (*flush)(AVCodecContext *);
+} AVCodec;
+
+int av_codec_get_max_lowres(const AVCodec *codec);
+
+/**
+ * AVHWAccel.
+ */
+typedef struct AVHWAccel {
+    /**
+     * Name of the hardware accelerated codec.
+     * The name is globally unique among encoders and among decoders (but an
+     * encoder and a decoder can share the same name).
+     */
+    const char *name;
+
+    /**
+     * Type of codec implemented by the hardware accelerator.
+     *
+     * See AVMEDIA_TYPE_xxx
+     */
+    enum AVMediaType type;
+
+    /**
+     * Codec implemented by the hardware accelerator.
+     *
+     * See AV_CODEC_ID_xxx
+     */
+    enum AVCodecID id;
+
+    /**
+     * Supported pixel format.
+     *
+     * Only hardware accelerated formats are supported here.
+     */
+    enum AVPixelFormat pix_fmt;
+
+    /**
+     * Hardware accelerated codec capabilities.
+     * see FF_HWACCEL_CODEC_CAP_*
+     */
+    int capabilities;
+
+    struct AVHWAccel *next;
+
+    /**
+     * Called at the beginning of each frame or field picture.
+     *
+     * Meaningful frame information (codec specific) is guaranteed to
+     * be parsed at this point. This function is mandatory.
+     *
+     * Note that buf can be NULL along with buf_size set to 0.
+     * Otherwise, this means the whole frame is available at this point.
+     *
+     * @param avctx the codec context
+     * @param buf the frame data buffer base
+     * @param buf_size the size of the frame in bytes
+     * @return zero if successful, a negative value otherwise
+     */
+    int (*start_frame)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size);
+
+    /**
+     * Callback for each slice.
+     *
+     * Meaningful slice information (codec specific) is guaranteed to
+     * be parsed at this point. This function is mandatory.
+     *
+     * @param avctx the codec context
+     * @param buf the slice data buffer base
+     * @param buf_size the size of the slice in bytes
+     * @return zero if successful, a negative value otherwise
+     */
+    int (*decode_slice)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size);
+
+    /**
+     * Called at the end of each frame or field picture.
+     *
+     * The whole picture is parsed at this point and can now be sent
+     * to the hardware accelerator. This function is mandatory.
+     *
+     * @param avctx the codec context
+     * @return zero if successful, a negative value otherwise
+     */
+    int (*end_frame)(AVCodecContext *avctx);
+
+    /**
+     * Size of HW accelerator private data.
+     *
+     * Private data is allocated with av_mallocz() before
+     * AVCodecContext.get_buffer() and deallocated after
+     * AVCodecContext.release_buffer().
+     */
+    int priv_data_size;
+} AVHWAccel;
+
+/**
+ * @defgroup lavc_picture AVPicture
+ *
+ * Functions for working with AVPicture
+ * @{
+ */
+
+/**
+ * Picture data structure.
+ *
+ * Up to four components can be stored into it, the last component is
+ * alpha.
+ */
+typedef struct AVPicture {
+    uint8_t *data[AV_NUM_DATA_POINTERS];    ///< pointers to the image data planes
+    int linesize[AV_NUM_DATA_POINTERS];     ///< number of bytes per line
+} AVPicture;
+
+/**
+ * @}
+ */
+
+enum AVSubtitleType {
+    SUBTITLE_NONE,
+
+    SUBTITLE_BITMAP,                ///< A bitmap, pict will be set
+
+    /**
+     * Plain text, the text field must be set by the decoder and is
+     * authoritative. ass and pict fields may contain approximations.
+     */
+    SUBTITLE_TEXT,
+
+    /**
+     * Formatted text, the ass field must be set by the decoder and is
+     * authoritative. pict and text fields may contain approximations.
+     */
+    SUBTITLE_ASS,
+};
+
+#define AV_SUBTITLE_FLAG_FORCED 0x00000001
+
+typedef struct AVSubtitleRect {
+    int x;         ///< top left corner  of pict, undefined when pict is not set
+    int y;         ///< top left corner  of pict, undefined when pict is not set
+    int w;         ///< width            of pict, undefined when pict is not set
+    int h;         ///< height           of pict, undefined when pict is not set
+    int nb_colors; ///< number of colors in pict, undefined when pict is not set
+
+    /**
+     * data+linesize for the bitmap of this subtitle.
+     * can be set for text/ass as well once they where rendered
+     */
+    AVPicture pict;
+    enum AVSubtitleType type;
+
+    char *text;                     ///< 0 terminated plain UTF-8 text
+
+    /**
+     * 0 terminated ASS/SSA compatible event line.
+     * The presentation of this is unaffected by the other values in this
+     * struct.
+     */
+    char *ass;
+
+    int flags;
+} AVSubtitleRect;
+
+typedef struct AVSubtitle {
+    uint16_t format; /* 0 = graphics */
+    uint32_t start_display_time; /* relative to packet pts, in ms */
+    uint32_t end_display_time; /* relative to packet pts, in ms */
+    unsigned num_rects;
+    AVSubtitleRect **rects;
+    int64_t pts;    ///< Same as packet pts, in AV_TIME_BASE
+} AVSubtitle;
+
+/**
+ * If c is NULL, returns the first registered codec,
+ * if c is non-NULL, returns the next registered codec after c,
+ * or NULL if c is the last one.
+ */
+AVCodec *av_codec_next(const AVCodec *c);
+
+/**
+ * Return the LIBAVCODEC_VERSION_INT constant.
+ */
+unsigned avcodec_version(void);
+
+/**
+ * Return the libavcodec build-time configuration.
+ */
+const char *avcodec_configuration(void);
+
+/**
+ * Return the libavcodec license.
+ */
+const char *avcodec_license(void);
+
+/**
+ * Register the codec codec and initialize libavcodec.
+ *
+ * @warning either this function or avcodec_register_all() must be called
+ * before any other libavcodec functions.
+ *
+ * @see avcodec_register_all()
+ */
+void avcodec_register(AVCodec *codec);
+
+/**
+ * Register all the codecs, parsers and bitstream filters which were enabled at
+ * configuration time. If you do not call this function you can select exactly
+ * which formats you want to support, by using the individual registration
+ * functions.
+ *
+ * @see avcodec_register
+ * @see av_register_codec_parser
+ * @see av_register_bitstream_filter
+ */
+void avcodec_register_all(void);
+
+
+#if FF_API_ALLOC_CONTEXT
+/**
+ * Allocate an AVCodecContext and set its fields to default values.  The
+ * resulting struct can be deallocated by simply calling av_free().
+ *
+ * @return An AVCodecContext filled with default values or NULL on failure.
+ * @see avcodec_get_context_defaults
+ *
+ * @deprecated use avcodec_alloc_context3()
+ */
+attribute_deprecated
+AVCodecContext *avcodec_alloc_context(void);
+
+/** THIS FUNCTION IS NOT YET PART OF THE PUBLIC API!
+ *  we WILL change its arguments and name a few times! */
+attribute_deprecated
+AVCodecContext *avcodec_alloc_context2(enum AVMediaType);
+
+/**
+ * Set the fields of the given AVCodecContext to default values.
+ *
+ * @param s The AVCodecContext of which the fields should be set to default values.
+ * @deprecated use avcodec_get_context_defaults3
+ */
+attribute_deprecated
+void avcodec_get_context_defaults(AVCodecContext *s);
+
+/** THIS FUNCTION IS NOT YET PART OF THE PUBLIC API!
+ *  we WILL change its arguments and name a few times! */
+attribute_deprecated
+void avcodec_get_context_defaults2(AVCodecContext *s, enum AVMediaType);
+#endif
+
+/**
+ * Allocate an AVCodecContext and set its fields to default values.  The
+ * resulting struct can be deallocated by calling avcodec_close() on it followed
+ * by av_free().
+ *
+ * @param codec if non-NULL, allocate private data and initialize defaults
+ *              for the given codec. It is illegal to then call avcodec_open2()
+ *              with a different codec.
+ *              If NULL, then the codec-specific defaults won't be initialized,
+ *              which may result in suboptimal default settings (this is
+ *              important mainly for encoders, e.g. libx264).
+ *
+ * @return An AVCodecContext filled with default values or NULL on failure.
+ * @see avcodec_get_context_defaults
+ */
+AVCodecContext *avcodec_alloc_context3(const AVCodec *codec);
+
+/**
+ * Set the fields of the given AVCodecContext to default values corresponding
+ * to the given codec (defaults may be codec-dependent).
+ *
+ * Do not call this function if a non-NULL codec has been passed
+ * to avcodec_alloc_context3() that allocated this AVCodecContext.
+ * If codec is non-NULL, it is illegal to call avcodec_open2() with a
+ * different codec on this AVCodecContext.
+ */
+int avcodec_get_context_defaults3(AVCodecContext *s, const AVCodec *codec);
+
+/**
+ * Get the AVClass for AVCodecContext. It can be used in combination with
+ * AV_OPT_SEARCH_FAKE_OBJ for examining options.
+ *
+ * @see av_opt_find().
+ */
+const AVClass *avcodec_get_class(void);
+
+/**
+ * Get the AVClass for AVFrame. It can be used in combination with
+ * AV_OPT_SEARCH_FAKE_OBJ for examining options.
+ *
+ * @see av_opt_find().
+ */
+const AVClass *avcodec_get_frame_class(void);
+
+/**
+ * Get the AVClass for AVSubtitleRect. It can be used in combination with
+ * AV_OPT_SEARCH_FAKE_OBJ for examining options.
+ *
+ * @see av_opt_find().
+ */
+const AVClass *avcodec_get_subtitle_rect_class(void);
+
+/**
+ * Copy the settings of the source AVCodecContext into the destination
+ * AVCodecContext. The resulting destination codec context will be
+ * unopened, i.e. you are required to call avcodec_open2() before you
+ * can use this AVCodecContext to decode/encode video/audio data.
+ *
+ * @param dest target codec context, should be initialized with
+ *             avcodec_alloc_context3(NULL), but otherwise uninitialized
+ * @param src source codec context
+ * @return AVERROR() on error (e.g. memory allocation error), 0 on success
+ */
+int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src);
+
+/**
+ * Allocate an AVFrame and set its fields to default values.  The resulting
+ * struct must be freed using avcodec_free_frame().
+ *
+ * @return An AVFrame filled with default values or NULL on failure.
+ * @see avcodec_get_frame_defaults
+ */
+AVFrame *avcodec_alloc_frame(void);
+
+/**
+ * Set the fields of the given AVFrame to default values.
+ *
+ * @param frame The AVFrame of which the fields should be set to default values.
+ */
+void avcodec_get_frame_defaults(AVFrame *frame);
+
+/**
+ * Free the frame and any dynamically allocated objects in it,
+ * e.g. extended_data.
+ *
+ * @param frame frame to be freed. The pointer will be set to NULL.
+ *
+ * @warning this function does NOT free the data buffers themselves
+ * (it does not know how, since they might have been allocated with
+ *  a custom get_buffer()).
+ */
+void avcodec_free_frame(AVFrame **frame);
+
+#if FF_API_AVCODEC_OPEN
+/**
+ * Initialize the AVCodecContext to use the given AVCodec. Prior to using this
+ * function the context has to be allocated.
+ *
+ * The functions avcodec_find_decoder_by_name(), avcodec_find_encoder_by_name(),
+ * avcodec_find_decoder() and avcodec_find_encoder() provide an easy way for
+ * retrieving a codec.
+ *
+ * @warning This function is not thread safe!
+ *
+ * @code
+ * avcodec_register_all();
+ * codec = avcodec_find_decoder(AV_CODEC_ID_H264);
+ * if (!codec)
+ *     exit(1);
+ *
+ * context = avcodec_alloc_context3(codec);
+ *
+ * if (avcodec_open(context, codec) < 0)
+ *     exit(1);
+ * @endcode
+ *
+ * @param avctx The context which will be set up to use the given codec.
+ * @param codec The codec to use within the context.
+ * @return zero on success, a negative value on error
+ * @see avcodec_alloc_context3, avcodec_find_decoder, avcodec_find_encoder, avcodec_close
+ *
+ * @deprecated use avcodec_open2
+ */
+attribute_deprecated
+int avcodec_open(AVCodecContext *avctx, AVCodec *codec);
+#endif
+
+/**
+ * Initialize the AVCodecContext to use the given AVCodec. Prior to using this
+ * function the context has to be allocated with avcodec_alloc_context3().
+ *
+ * The functions avcodec_find_decoder_by_name(), avcodec_find_encoder_by_name(),
+ * avcodec_find_decoder() and avcodec_find_encoder() provide an easy way for
+ * retrieving a codec.
+ *
+ * @warning This function is not thread safe!
+ *
+ * @code
+ * avcodec_register_all();
+ * av_dict_set(&opts, "b", "2.5M", 0);
+ * codec = avcodec_find_decoder(AV_CODEC_ID_H264);
+ * if (!codec)
+ *     exit(1);
+ *
+ * context = avcodec_alloc_context3(codec);
+ *
+ * if (avcodec_open2(context, codec, opts) < 0)
+ *     exit(1);
+ * @endcode
+ *
+ * @param avctx The context to initialize.
+ * @param codec The codec to open this context for. If a non-NULL codec has been
+ *              previously passed to avcodec_alloc_context3() or
+ *              avcodec_get_context_defaults3() for this context, then this
+ *              parameter MUST be either NULL or equal to the previously passed
+ *              codec.
+ * @param options A dictionary filled with AVCodecContext and codec-private options.
+ *                On return this object will be filled with options that were not found.
+ *
+ * @return zero on success, a negative value on error
+ * @see avcodec_alloc_context3(), avcodec_find_decoder(), avcodec_find_encoder(),
+ *      av_dict_set(), av_opt_find().
+ */
+int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options);
+
+/**
+ * Close a given AVCodecContext and free all the data associated with it
+ * (but not the AVCodecContext itself).
+ *
+ * Calling this function on an AVCodecContext that hasn't been opened will free
+ * the codec-specific data allocated in avcodec_alloc_context3() /
+ * avcodec_get_context_defaults3() with a non-NULL codec. Subsequent calls will
+ * do nothing.
+ */
+int avcodec_close(AVCodecContext *avctx);
+
+/**
+ * Free all allocated data in the given subtitle struct.
+ *
+ * @param sub AVSubtitle to free.
+ */
+void avsubtitle_free(AVSubtitle *sub);
+
+/**
+ * @}
+ */
+
+/**
+ * @addtogroup lavc_packet
+ * @{
+ */
+
+#if FF_API_DESTRUCT_PACKET
+/**
+ * Default packet destructor.
+ * @deprecated use the AVBuffer API instead
+ */
+attribute_deprecated
+void av_destruct_packet(AVPacket *pkt);
+#endif
+
+/**
+ * Initialize optional fields of a packet with default values.
+ *
+ * Note, this does not touch the data and size members, which have to be
+ * initialized separately.
+ *
+ * @param pkt packet
+ */
+void av_init_packet(AVPacket *pkt);
+
+/**
+ * Allocate the payload of a packet and initialize its fields with
+ * default values.
+ *
+ * @param pkt packet
+ * @param size wanted payload size
+ * @return 0 if OK, AVERROR_xxx otherwise
+ */
+int av_new_packet(AVPacket *pkt, int size);
+
+/**
+ * Reduce packet size, correctly zeroing padding
+ *
+ * @param pkt packet
+ * @param size new size
+ */
+void av_shrink_packet(AVPacket *pkt, int size);
+
+/**
+ * Increase packet size, correctly zeroing padding
+ *
+ * @param pkt packet
+ * @param grow_by number of bytes by which to increase the size of the packet
+ */
+int av_grow_packet(AVPacket *pkt, int grow_by);
+
+/**
+ * Initialize a reference-counted packet from av_malloc()ed data.
+ *
+ * @param pkt packet to be initialized. This function will set the data, size,
+ *        buf and destruct fields, all others are left untouched.
+ * @param data Data allocated by av_malloc() to be used as packet data. If this
+ *        function returns successfully, the data is owned by the underlying AVBuffer.
+ *        The caller may not access the data through other means.
+ * @param size size of data in bytes, without the padding. I.e. the full buffer
+ *        size is assumed to be size + FF_INPUT_BUFFER_PADDING_SIZE.
+ *
+ * @return 0 on success, a negative AVERROR on error
+ */
+int av_packet_from_data(AVPacket *pkt, uint8_t *data, int size);
+
+/**
+ * @warning This is a hack - the packet memory allocation stuff is broken. The
+ * packet is allocated if it was not really allocated.
+ */
+int av_dup_packet(AVPacket *pkt);
+
+/**
+ * Copy packet, including contents
+ *
+ * @return 0 on success, negative AVERROR on fail
+ */
+int av_copy_packet(AVPacket *dst, AVPacket *src);
+
+/**
+ * Copy packet side data
+ *
+ * @return 0 on success, negative AVERROR on fail
+ */
+int av_copy_packet_side_data(AVPacket *dst, AVPacket *src);
+
+/**
+ * Free a packet.
+ *
+ * @param pkt packet to free
+ */
+void av_free_packet(AVPacket *pkt);
+
+/**
+ * Allocate new information of a packet.
+ *
+ * @param pkt packet
+ * @param type side information type
+ * @param size side information size
+ * @return pointer to fresh allocated data or NULL otherwise
+ */
+uint8_t* av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
+                                 int size);
+
+/**
+ * Shrink the already allocated side data buffer
+ *
+ * @param pkt packet
+ * @param type side information type
+ * @param size new side information size
+ * @return 0 on success, < 0 on failure
+ */
+int av_packet_shrink_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
+                               int size);
+
+/**
+ * Get side information from packet.
+ *
+ * @param pkt packet
+ * @param type desired side information type
+ * @param size pointer for side information size to store (optional)
+ * @return pointer to data if present or NULL otherwise
+ */
+uint8_t* av_packet_get_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
+                                 int *size);
+
+int av_packet_merge_side_data(AVPacket *pkt);
+
+int av_packet_split_side_data(AVPacket *pkt);
+
+
+/**
+ * Convenience function to free all the side data stored.
+ * All the other fields stay untouched.
+ *
+ * @param pkt packet
+ */
+void av_packet_free_side_data(AVPacket *pkt);
+
+/**
+ * Setup a new reference to the data described by a given packet
+ *
+ * If src is reference-counted, setup dst as a new reference to the
+ * buffer in src. Otherwise allocate a new buffer in dst and copy the
+ * data from src into it.
+ *
+ * All the other fields are copied from src.
+ *
+ * @see av_packet_unref
+ *
+ * @param dst Destination packet
+ * @param src Source packet
+ *
+ * @return 0 on success, a negative AVERROR on error.
+ */
+int av_packet_ref(AVPacket *dst, AVPacket *src);
+
+/**
+ * Wipe the packet.
+ *
+ * Unreference the buffer referenced by the packet and reset the
+ * remaining packet fields to their default values.
+ *
+ * @param pkt The packet to be unreferenced.
+ */
+void av_packet_unref(AVPacket *pkt);
+
+/**
+ * Move every field in src to dst and reset src.
+ *
+ * @see av_packet_unref
+ *
+ * @param src Source packet, will be reset
+ * @param dst Destination packet
+ */
+void av_packet_move_ref(AVPacket *dst, AVPacket *src);
+
+/**
+ * Copy only "properties" fields from src to dst.
+ *
+ * Properties for the purpose of this function are all the fields
+ * beside those related to the packet data (buf, data, size)
+ *
+ * @param dst Destination packet
+ * @param src Source packet
+ *
+ * @return 0 on success AVERROR on failure.
+ *
+ */
+int av_packet_copy_props(AVPacket *dst, const AVPacket *src);
+
+/**
+ * @}
+ */
+
+/**
+ * @addtogroup lavc_decoding
+ * @{
+ */
+
+/**
+ * Find a registered decoder with a matching codec ID.
+ *
+ * @param id AVCodecID of the requested decoder
+ * @return A decoder if one was found, NULL otherwise.
+ */
+AVCodec *avcodec_find_decoder(enum AVCodecID id);
+
+/**
+ * Find a registered decoder with the specified name.
+ *
+ * @param name name of the requested decoder
+ * @return A decoder if one was found, NULL otherwise.
+ */
+AVCodec *avcodec_find_decoder_by_name(const char *name);
+
+#if FF_API_GET_BUFFER
+attribute_deprecated int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic);
+attribute_deprecated void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic);
+attribute_deprecated int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic);
+#endif
+
+/**
+ * The default callback for AVCodecContext.get_buffer2(). It is made public so
+ * it can be called by custom get_buffer2() implementations for decoders without
+ * CODEC_CAP_DR1 set.
+ */
+int avcodec_default_get_buffer2(AVCodecContext *s, AVFrame *frame, int flags);
+
+/**
+ * Return the amount of padding in pixels which the get_buffer callback must
+ * provide around the edge of the image for codecs which do not have the
+ * CODEC_FLAG_EMU_EDGE flag.
+ *
+ * @return Required padding in pixels.
+ */
+unsigned avcodec_get_edge_width(void);
+
+/**
+ * Modify width and height values so that they will result in a memory
+ * buffer that is acceptable for the codec if you do not use any horizontal
+ * padding.
+ *
+ * May only be used if a codec with CODEC_CAP_DR1 has been opened.
+ * If CODEC_FLAG_EMU_EDGE is not set, the dimensions must have been increased
+ * according to avcodec_get_edge_width() before.
+ */
+void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height);
+
+/**
+ * Modify width and height values so that they will result in a memory
+ * buffer that is acceptable for the codec if you also ensure that all
+ * line sizes are a multiple of the respective linesize_align[i].
+ *
+ * May only be used if a codec with CODEC_CAP_DR1 has been opened.
+ * If CODEC_FLAG_EMU_EDGE is not set, the dimensions must have been increased
+ * according to avcodec_get_edge_width() before.
+ */
+void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height,
+                               int linesize_align[AV_NUM_DATA_POINTERS]);
+
+/**
+ * Converts AVChromaLocation to swscale x/y chroma position.
+ *
+ * The positions represent the chroma (0,0) position in a coordinates system
+ * with luma (0,0) representing the origin and luma(1,1) representing 256,256
+ *
+ * @param xpos  horizontal chroma sample position
+ * @param ypos  vertical   chroma sample position
+ */
+int avcodec_enum_to_chroma_pos(int *xpos, int *ypos, enum AVChromaLocation pos);
+
+/**
+ * Converts swscale x/y chroma position to AVChromaLocation.
+ *
+ * The positions represent the chroma (0,0) position in a coordinates system
+ * with luma (0,0) representing the origin and luma(1,1) representing 256,256
+ *
+ * @param xpos  horizontal chroma sample position
+ * @param ypos  vertical   chroma sample position
+ */
+enum AVChromaLocation avcodec_chroma_pos_to_enum(int xpos, int ypos);
+
+#if FF_API_OLD_DECODE_AUDIO
+/**
+ * Wrapper function which calls avcodec_decode_audio4.
+ *
+ * @deprecated Use avcodec_decode_audio4 instead.
+ *
+ * Decode the audio frame of size avpkt->size from avpkt->data into samples.
+ * Some decoders may support multiple frames in a single AVPacket, such
+ * decoders would then just decode the first frame. In this case,
+ * avcodec_decode_audio3 has to be called again with an AVPacket that contains
+ * the remaining data in order to decode the second frame etc.
+ * If no frame
+ * could be outputted, frame_size_ptr is zero. Otherwise, it is the
+ * decompressed frame size in bytes.
+ *
+ * @warning You must set frame_size_ptr to the allocated size of the
+ * output buffer before calling avcodec_decode_audio3().
+ *
+ * @warning The input buffer must be FF_INPUT_BUFFER_PADDING_SIZE larger than
+ * the actual read bytes because some optimized bitstream readers read 32 or 64
+ * bits at once and could read over the end.
+ *
+ * @warning The end of the input buffer avpkt->data should be set to 0 to ensure that
+ * no overreading happens for damaged MPEG streams.
+ *
+ * @warning You must not provide a custom get_buffer() when using
+ * avcodec_decode_audio3().  Doing so will override it with
+ * avcodec_default_get_buffer.  Use avcodec_decode_audio4() instead,
+ * which does allow the application to provide a custom get_buffer().
+ *
+ * @note You might have to align the input buffer avpkt->data and output buffer
+ * samples. The alignment requirements depend on the CPU: On some CPUs it isn't
+ * necessary at all, on others it won't work at all if not aligned and on others
+ * it will work but it will have an impact on performance.
+ *
+ * In practice, avpkt->data should have 4 byte alignment at minimum and
+ * samples should be 16 byte aligned unless the CPU doesn't need it
+ * (AltiVec and SSE do).
+ *
+ * @note Codecs which have the CODEC_CAP_DELAY capability set have a delay
+ * between input and output, these need to be fed with avpkt->data=NULL,
+ * avpkt->size=0 at the end to return the remaining frames.
+ *
+ * @param avctx the codec context
+ * @param[out] samples the output buffer, sample type in avctx->sample_fmt
+ *                     If the sample format is planar, each channel plane will
+ *                     be the same size, with no padding between channels.
+ * @param[in,out] frame_size_ptr the output buffer size in bytes
+ * @param[in] avpkt The input AVPacket containing the input buffer.
+ *            You can create such packet with av_init_packet() and by then setting
+ *            data and size, some decoders might in addition need other fields.
+ *            All decoders are designed to use the least fields possible though.
+ * @return On error a negative value is returned, otherwise the number of bytes
+ * used or zero if no frame data was decompressed (used) from the input AVPacket.
+ */
+attribute_deprecated int avcodec_decode_audio3(AVCodecContext *avctx, int16_t *samples,
+                         int *frame_size_ptr,
+                         AVPacket *avpkt);
+#endif
+
+/**
+ * Decode the audio frame of size avpkt->size from avpkt->data into frame.
+ *
+ * Some decoders may support multiple frames in a single AVPacket. Such
+ * decoders would then just decode the first frame and the return value would be
+ * less than the packet size. In this case, avcodec_decode_audio4 has to be
+ * called again with an AVPacket containing the remaining data in order to
+ * decode the second frame, etc...  Even if no frames are returned, the packet
+ * needs to be fed to the decoder with remaining data until it is completely
+ * consumed or an error occurs.
+ *
+ * Some decoders (those marked with CODEC_CAP_DELAY) have a delay between input
+ * and output. This means that for some packets they will not immediately
+ * produce decoded output and need to be flushed at the end of decoding to get
+ * all the decoded data. Flushing is done by calling this function with packets
+ * with avpkt->data set to NULL and avpkt->size set to 0 until it stops
+ * returning samples. It is safe to flush even those decoders that are not
+ * marked with CODEC_CAP_DELAY, then no samples will be returned.
+ *
+ * @warning The input buffer, avpkt->data must be FF_INPUT_BUFFER_PADDING_SIZE
+ *          larger than the actual read bytes because some optimized bitstream
+ *          readers read 32 or 64 bits at once and could read over the end.
+ *
+ * @param      avctx the codec context
+ * @param[out] frame The AVFrame in which to store decoded audio samples.
+ *                   The decoder will allocate a buffer for the decoded frame by
+ *                   calling the AVCodecContext.get_buffer2() callback.
+ *                   When AVCodecContext.refcounted_frames is set to 1, the frame is
+ *                   reference counted and the returned reference belongs to the
+ *                   caller. The caller must release the frame using av_frame_unref()
+ *                   when the frame is no longer needed. The caller may safely write
+ *                   to the frame if av_frame_is_writable() returns 1.
+ *                   When AVCodecContext.refcounted_frames is set to 0, the returned
+ *                   reference belongs to the decoder and is valid only until the
+ *                   next call to this function or until closing or flushing the
+ *                   decoder. The caller may not write to it.
+ * @param[out] got_frame_ptr Zero if no frame could be decoded, otherwise it is
+ *                           non-zero. Note that this field being set to zero
+ *                           does not mean that an error has occurred. For
+ *                           decoders with CODEC_CAP_DELAY set, no given decode
+ *                           call is guaranteed to produce a frame.
+ * @param[in]  avpkt The input AVPacket containing the input buffer.
+ *                   At least avpkt->data and avpkt->size should be set. Some
+ *                   decoders might also require additional fields to be set.
+ * @return A negative error code is returned if an error occurred during
+ *         decoding, otherwise the number of bytes consumed from the input
+ *         AVPacket is returned.
+ */
+int avcodec_decode_audio4(AVCodecContext *avctx, AVFrame *frame,
+                          int *got_frame_ptr, const AVPacket *avpkt);
+
+/**
+ * Decode the video frame of size avpkt->size from avpkt->data into picture.
+ * Some decoders may support multiple frames in a single AVPacket, such
+ * decoders would then just decode the first frame.
+ *
+ * @warning The input buffer must be FF_INPUT_BUFFER_PADDING_SIZE larger than
+ * the actual read bytes because some optimized bitstream readers read 32 or 64
+ * bits at once and could read over the end.
+ *
+ * @warning The end of the input buffer buf should be set to 0 to ensure that
+ * no overreading happens for damaged MPEG streams.
+ *
+ * @note Codecs which have the CODEC_CAP_DELAY capability set have a delay
+ * between input and output, these need to be fed with avpkt->data=NULL,
+ * avpkt->size=0 at the end to return the remaining frames.
+ *
+ * @param avctx the codec context
+ * @param[out] picture The AVFrame in which the decoded video frame will be stored.
+ *             Use av_frame_alloc() to get an AVFrame. The codec will
+ *             allocate memory for the actual bitmap by calling the
+ *             AVCodecContext.get_buffer2() callback.
+ *             When AVCodecContext.refcounted_frames is set to 1, the frame is
+ *             reference counted and the returned reference belongs to the
+ *             caller. The caller must release the frame using av_frame_unref()
+ *             when the frame is no longer needed. The caller may safely write
+ *             to the frame if av_frame_is_writable() returns 1.
+ *             When AVCodecContext.refcounted_frames is set to 0, the returned
+ *             reference belongs to the decoder and is valid only until the
+ *             next call to this function or until closing or flushing the
+ *             decoder. The caller may not write to it.
+ *
+ * @param[in] avpkt The input AVPacket containing the input buffer.
+ *            You can create such packet with av_init_packet() and by then setting
+ *            data and size, some decoders might in addition need other fields like
+ *            flags&AV_PKT_FLAG_KEY. All decoders are designed to use the least
+ *            fields possible.
+ * @param[in,out] got_picture_ptr Zero if no frame could be decompressed, otherwise, it is nonzero.
+ * @return On error a negative value is returned, otherwise the number of bytes
+ * used or zero if no frame could be decompressed.
+ */
+int avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture,
+                         int *got_picture_ptr,
+                         const AVPacket *avpkt);
+
+/**
+ * Decode a subtitle message.
+ * Return a negative value on error, otherwise return the number of bytes used.
+ * If no subtitle could be decompressed, got_sub_ptr is zero.
+ * Otherwise, the subtitle is stored in *sub.
+ * Note that CODEC_CAP_DR1 is not available for subtitle codecs. This is for
+ * simplicity, because the performance difference is expect to be negligible
+ * and reusing a get_buffer written for video codecs would probably perform badly
+ * due to a potentially very different allocation pattern.
+ *
+ * Some decoders (those marked with CODEC_CAP_DELAY) have a delay between input
+ * and output. This means that for some packets they will not immediately
+ * produce decoded output and need to be flushed at the end of decoding to get
+ * all the decoded data. Flushing is done by calling this function with packets
+ * with avpkt->data set to NULL and avpkt->size set to 0 until it stops
+ * returning subtitles. It is safe to flush even those decoders that are not
+ * marked with CODEC_CAP_DELAY, then no subtitles will be returned.
+ *
+ * @param avctx the codec context
+ * @param[out] sub The AVSubtitle in which the decoded subtitle will be stored, must be
+                   freed with avsubtitle_free if *got_sub_ptr is set.
+ * @param[in,out] got_sub_ptr Zero if no subtitle could be decompressed, otherwise, it is nonzero.
+ * @param[in] avpkt The input AVPacket containing the input buffer.
+ */
+int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
+                            int *got_sub_ptr,
+                            AVPacket *avpkt);
+
+/**
+ * @defgroup lavc_parsing Frame parsing
+ * @{
+ */
+
+enum AVPictureStructure {
+    AV_PICTURE_STRUCTURE_UNKNOWN,      //< unknown
+    AV_PICTURE_STRUCTURE_TOP_FIELD,    //< coded as top field
+    AV_PICTURE_STRUCTURE_BOTTOM_FIELD, //< coded as bottom field
+    AV_PICTURE_STRUCTURE_FRAME,        //< coded as frame
+};
+
+typedef struct AVCodecParserContext {
+    void *priv_data;
+    struct AVCodecParser *parser;
+    int64_t frame_offset; /* offset of the current frame */
+    int64_t cur_offset; /* current offset
+                           (incremented by each av_parser_parse()) */
+    int64_t next_frame_offset; /* offset of the next frame */
+    /* video info */
+    int pict_type; /* XXX: Put it back in AVCodecContext. */
+    /**
+     * This field is used for proper frame duration computation in lavf.
+     * It signals, how much longer the frame duration of the current frame
+     * is compared to normal frame duration.
+     *
+     * frame_duration = (1 + repeat_pict) * time_base
+     *
+     * It is used by codecs like H.264 to display telecined material.
+     */
+    int repeat_pict; /* XXX: Put it back in AVCodecContext. */
+    int64_t pts;     /* pts of the current frame */
+    int64_t dts;     /* dts of the current frame */
+
+    /* private data */
+    int64_t last_pts;
+    int64_t last_dts;
+    int fetch_timestamp;
+
+#define AV_PARSER_PTS_NB 4
+    int cur_frame_start_index;
+    int64_t cur_frame_offset[AV_PARSER_PTS_NB];
+    int64_t cur_frame_pts[AV_PARSER_PTS_NB];
+    int64_t cur_frame_dts[AV_PARSER_PTS_NB];
+
+    int flags;
+#define PARSER_FLAG_COMPLETE_FRAMES           0x0001
+#define PARSER_FLAG_ONCE                      0x0002
+/// Set if the parser has a valid file offset
+#define PARSER_FLAG_FETCHED_OFFSET            0x0004
+#define PARSER_FLAG_USE_CODEC_TS              0x1000
+
+    int64_t offset;      ///< byte offset from starting packet start
+    int64_t cur_frame_end[AV_PARSER_PTS_NB];
+
+    /**
+     * Set by parser to 1 for key frames and 0 for non-key frames.
+     * It is initialized to -1, so if the parser doesn't set this flag,
+     * old-style fallback using AV_PICTURE_TYPE_I picture type as key frames
+     * will be used.
+     */
+    int key_frame;
+
+    /**
+     * Time difference in stream time base units from the pts of this
+     * packet to the point at which the output from the decoder has converged
+     * independent from the availability of previous frames. That is, the
+     * frames are virtually identical no matter if decoding started from
+     * the very first frame or from this keyframe.
+     * Is AV_NOPTS_VALUE if unknown.
+     * This field is not the display duration of the current frame.
+     * This field has no meaning if the packet does not have AV_PKT_FLAG_KEY
+     * set.
+     *
+     * The purpose of this field is to allow seeking in streams that have no
+     * keyframes in the conventional sense. It corresponds to the
+     * recovery point SEI in H.264 and match_time_delta in NUT. It is also
+     * essential for some types of subtitle streams to ensure that all
+     * subtitles are correctly displayed after seeking.
+     */
+    int64_t convergence_duration;
+
+    // Timestamp generation support:
+    /**
+     * Synchronization point for start of timestamp generation.
+     *
+     * Set to >0 for sync point, 0 for no sync point and <0 for undefined
+     * (default).
+     *
+     * For example, this corresponds to presence of H.264 buffering period
+     * SEI message.
+     */
+    int dts_sync_point;
+
+    /**
+     * Offset of the current timestamp against last timestamp sync point in
+     * units of AVCodecContext.time_base.
+     *
+     * Set to INT_MIN when dts_sync_point unused. Otherwise, it must
+     * contain a valid timestamp offset.
+     *
+     * Note that the timestamp of sync point has usually a nonzero
+     * dts_ref_dts_delta, which refers to the previous sync point. Offset of
+     * the next frame after timestamp sync point will be usually 1.
+     *
+     * For example, this corresponds to H.264 cpb_removal_delay.
+     */
+    int dts_ref_dts_delta;
+
+    /**
+     * Presentation delay of current frame in units of AVCodecContext.time_base.
+     *
+     * Set to INT_MIN when dts_sync_point unused. Otherwise, it must
+     * contain valid non-negative timestamp delta (presentation time of a frame
+     * must not lie in the past).
+     *
+     * This delay represents the difference between decoding and presentation
+     * time of the frame.
+     *
+     * For example, this corresponds to H.264 dpb_output_delay.
+     */
+    int pts_dts_delta;
+
+    /**
+     * Position of the packet in file.
+     *
+     * Analogous to cur_frame_pts/dts
+     */
+    int64_t cur_frame_pos[AV_PARSER_PTS_NB];
+
+    /**
+     * Byte position of currently parsed frame in stream.
+     */
+    int64_t pos;
+
+    /**
+     * Previous frame byte position.
+     */
+    int64_t last_pos;
+
+    /**
+     * Duration of the current frame.
+     * For audio, this is in units of 1 / AVCodecContext.sample_rate.
+     * For all other types, this is in units of AVCodecContext.time_base.
+     */
+    int duration;
+
+    enum AVFieldOrder field_order;
+
+    /**
+     * Indicate whether a picture is coded as a frame, top field or bottom field.
+     *
+     * For example, H.264 field_pic_flag equal to 0 corresponds to
+     * AV_PICTURE_STRUCTURE_FRAME. An H.264 picture with field_pic_flag
+     * equal to 1 and bottom_field_flag equal to 0 corresponds to
+     * AV_PICTURE_STRUCTURE_TOP_FIELD.
+     */
+    enum AVPictureStructure picture_structure;
+
+    /**
+     * Picture number incremented in presentation or output order.
+     * This field may be reinitialized at the first picture of a new sequence.
+     *
+     * For example, this corresponds to H.264 PicOrderCnt.
+     */
+    int output_picture_number;
+} AVCodecParserContext;
+
+typedef struct AVCodecParser {
+    int codec_ids[5]; /* several codec IDs are permitted */
+    int priv_data_size;
+    int (*parser_init)(AVCodecParserContext *s);
+    int (*parser_parse)(AVCodecParserContext *s,
+                        AVCodecContext *avctx,
+                        const uint8_t **poutbuf, int *poutbuf_size,
+                        const uint8_t *buf, int buf_size);
+    void (*parser_close)(AVCodecParserContext *s);
+    int (*split)(AVCodecContext *avctx, const uint8_t *buf, int buf_size);
+    struct AVCodecParser *next;
+} AVCodecParser;
+
+AVCodecParser *av_parser_next(AVCodecParser *c);
+
+void av_register_codec_parser(AVCodecParser *parser);
+AVCodecParserContext *av_parser_init(int codec_id);
+
+/**
+ * Parse a packet.
+ *
+ * @param s             parser context.
+ * @param avctx         codec context.
+ * @param poutbuf       set to pointer to parsed buffer or NULL if not yet finished.
+ * @param poutbuf_size  set to size of parsed buffer or zero if not yet finished.
+ * @param buf           input buffer.
+ * @param buf_size      input length, to signal EOF, this should be 0 (so that the last frame can be output).
+ * @param pts           input presentation timestamp.
+ * @param dts           input decoding timestamp.
+ * @param pos           input byte position in stream.
+ * @return the number of bytes of the input bitstream used.
+ *
+ * Example:
+ * @code
+ *   while(in_len){
+ *       len = av_parser_parse2(myparser, AVCodecContext, &data, &size,
+ *                                        in_data, in_len,
+ *                                        pts, dts, pos);
+ *       in_data += len;
+ *       in_len  -= len;
+ *
+ *       if(size)
+ *          decode_frame(data, size);
+ *   }
+ * @endcode
+ */
+int av_parser_parse2(AVCodecParserContext *s,
+                     AVCodecContext *avctx,
+                     uint8_t **poutbuf, int *poutbuf_size,
+                     const uint8_t *buf, int buf_size,
+                     int64_t pts, int64_t dts,
+                     int64_t pos);
+
+/**
+ * @return 0 if the output buffer is a subset of the input, 1 if it is allocated and must be freed
+ * @deprecated use AVBitStreamFilter
+ */
+int av_parser_change(AVCodecParserContext *s,
+                     AVCodecContext *avctx,
+                     uint8_t **poutbuf, int *poutbuf_size,
+                     const uint8_t *buf, int buf_size, int keyframe);
+void av_parser_close(AVCodecParserContext *s);
+
+/**
+ * @}
+ * @}
+ */
+
+/**
+ * @addtogroup lavc_encoding
+ * @{
+ */
+
+/**
+ * Find a registered encoder with a matching codec ID.
+ *
+ * @param id AVCodecID of the requested encoder
+ * @return An encoder if one was found, NULL otherwise.
+ */
+AVCodec *avcodec_find_encoder(enum AVCodecID id);
+
+/**
+ * Find a registered encoder with the specified name.
+ *
+ * @param name name of the requested encoder
+ * @return An encoder if one was found, NULL otherwise.
+ */
+AVCodec *avcodec_find_encoder_by_name(const char *name);
+
+#if FF_API_OLD_ENCODE_AUDIO
+/**
+ * Encode an audio frame from samples into buf.
+ *
+ * @deprecated Use avcodec_encode_audio2 instead.
+ *
+ * @note The output buffer should be at least FF_MIN_BUFFER_SIZE bytes large.
+ * However, for codecs with avctx->frame_size equal to 0 (e.g. PCM) the user
+ * will know how much space is needed because it depends on the value passed
+ * in buf_size as described below. In that case a lower value can be used.
+ *
+ * @param avctx the codec context
+ * @param[out] buf the output buffer
+ * @param[in] buf_size the output buffer size
+ * @param[in] samples the input buffer containing the samples
+ * The number of samples read from this buffer is frame_size*channels,
+ * both of which are defined in avctx.
+ * For codecs which have avctx->frame_size equal to 0 (e.g. PCM) the number of
+ * samples read from samples is equal to:
+ * buf_size * 8 / (avctx->channels * av_get_bits_per_sample(avctx->codec_id))
+ * This also implies that av_get_bits_per_sample() must not return 0 for these
+ * codecs.
+ * @return On error a negative value is returned, on success zero or the number
+ * of bytes used to encode the data read from the input buffer.
+ */
+int attribute_deprecated avcodec_encode_audio(AVCodecContext *avctx,
+                                              uint8_t *buf, int buf_size,
+                                              const short *samples);
+#endif
+
+/**
+ * Encode a frame of audio.
+ *
+ * Takes input samples from frame and writes the next output packet, if
+ * available, to avpkt. The output packet does not necessarily contain data for
+ * the most recent frame, as encoders can delay, split, and combine input frames
+ * internally as needed.
+ *
+ * @param avctx     codec context
+ * @param avpkt     output AVPacket.
+ *                  The user can supply an output buffer by setting
+ *                  avpkt->data and avpkt->size prior to calling the
+ *                  function, but if the size of the user-provided data is not
+ *                  large enough, encoding will fail. If avpkt->data and
+ *                  avpkt->size are set, avpkt->destruct must also be set. All
+ *                  other AVPacket fields will be reset by the encoder using
+ *                  av_init_packet(). If avpkt->data is NULL, the encoder will
+ *                  allocate it. The encoder will set avpkt->size to the size
+ *                  of the output packet.
+ *
+ *                  If this function fails or produces no output, avpkt will be
+ *                  freed using av_free_packet() (i.e. avpkt->destruct will be
+ *                  called to free the user supplied buffer).
+ * @param[in] frame AVFrame containing the raw audio data to be encoded.
+ *                  May be NULL when flushing an encoder that has the
+ *                  CODEC_CAP_DELAY capability set.
+ *                  If CODEC_CAP_VARIABLE_FRAME_SIZE is set, then each frame
+ *                  can have any number of samples.
+ *                  If it is not set, frame->nb_samples must be equal to
+ *                  avctx->frame_size for all frames except the last.
+ *                  The final frame may be smaller than avctx->frame_size.
+ * @param[out] got_packet_ptr This field is set to 1 by libavcodec if the
+ *                            output packet is non-empty, and to 0 if it is
+ *                            empty. If the function returns an error, the
+ *                            packet can be assumed to be invalid, and the
+ *                            value of got_packet_ptr is undefined and should
+ *                            not be used.
+ * @return          0 on success, negative error code on failure
+ */
+int avcodec_encode_audio2(AVCodecContext *avctx, AVPacket *avpkt,
+                          const AVFrame *frame, int *got_packet_ptr);
+
+#if FF_API_OLD_ENCODE_VIDEO
+/**
+ * @deprecated use avcodec_encode_video2() instead.
+ *
+ * Encode a video frame from pict into buf.
+ * The input picture should be
+ * stored using a specific format, namely avctx.pix_fmt.
+ *
+ * @param avctx the codec context
+ * @param[out] buf the output buffer for the bitstream of encoded frame
+ * @param[in] buf_size the size of the output buffer in bytes
+ * @param[in] pict the input picture to encode
+ * @return On error a negative value is returned, on success zero or the number
+ * of bytes used from the output buffer.
+ */
+attribute_deprecated
+int avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size,
+                         const AVFrame *pict);
+#endif
+
+/**
+ * Encode a frame of video.
+ *
+ * Takes input raw video data from frame and writes the next output packet, if
+ * available, to avpkt. The output packet does not necessarily contain data for
+ * the most recent frame, as encoders can delay and reorder input frames
+ * internally as needed.
+ *
+ * @param avctx     codec context
+ * @param avpkt     output AVPacket.
+ *                  The user can supply an output buffer by setting
+ *                  avpkt->data and avpkt->size prior to calling the
+ *                  function, but if the size of the user-provided data is not
+ *                  large enough, encoding will fail. All other AVPacket fields
+ *                  will be reset by the encoder using av_init_packet(). If
+ *                  avpkt->data is NULL, the encoder will allocate it.
+ *                  The encoder will set avpkt->size to the size of the
+ *                  output packet. The returned data (if any) belongs to the
+ *                  caller, he is responsible for freeing it.
+ *
+ *                  If this function fails or produces no output, avpkt will be
+ *                  freed using av_free_packet() (i.e. avpkt->destruct will be
+ *                  called to free the user supplied buffer).
+ * @param[in] frame AVFrame containing the raw video data to be encoded.
+ *                  May be NULL when flushing an encoder that has the
+ *                  CODEC_CAP_DELAY capability set.
+ * @param[out] got_packet_ptr This field is set to 1 by libavcodec if the
+ *                            output packet is non-empty, and to 0 if it is
+ *                            empty. If the function returns an error, the
+ *                            packet can be assumed to be invalid, and the
+ *                            value of got_packet_ptr is undefined and should
+ *                            not be used.
+ * @return          0 on success, negative error code on failure
+ */
+int avcodec_encode_video2(AVCodecContext *avctx, AVPacket *avpkt,
+                          const AVFrame *frame, int *got_packet_ptr);
+
+int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size,
+                            const AVSubtitle *sub);
+
+
+/**
+ * @}
+ */
+
+#if FF_API_AVCODEC_RESAMPLE
+/**
+ * @defgroup lavc_resample Audio resampling
+ * @ingroup libavc
+ * @deprecated use libswresample instead
+ *
+ * @{
+ */
+struct ReSampleContext;
+struct AVResampleContext;
+
+typedef struct ReSampleContext ReSampleContext;
+
+/**
+ *  Initialize audio resampling context.
+ *
+ * @param output_channels  number of output channels
+ * @param input_channels   number of input channels
+ * @param output_rate      output sample rate
+ * @param input_rate       input sample rate
+ * @param sample_fmt_out   requested output sample format
+ * @param sample_fmt_in    input sample format
+ * @param filter_length    length of each FIR filter in the filterbank relative to the cutoff frequency
+ * @param log2_phase_count log2 of the number of entries in the polyphase filterbank
+ * @param linear           if 1 then the used FIR filter will be linearly interpolated
+                           between the 2 closest, if 0 the closest will be used
+ * @param cutoff           cutoff frequency, 1.0 corresponds to half the output sampling rate
+ * @return allocated ReSampleContext, NULL if error occurred
+ */
+attribute_deprecated
+ReSampleContext *av_audio_resample_init(int output_channels, int input_channels,
+                                        int output_rate, int input_rate,
+                                        enum AVSampleFormat sample_fmt_out,
+                                        enum AVSampleFormat sample_fmt_in,
+                                        int filter_length, int log2_phase_count,
+                                        int linear, double cutoff);
+
+attribute_deprecated
+int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples);
+
+/**
+ * Free resample context.
+ *
+ * @param s a non-NULL pointer to a resample context previously
+ *          created with av_audio_resample_init()
+ */
+attribute_deprecated
+void audio_resample_close(ReSampleContext *s);
+
+
+/**
+ * Initialize an audio resampler.
+ * Note, if either rate is not an integer then simply scale both rates up so they are.
+ * @param filter_length length of each FIR filter in the filterbank relative to the cutoff freq
+ * @param log2_phase_count log2 of the number of entries in the polyphase filterbank
+ * @param linear If 1 then the used FIR filter will be linearly interpolated
+                 between the 2 closest, if 0 the closest will be used
+ * @param cutoff cutoff frequency, 1.0 corresponds to half the output sampling rate
+ */
+attribute_deprecated
+struct AVResampleContext *av_resample_init(int out_rate, int in_rate, int filter_length, int log2_phase_count, int linear, double cutoff);
+
+/**
+ * Resample an array of samples using a previously configured context.
+ * @param src an array of unconsumed samples
+ * @param consumed the number of samples of src which have been consumed are returned here
+ * @param src_size the number of unconsumed samples available
+ * @param dst_size the amount of space in samples available in dst
+ * @param update_ctx If this is 0 then the context will not be modified, that way several channels can be resampled with the same context.
+ * @return the number of samples written in dst or -1 if an error occurred
+ */
+attribute_deprecated
+int av_resample(struct AVResampleContext *c, short *dst, short *src, int *consumed, int src_size, int dst_size, int update_ctx);
+
+
+/**
+ * Compensate samplerate/timestamp drift. The compensation is done by changing
+ * the resampler parameters, so no audible clicks or similar distortions occur
+ * @param compensation_distance distance in output samples over which the compensation should be performed
+ * @param sample_delta number of output samples which should be output less
+ *
+ * example: av_resample_compensate(c, 10, 500)
+ * here instead of 510 samples only 500 samples would be output
+ *
+ * note, due to rounding the actual compensation might be slightly different,
+ * especially if the compensation_distance is large and the in_rate used during init is small
+ */
+attribute_deprecated
+void av_resample_compensate(struct AVResampleContext *c, int sample_delta, int compensation_distance);
+attribute_deprecated
+void av_resample_close(struct AVResampleContext *c);
+
+/**
+ * @}
+ */
+#endif
+
+/**
+ * @addtogroup lavc_picture
+ * @{
+ */
+
+/**
+ * Allocate memory for the pixels of a picture and setup the AVPicture
+ * fields for it.
+ *
+ * Call avpicture_free() to free it.
+ *
+ * @param picture            the picture structure to be filled in
+ * @param pix_fmt            the pixel format of the picture
+ * @param width              the width of the picture
+ * @param height             the height of the picture
+ * @return zero if successful, a negative error code otherwise
+ *
+ * @see av_image_alloc(), avpicture_fill()
+ */
+int avpicture_alloc(AVPicture *picture, enum AVPixelFormat pix_fmt, int width, int height);
+
+/**
+ * Free a picture previously allocated by avpicture_alloc().
+ * The data buffer used by the AVPicture is freed, but the AVPicture structure
+ * itself is not.
+ *
+ * @param picture the AVPicture to be freed
+ */
+void avpicture_free(AVPicture *picture);
+
+/**
+ * Setup the picture fields based on the specified image parameters
+ * and the provided image data buffer.
+ *
+ * The picture fields are filled in by using the image data buffer
+ * pointed to by ptr.
+ *
+ * If ptr is NULL, the function will fill only the picture linesize
+ * array and return the required size for the image buffer.
+ *
+ * To allocate an image buffer and fill the picture data in one call,
+ * use avpicture_alloc().
+ *
+ * @param picture       the picture to be filled in
+ * @param ptr           buffer where the image data is stored, or NULL
+ * @param pix_fmt       the pixel format of the image
+ * @param width         the width of the image in pixels
+ * @param height        the height of the image in pixels
+ * @return the size in bytes required for src, a negative error code
+ * in case of failure
+ *
+ * @see av_image_fill_arrays()
+ */
+int avpicture_fill(AVPicture *picture, const uint8_t *ptr,
+                   enum AVPixelFormat pix_fmt, int width, int height);
+
+/**
+ * Copy pixel data from an AVPicture into a buffer.
+ *
+ * avpicture_get_size() can be used to compute the required size for
+ * the buffer to fill.
+ *
+ * @param src        source picture with filled data
+ * @param pix_fmt    picture pixel format
+ * @param width      picture width
+ * @param height     picture height
+ * @param dest       destination buffer
+ * @param dest_size  destination buffer size in bytes
+ * @return the number of bytes written to dest, or a negative value
+ * (error code) on error, for example if the destination buffer is not
+ * big enough
+ *
+ * @see av_image_copy_to_buffer()
+ */
+int avpicture_layout(const AVPicture *src, enum AVPixelFormat pix_fmt,
+                     int width, int height,
+                     unsigned char *dest, int dest_size);
+
+/**
+ * Calculate the size in bytes that a picture of the given width and height
+ * would occupy if stored in the given picture format.
+ *
+ * @param pix_fmt    picture pixel format
+ * @param width      picture width
+ * @param height     picture height
+ * @return the computed picture buffer size or a negative error code
+ * in case of error
+ *
+ * @see av_image_get_buffer_size().
+ */
+int avpicture_get_size(enum AVPixelFormat pix_fmt, int width, int height);
+
+#if FF_API_DEINTERLACE
+/**
+ *  deinterlace - if not supported return -1
+ *
+ * @deprecated - use yadif (in libavfilter) instead
+ */
+attribute_deprecated
+int avpicture_deinterlace(AVPicture *dst, const AVPicture *src,
+                          enum AVPixelFormat pix_fmt, int width, int height);
+#endif
+/**
+ * Copy image src to dst. Wraps av_image_copy().
+ */
+void av_picture_copy(AVPicture *dst, const AVPicture *src,
+                     enum AVPixelFormat pix_fmt, int width, int height);
+
+/**
+ * Crop image top and left side.
+ */
+int av_picture_crop(AVPicture *dst, const AVPicture *src,
+                    enum AVPixelFormat pix_fmt, int top_band, int left_band);
+
+/**
+ * Pad image.
+ */
+int av_picture_pad(AVPicture *dst, const AVPicture *src, int height, int width, enum AVPixelFormat pix_fmt,
+            int padtop, int padbottom, int padleft, int padright, int *color);
+
+/**
+ * @}
+ */
+
+/**
+ * @defgroup lavc_misc Utility functions
+ * @ingroup libavc
+ *
+ * Miscellaneous utility functions related to both encoding and decoding
+ * (or neither).
+ * @{
+ */
+
+/**
+ * @defgroup lavc_misc_pixfmt Pixel formats
+ *
+ * Functions for working with pixel formats.
+ * @{
+ */
+
+/**
+ * Utility function to access log2_chroma_w log2_chroma_h from
+ * the pixel format AVPixFmtDescriptor.
+ *
+ * This function asserts that pix_fmt is valid. See av_pix_fmt_get_chroma_sub_sample
+ * for one that returns a failure code and continues in case of invalid
+ * pix_fmts.
+ *
+ * @param[in]  pix_fmt the pixel format
+ * @param[out] h_shift store log2_chroma_w
+ * @param[out] v_shift store log2_chroma_h
+ *
+ * @see av_pix_fmt_get_chroma_sub_sample
+ */
+
+void avcodec_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift);
+
+/**
+ * Return a value representing the fourCC code associated to the
+ * pixel format pix_fmt, or 0 if no associated fourCC code can be
+ * found.
+ */
+unsigned int avcodec_pix_fmt_to_codec_tag(enum AVPixelFormat pix_fmt);
+
+#define FF_LOSS_RESOLUTION  0x0001 /**< loss due to resolution change */
+#define FF_LOSS_DEPTH       0x0002 /**< loss due to color depth change */
+#define FF_LOSS_COLORSPACE  0x0004 /**< loss due to color space conversion */
+#define FF_LOSS_ALPHA       0x0008 /**< loss of alpha bits */
+#define FF_LOSS_COLORQUANT  0x0010 /**< loss due to color quantization */
+#define FF_LOSS_CHROMA      0x0020 /**< loss of chroma (e.g. RGB to gray conversion) */
+
+/**
+ * Compute what kind of losses will occur when converting from one specific
+ * pixel format to another.
+ * When converting from one pixel format to another, information loss may occur.
+ * For example, when converting from RGB24 to GRAY, the color information will
+ * be lost. Similarly, other losses occur when converting from some formats to
+ * other formats. These losses can involve loss of chroma, but also loss of
+ * resolution, loss of color depth, loss due to the color space conversion, loss
+ * of the alpha bits or loss due to color quantization.
+ * avcodec_get_fix_fmt_loss() informs you about the various types of losses
+ * which will occur when converting from one pixel format to another.
+ *
+ * @param[in] dst_pix_fmt destination pixel format
+ * @param[in] src_pix_fmt source pixel format
+ * @param[in] has_alpha Whether the source pixel format alpha channel is used.
+ * @return Combination of flags informing you what kind of losses will occur
+ * (maximum loss for an invalid dst_pix_fmt).
+ */
+int avcodec_get_pix_fmt_loss(enum AVPixelFormat dst_pix_fmt, enum AVPixelFormat src_pix_fmt,
+                             int has_alpha);
+
+/**
+ * Find the best pixel format to convert to given a certain source pixel
+ * format.  When converting from one pixel format to another, information loss
+ * may occur.  For example, when converting from RGB24 to GRAY, the color
+ * information will be lost. Similarly, other losses occur when converting from
+ * some formats to other formats. avcodec_find_best_pix_fmt_of_2() searches which of
+ * the given pixel formats should be used to suffer the least amount of loss.
+ * The pixel formats from which it chooses one, are determined by the
+ * pix_fmt_list parameter.
+ *
+ *
+ * @param[in] pix_fmt_list AV_PIX_FMT_NONE terminated array of pixel formats to choose from
+ * @param[in] src_pix_fmt source pixel format
+ * @param[in] has_alpha Whether the source pixel format alpha channel is used.
+ * @param[out] loss_ptr Combination of flags informing you what kind of losses will occur.
+ * @return The best pixel format to convert to or -1 if none was found.
+ */
+enum AVPixelFormat avcodec_find_best_pix_fmt_of_list(const enum AVPixelFormat *pix_fmt_list,
+                                            enum AVPixelFormat src_pix_fmt,
+                                            int has_alpha, int *loss_ptr);
+
+/**
+ * Find the best pixel format to convert to given a certain source pixel
+ * format and a selection of two destination pixel formats. When converting from
+ * one pixel format to another, information loss may occur.  For example, when converting
+ * from RGB24 to GRAY, the color information will be lost. Similarly, other losses occur when
+ * converting from some formats to other formats. avcodec_find_best_pix_fmt_of_2() selects which of
+ * the given pixel formats should be used to suffer the least amount of loss.
+ *
+ * If one of the destination formats is AV_PIX_FMT_NONE the other pixel format (if valid) will be
+ * returned.
+ *
+ * @code
+ * src_pix_fmt = AV_PIX_FMT_YUV420P;
+ * dst_pix_fmt1= AV_PIX_FMT_RGB24;
+ * dst_pix_fmt2= AV_PIX_FMT_GRAY8;
+ * dst_pix_fmt3= AV_PIX_FMT_RGB8;
+ * loss= FF_LOSS_CHROMA; // don't care about chroma loss, so chroma loss will be ignored.
+ * dst_pix_fmt = avcodec_find_best_pix_fmt_of_2(dst_pix_fmt1, dst_pix_fmt2, src_pix_fmt, alpha, &loss);
+ * dst_pix_fmt = avcodec_find_best_pix_fmt_of_2(dst_pix_fmt, dst_pix_fmt3, src_pix_fmt, alpha, &loss);
+ * @endcode
+ *
+ * @param[in] dst_pix_fmt1 One of the two destination pixel formats to choose from
+ * @param[in] dst_pix_fmt2 The other of the two destination pixel formats to choose from
+ * @param[in] src_pix_fmt Source pixel format
+ * @param[in] has_alpha Whether the source pixel format alpha channel is used.
+ * @param[in, out] loss_ptr Combination of loss flags. In: selects which of the losses to ignore, i.e.
+ *                               NULL or value of zero means we care about all losses. Out: the loss
+ *                               that occurs when converting from src to selected dst pixel format.
+ * @return The best pixel format to convert to or -1 if none was found.
+ */
+enum AVPixelFormat avcodec_find_best_pix_fmt_of_2(enum AVPixelFormat dst_pix_fmt1, enum AVPixelFormat dst_pix_fmt2,
+                                            enum AVPixelFormat src_pix_fmt, int has_alpha, int *loss_ptr);
+
+attribute_deprecated
+#if AV_HAVE_INCOMPATIBLE_LIBAV_ABI
+enum AVPixelFormat avcodec_find_best_pix_fmt2(const enum AVPixelFormat *pix_fmt_list,
+                                              enum AVPixelFormat src_pix_fmt,
+                                              int has_alpha, int *loss_ptr);
+#else
+enum AVPixelFormat avcodec_find_best_pix_fmt2(enum AVPixelFormat dst_pix_fmt1, enum AVPixelFormat dst_pix_fmt2,
+                                            enum AVPixelFormat src_pix_fmt, int has_alpha, int *loss_ptr);
+#endif
+
+
+enum AVPixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum AVPixelFormat * fmt);
+
+/**
+ * @}
+ */
+
+void avcodec_set_dimensions(AVCodecContext *s, int width, int height);
+
+/**
+ * Put a string representing the codec tag codec_tag in buf.
+ *
+ * @param buf_size size in bytes of buf
+ * @return the length of the string that would have been generated if
+ * enough space had been available, excluding the trailing null
+ */
+size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_tag);
+
+void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode);
+
+/**
+ * Return a name for the specified profile, if available.
+ *
+ * @param codec the codec that is searched for the given profile
+ * @param profile the profile value for which a name is requested
+ * @return A name for the profile if found, NULL otherwise.
+ */
+const char *av_get_profile_name(const AVCodec *codec, int profile);
+
+int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size);
+int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int, int),void *arg, int *ret, int count);
+//FIXME func typedef
+
+/**
+ * Fill AVFrame audio data and linesize pointers.
+ *
+ * The buffer buf must be a preallocated buffer with a size big enough
+ * to contain the specified samples amount. The filled AVFrame data
+ * pointers will point to this buffer.
+ *
+ * AVFrame extended_data channel pointers are allocated if necessary for
+ * planar audio.
+ *
+ * @param frame       the AVFrame
+ *                    frame->nb_samples must be set prior to calling the
+ *                    function. This function fills in frame->data,
+ *                    frame->extended_data, frame->linesize[0].
+ * @param nb_channels channel count
+ * @param sample_fmt  sample format
+ * @param buf         buffer to use for frame data
+ * @param buf_size    size of buffer
+ * @param align       plane size sample alignment (0 = default)
+ * @return            >=0 on success, negative error code on failure
+ * @todo return the size in bytes required to store the samples in
+ * case of success, at the next libavutil bump
+ */
+int avcodec_fill_audio_frame(AVFrame *frame, int nb_channels,
+                             enum AVSampleFormat sample_fmt, const uint8_t *buf,
+                             int buf_size, int align);
+
+/**
+ * Reset the internal decoder state / flush internal buffers. Should be called
+ * e.g. when seeking or when switching to a different stream.
+ *
+ * @note when refcounted frames are not used (i.e. avctx->refcounted_frames is 0),
+ * this invalidates the frames previously returned from the decoder. When
+ * refcounted frames are used, the decoder just releases any references it might
+ * keep internally, but the caller's reference remains valid.
+ */
+void avcodec_flush_buffers(AVCodecContext *avctx);
+
+/**
+ * Return codec bits per sample.
+ *
+ * @param[in] codec_id the codec
+ * @return Number of bits per sample or zero if unknown for the given codec.
+ */
+int av_get_bits_per_sample(enum AVCodecID codec_id);
+
+/**
+ * Return the PCM codec associated with a sample format.
+ * @param be  endianness, 0 for little, 1 for big,
+ *            -1 (or anything else) for native
+ * @return  AV_CODEC_ID_PCM_* or AV_CODEC_ID_NONE
+ */
+enum AVCodecID av_get_pcm_codec(enum AVSampleFormat fmt, int be);
+
+/**
+ * Return codec bits per sample.
+ * Only return non-zero if the bits per sample is exactly correct, not an
+ * approximation.
+ *
+ * @param[in] codec_id the codec
+ * @return Number of bits per sample or zero if unknown for the given codec.
+ */
+int av_get_exact_bits_per_sample(enum AVCodecID codec_id);
+
+/**
+ * Return audio frame duration.
+ *
+ * @param avctx        codec context
+ * @param frame_bytes  size of the frame, or 0 if unknown
+ * @return             frame duration, in samples, if known. 0 if not able to
+ *                     determine.
+ */
+int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes);
+
+
+typedef struct AVBitStreamFilterContext {
+    void *priv_data;
+    struct AVBitStreamFilter *filter;
+    AVCodecParserContext *parser;
+    struct AVBitStreamFilterContext *next;
+} AVBitStreamFilterContext;
+
+
+typedef struct AVBitStreamFilter {
+    const char *name;
+    int priv_data_size;
+    int (*filter)(AVBitStreamFilterContext *bsfc,
+                  AVCodecContext *avctx, const char *args,
+                  uint8_t **poutbuf, int *poutbuf_size,
+                  const uint8_t *buf, int buf_size, int keyframe);
+    void (*close)(AVBitStreamFilterContext *bsfc);
+    struct AVBitStreamFilter *next;
+} AVBitStreamFilter;
+
+/**
+ * Register a bitstream filter.
+ *
+ * The filter will be accessible to the application code through
+ * av_bitstream_filter_next() or can be directly initialized with
+ * av_bitstream_filter_init().
+ *
+ * @see avcodec_register_all()
+ */
+void av_register_bitstream_filter(AVBitStreamFilter *bsf);
+
+/**
+ * Create and initialize a bitstream filter context given a bitstream
+ * filter name.
+ *
+ * The returned context must be freed with av_bitstream_filter_close().
+ *
+ * @param name    the name of the bitstream filter
+ * @return a bitstream filter context if a matching filter was found
+ * and successfully initialized, NULL otherwise
+ */
+AVBitStreamFilterContext *av_bitstream_filter_init(const char *name);
+
+/**
+ * Filter bitstream.
+ *
+ * This function filters the buffer buf with size buf_size, and places the
+ * filtered buffer in the buffer pointed to by poutbuf.
+ *
+ * The output buffer must be freed by the caller.
+ *
+ * @param bsfc            bitstream filter context created by av_bitstream_filter_init()
+ * @param avctx           AVCodecContext accessed by the filter, may be NULL.
+ *                        If specified, this must point to the encoder context of the
+ *                        output stream the packet is sent to.
+ * @param args            arguments which specify the filter configuration, may be NULL
+ * @param poutbuf         pointer which is updated to point to the filtered buffer
+ * @param poutbuf_size    pointer which is updated to the filtered buffer size in bytes
+ * @param buf             buffer containing the data to filter
+ * @param buf_size        size in bytes of buf
+ * @param keyframe        set to non-zero if the buffer to filter corresponds to a key-frame packet data
+ * @return >= 0 in case of success, or a negative error code in case of failure
+ *
+ * If the return value is positive, an output buffer is allocated and
+ * is availble in *poutbuf, and is distinct from the input buffer.
+ *
+ * If the return value is 0, the output buffer is not allocated and
+ * should be considered identical to the input buffer, or in case
+ * *poutbuf was set it points to the input buffer (not necessarily to
+ * its starting address).
+ */
+int av_bitstream_filter_filter(AVBitStreamFilterContext *bsfc,
+                               AVCodecContext *avctx, const char *args,
+                               uint8_t **poutbuf, int *poutbuf_size,
+                               const uint8_t *buf, int buf_size, int keyframe);
+
+/**
+ * Release bitstream filter context.
+ *
+ * @param bsf the bitstream filter context created with
+ * av_bitstream_filter_init(), can be NULL
+ */
+void av_bitstream_filter_close(AVBitStreamFilterContext *bsf);
+
+/**
+ * If f is NULL, return the first registered bitstream filter,
+ * if f is non-NULL, return the next registered bitstream filter
+ * after f, or NULL if f is the last one.
+ *
+ * This function can be used to iterate over all registered bitstream
+ * filters.
+ */
+AVBitStreamFilter *av_bitstream_filter_next(AVBitStreamFilter *f);
+
+/* memory */
+
+/**
+ * Reallocate the given block if it is not large enough, otherwise do nothing.
+ *
+ * @see av_realloc
+ */
+void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size);
+
+/**
+ * Allocate a buffer, reusing the given one if large enough.
+ *
+ * Contrary to av_fast_realloc the current buffer contents might not be
+ * preserved and on error the old buffer is freed, thus no special
+ * handling to avoid memleaks is necessary.
+ *
+ * @param ptr pointer to pointer to already allocated buffer, overwritten with pointer to new buffer
+ * @param size size of the buffer *ptr points to
+ * @param min_size minimum size of *ptr buffer after returning, *ptr will be NULL and
+ *                 *size 0 if an error occurred.
+ */
+void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size);
+
+/**
+ * Same behaviour av_fast_malloc but the buffer has additional
+ * FF_INPUT_BUFFER_PADDING_SIZE at the end which will always be 0.
+ *
+ * In addition the whole buffer will initially and after resizes
+ * be 0-initialized so that no uninitialized data will ever appear.
+ */
+void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size);
+
+/**
+ * Same behaviour av_fast_padded_malloc except that buffer will always
+ * be 0-initialized after call.
+ */
+void av_fast_padded_mallocz(void *ptr, unsigned int *size, size_t min_size);
+
+/**
+ * Encode extradata length to a buffer. Used by xiph codecs.
+ *
+ * @param s buffer to write to; must be at least (v/255+1) bytes long
+ * @param v size of extradata in bytes
+ * @return number of bytes written to the buffer.
+ */
+unsigned int av_xiphlacing(unsigned char *s, unsigned int v);
+
+#if FF_API_MISSING_SAMPLE
+/**
+ * Log a generic warning message about a missing feature. This function is
+ * intended to be used internally by FFmpeg (libavcodec, libavformat, etc.)
+ * only, and would normally not be used by applications.
+ * @param[in] avc a pointer to an arbitrary struct of which the first field is
+ * a pointer to an AVClass struct
+ * @param[in] feature string containing the name of the missing feature
+ * @param[in] want_sample indicates if samples are wanted which exhibit this feature.
+ * If want_sample is non-zero, additional verbage will be added to the log
+ * message which tells the user how to report samples to the development
+ * mailing list.
+ * @deprecated Use avpriv_report_missing_feature() instead.
+ */
+attribute_deprecated
+void av_log_missing_feature(void *avc, const char *feature, int want_sample);
+
+/**
+ * Log a generic warning message asking for a sample. This function is
+ * intended to be used internally by FFmpeg (libavcodec, libavformat, etc.)
+ * only, and would normally not be used by applications.
+ * @param[in] avc a pointer to an arbitrary struct of which the first field is
+ * a pointer to an AVClass struct
+ * @param[in] msg string containing an optional message, or NULL if no message
+ * @deprecated Use avpriv_request_sample() instead.
+ */
+attribute_deprecated
+void av_log_ask_for_sample(void *avc, const char *msg, ...) av_printf_format(2, 3);
+#endif /* FF_API_MISSING_SAMPLE */
+
+/**
+ * Register the hardware accelerator hwaccel.
+ */
+void av_register_hwaccel(AVHWAccel *hwaccel);
+
+/**
+ * If hwaccel is NULL, returns the first registered hardware accelerator,
+ * if hwaccel is non-NULL, returns the next registered hardware accelerator
+ * after hwaccel, or NULL if hwaccel is the last one.
+ */
+AVHWAccel *av_hwaccel_next(AVHWAccel *hwaccel);
+
+
+/**
+ * Lock operation used by lockmgr
+ */
+enum AVLockOp {
+  AV_LOCK_CREATE,  ///< Create a mutex
+  AV_LOCK_OBTAIN,  ///< Lock the mutex
+  AV_LOCK_RELEASE, ///< Unlock the mutex
+  AV_LOCK_DESTROY, ///< Free mutex resources
+};
+
+/**
+ * Register a user provided lock manager supporting the operations
+ * specified by AVLockOp. mutex points to a (void *) where the
+ * lockmgr should store/get a pointer to a user allocated mutex. It's
+ * NULL upon AV_LOCK_CREATE and != NULL for all other ops.
+ *
+ * @param cb User defined callback. Note: FFmpeg may invoke calls to this
+ *           callback during the call to av_lockmgr_register().
+ *           Thus, the application must be prepared to handle that.
+ *           If cb is set to NULL the lockmgr will be unregistered.
+ *           Also note that during unregistration the previously registered
+ *           lockmgr callback may also be invoked.
+ */
+int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op));
+
+/**
+ * Get the type of the given codec.
+ */
+enum AVMediaType avcodec_get_type(enum AVCodecID codec_id);
+
+/**
+ * Get the name of a codec.
+ * @return  a static string identifying the codec; never NULL
+ */
+const char *avcodec_get_name(enum AVCodecID id);
+
+/**
+ * @return a positive value if s is open (i.e. avcodec_open2() was called on it
+ * with no corresponding avcodec_close()), 0 otherwise.
+ */
+int avcodec_is_open(AVCodecContext *s);
+
+/**
+ * @return a non-zero number if codec is an encoder, zero otherwise
+ */
+int av_codec_is_encoder(const AVCodec *codec);
+
+/**
+ * @return a non-zero number if codec is a decoder, zero otherwise
+ */
+int av_codec_is_decoder(const AVCodec *codec);
+
+/**
+ * @return descriptor for given codec ID or NULL if no descriptor exists.
+ */
+const AVCodecDescriptor *avcodec_descriptor_get(enum AVCodecID id);
+
+/**
+ * Iterate over all codec descriptors known to libavcodec.
+ *
+ * @param prev previous descriptor. NULL to get the first descriptor.
+ *
+ * @return next descriptor or NULL after the last descriptor
+ */
+const AVCodecDescriptor *avcodec_descriptor_next(const AVCodecDescriptor *prev);
+
+/**
+ * @return codec descriptor with the given name or NULL if no such descriptor
+ *         exists.
+ */
+const AVCodecDescriptor *avcodec_descriptor_get_by_name(const char *name);
+
+/**
+ * @}
+ */
+
+#endif /* AVCODEC_AVCODEC_H */

+ 116 - 0
wave420l/code/ffmpeg/include/libavcodec/avfft.h

@@ -0,0 +1,116 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_AVFFT_H
+#define AVCODEC_AVFFT_H
+
+/**
+ * @file
+ * @ingroup lavc_fft
+ * FFT functions
+ */
+
+/**
+ * @defgroup lavc_fft FFT functions
+ * @ingroup lavc_misc
+ *
+ * @{
+ */
+
+typedef float FFTSample;
+
+typedef struct FFTComplex {
+    FFTSample re, im;
+} FFTComplex;
+
+typedef struct FFTContext FFTContext;
+
+/**
+ * Set up a complex FFT.
+ * @param nbits           log2 of the length of the input array
+ * @param inverse         if 0 perform the forward transform, if 1 perform the inverse
+ */
+FFTContext *av_fft_init(int nbits, int inverse);
+
+/**
+ * Do the permutation needed BEFORE calling ff_fft_calc().
+ */
+void av_fft_permute(FFTContext *s, FFTComplex *z);
+
+/**
+ * Do a complex FFT with the parameters defined in av_fft_init(). The
+ * input data must be permuted before. No 1.0/sqrt(n) normalization is done.
+ */
+void av_fft_calc(FFTContext *s, FFTComplex *z);
+
+void av_fft_end(FFTContext *s);
+
+FFTContext *av_mdct_init(int nbits, int inverse, double scale);
+void av_imdct_calc(FFTContext *s, FFTSample *output, const FFTSample *input);
+void av_imdct_half(FFTContext *s, FFTSample *output, const FFTSample *input);
+void av_mdct_calc(FFTContext *s, FFTSample *output, const FFTSample *input);
+void av_mdct_end(FFTContext *s);
+
+/* Real Discrete Fourier Transform */
+
+enum RDFTransformType {
+    DFT_R2C,
+    IDFT_C2R,
+    IDFT_R2C,
+    DFT_C2R,
+};
+
+typedef struct RDFTContext RDFTContext;
+
+/**
+ * Set up a real FFT.
+ * @param nbits           log2 of the length of the input array
+ * @param trans           the type of transform
+ */
+RDFTContext *av_rdft_init(int nbits, enum RDFTransformType trans);
+void av_rdft_calc(RDFTContext *s, FFTSample *data);
+void av_rdft_end(RDFTContext *s);
+
+/* Discrete Cosine Transform */
+
+typedef struct DCTContext DCTContext;
+
+enum DCTTransformType {
+    DCT_II = 0,
+    DCT_III,
+    DCT_I,
+    DST_I,
+};
+
+/**
+ * Set up DCT.
+ * @param nbits           size of the input array:
+ *                        (1 << nbits)     for DCT-II, DCT-III and DST-I
+ *                        (1 << nbits) + 1 for DCT-I
+ *
+ * @note the first element of the input of DST-I is ignored
+ */
+DCTContext *av_dct_init(int nbits, enum DCTTransformType type);
+void av_dct_calc(DCTContext *s, FFTSample *data);
+void av_dct_end (DCTContext *s);
+
+/**
+ * @}
+ */
+
+#endif /* AVCODEC_AVFFT_H */

+ 95 - 0
wave420l/code/ffmpeg/include/libavcodec/dxva2.h

@@ -0,0 +1,95 @@
+/*
+ * DXVA2 HW acceleration
+ *
+ * copyright (c) 2009 Laurent Aimar
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_DXVA_H
+#define AVCODEC_DXVA_H
+
+/**
+ * @file
+ * @ingroup lavc_codec_hwaccel_dxva2
+ * Public libavcodec DXVA2 header.
+ */
+
+#if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0600
+#undef _WIN32_WINNT
+#endif
+
+#if !defined(_WIN32_WINNT)
+#define _WIN32_WINNT 0x0600
+#endif
+
+#include <stdint.h>
+#include <d3d9.h>
+#include <dxva2api.h>
+
+/**
+ * @defgroup lavc_codec_hwaccel_dxva2 DXVA2
+ * @ingroup lavc_codec_hwaccel
+ *
+ * @{
+ */
+
+#define FF_DXVA2_WORKAROUND_SCALING_LIST_ZIGZAG 1 ///< Work around for DXVA2 and old UVD/UVD+ ATI video cards
+
+/**
+ * This structure is used to provides the necessary configurations and data
+ * to the DXVA2 FFmpeg HWAccel implementation.
+ *
+ * The application must make it available as AVCodecContext.hwaccel_context.
+ */
+struct dxva_context {
+    /**
+     * DXVA2 decoder object
+     */
+    IDirectXVideoDecoder *decoder;
+
+    /**
+     * DXVA2 configuration used to create the decoder
+     */
+    const DXVA2_ConfigPictureDecode *cfg;
+
+    /**
+     * The number of surface in the surface array
+     */
+    unsigned surface_count;
+
+    /**
+     * The array of Direct3D surfaces used to create the decoder
+     */
+    LPDIRECT3DSURFACE9 *surface;
+
+    /**
+     * A bit field configuring the workarounds needed for using the decoder
+     */
+    uint64_t workaround;
+
+    /**
+     * Private to the FFmpeg AVHWAccel implementation
+     */
+    unsigned report_id;
+};
+
+/**
+ * @}
+ */
+
+#endif /* AVCODEC_DXVA_H */

+ 397 - 0
wave420l/code/ffmpeg/include/libavcodec/old_codec_ids.h

@@ -0,0 +1,397 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_OLD_CODEC_IDS_H
+#define AVCODEC_OLD_CODEC_IDS_H
+
+#include "libavutil/common.h"
+
+/*
+ * This header exists to prevent new codec IDs from being accidentally added to
+ * the deprecated list.
+ * Do not include it directly. It will be removed on next major bump
+ *
+ * Do not add new items to this list. Use the AVCodecID enum instead.
+ */
+
+    CODEC_ID_NONE = AV_CODEC_ID_NONE,
+
+    /* video codecs */
+    CODEC_ID_MPEG1VIDEO,
+    CODEC_ID_MPEG2VIDEO, ///< preferred ID for MPEG-1/2 video decoding
+    CODEC_ID_MPEG2VIDEO_XVMC,
+    CODEC_ID_H261,
+    CODEC_ID_H263,
+    CODEC_ID_RV10,
+    CODEC_ID_RV20,
+    CODEC_ID_MJPEG,
+    CODEC_ID_MJPEGB,
+    CODEC_ID_LJPEG,
+    CODEC_ID_SP5X,
+    CODEC_ID_JPEGLS,
+    CODEC_ID_MPEG4,
+    CODEC_ID_RAWVIDEO,
+    CODEC_ID_MSMPEG4V1,
+    CODEC_ID_MSMPEG4V2,
+    CODEC_ID_MSMPEG4V3,
+    CODEC_ID_WMV1,
+    CODEC_ID_WMV2,
+    CODEC_ID_H263P,
+    CODEC_ID_H263I,
+    CODEC_ID_FLV1,
+    CODEC_ID_SVQ1,
+    CODEC_ID_SVQ3,
+    CODEC_ID_DVVIDEO,
+    CODEC_ID_HUFFYUV,
+    CODEC_ID_CYUV,
+    CODEC_ID_H264,
+    CODEC_ID_INDEO3,
+    CODEC_ID_VP3,
+    CODEC_ID_THEORA,
+    CODEC_ID_ASV1,
+    CODEC_ID_ASV2,
+    CODEC_ID_FFV1,
+    CODEC_ID_4XM,
+    CODEC_ID_VCR1,
+    CODEC_ID_CLJR,
+    CODEC_ID_MDEC,
+    CODEC_ID_ROQ,
+    CODEC_ID_INTERPLAY_VIDEO,
+    CODEC_ID_XAN_WC3,
+    CODEC_ID_XAN_WC4,
+    CODEC_ID_RPZA,
+    CODEC_ID_CINEPAK,
+    CODEC_ID_WS_VQA,
+    CODEC_ID_MSRLE,
+    CODEC_ID_MSVIDEO1,
+    CODEC_ID_IDCIN,
+    CODEC_ID_8BPS,
+    CODEC_ID_SMC,
+    CODEC_ID_FLIC,
+    CODEC_ID_TRUEMOTION1,
+    CODEC_ID_VMDVIDEO,
+    CODEC_ID_MSZH,
+    CODEC_ID_ZLIB,
+    CODEC_ID_QTRLE,
+    CODEC_ID_TSCC,
+    CODEC_ID_ULTI,
+    CODEC_ID_QDRAW,
+    CODEC_ID_VIXL,
+    CODEC_ID_QPEG,
+    CODEC_ID_PNG,
+    CODEC_ID_PPM,
+    CODEC_ID_PBM,
+    CODEC_ID_PGM,
+    CODEC_ID_PGMYUV,
+    CODEC_ID_PAM,
+    CODEC_ID_FFVHUFF,
+    CODEC_ID_RV30,
+    CODEC_ID_RV40,
+    CODEC_ID_VC1,
+    CODEC_ID_WMV3,
+    CODEC_ID_LOCO,
+    CODEC_ID_WNV1,
+    CODEC_ID_AASC,
+    CODEC_ID_INDEO2,
+    CODEC_ID_FRAPS,
+    CODEC_ID_TRUEMOTION2,
+    CODEC_ID_BMP,
+    CODEC_ID_CSCD,
+    CODEC_ID_MMVIDEO,
+    CODEC_ID_ZMBV,
+    CODEC_ID_AVS,
+    CODEC_ID_SMACKVIDEO,
+    CODEC_ID_NUV,
+    CODEC_ID_KMVC,
+    CODEC_ID_FLASHSV,
+    CODEC_ID_CAVS,
+    CODEC_ID_JPEG2000,
+    CODEC_ID_VMNC,
+    CODEC_ID_VP5,
+    CODEC_ID_VP6,
+    CODEC_ID_VP6F,
+    CODEC_ID_TARGA,
+    CODEC_ID_DSICINVIDEO,
+    CODEC_ID_TIERTEXSEQVIDEO,
+    CODEC_ID_TIFF,
+    CODEC_ID_GIF,
+    CODEC_ID_DXA,
+    CODEC_ID_DNXHD,
+    CODEC_ID_THP,
+    CODEC_ID_SGI,
+    CODEC_ID_C93,
+    CODEC_ID_BETHSOFTVID,
+    CODEC_ID_PTX,
+    CODEC_ID_TXD,
+    CODEC_ID_VP6A,
+    CODEC_ID_AMV,
+    CODEC_ID_VB,
+    CODEC_ID_PCX,
+    CODEC_ID_SUNRAST,
+    CODEC_ID_INDEO4,
+    CODEC_ID_INDEO5,
+    CODEC_ID_MIMIC,
+    CODEC_ID_RL2,
+    CODEC_ID_ESCAPE124,
+    CODEC_ID_DIRAC,
+    CODEC_ID_BFI,
+    CODEC_ID_CMV,
+    CODEC_ID_MOTIONPIXELS,
+    CODEC_ID_TGV,
+    CODEC_ID_TGQ,
+    CODEC_ID_TQI,
+    CODEC_ID_AURA,
+    CODEC_ID_AURA2,
+    CODEC_ID_V210X,
+    CODEC_ID_TMV,
+    CODEC_ID_V210,
+    CODEC_ID_DPX,
+    CODEC_ID_MAD,
+    CODEC_ID_FRWU,
+    CODEC_ID_FLASHSV2,
+    CODEC_ID_CDGRAPHICS,
+    CODEC_ID_R210,
+    CODEC_ID_ANM,
+    CODEC_ID_BINKVIDEO,
+    CODEC_ID_IFF_ILBM,
+    CODEC_ID_IFF_BYTERUN1,
+    CODEC_ID_KGV1,
+    CODEC_ID_YOP,
+    CODEC_ID_VP8,
+    CODEC_ID_PICTOR,
+    CODEC_ID_ANSI,
+    CODEC_ID_A64_MULTI,
+    CODEC_ID_A64_MULTI5,
+    CODEC_ID_R10K,
+    CODEC_ID_MXPEG,
+    CODEC_ID_LAGARITH,
+    CODEC_ID_PRORES,
+    CODEC_ID_JV,
+    CODEC_ID_DFA,
+    CODEC_ID_WMV3IMAGE,
+    CODEC_ID_VC1IMAGE,
+    CODEC_ID_UTVIDEO,
+    CODEC_ID_BMV_VIDEO,
+    CODEC_ID_VBLE,
+    CODEC_ID_DXTORY,
+    CODEC_ID_V410,
+    CODEC_ID_XWD,
+    CODEC_ID_CDXL,
+    CODEC_ID_XBM,
+    CODEC_ID_ZEROCODEC,
+    CODEC_ID_MSS1,
+    CODEC_ID_MSA1,
+    CODEC_ID_TSCC2,
+    CODEC_ID_MTS2,
+    CODEC_ID_CLLC,
+    CODEC_ID_Y41P       = MKBETAG('Y','4','1','P'),
+    CODEC_ID_ESCAPE130  = MKBETAG('E','1','3','0'),
+    CODEC_ID_EXR        = MKBETAG('0','E','X','R'),
+    CODEC_ID_AVRP       = MKBETAG('A','V','R','P'),
+
+    CODEC_ID_G2M        = MKBETAG( 0 ,'G','2','M'),
+    CODEC_ID_AVUI       = MKBETAG('A','V','U','I'),
+    CODEC_ID_AYUV       = MKBETAG('A','Y','U','V'),
+    CODEC_ID_V308       = MKBETAG('V','3','0','8'),
+    CODEC_ID_V408       = MKBETAG('V','4','0','8'),
+    CODEC_ID_YUV4       = MKBETAG('Y','U','V','4'),
+    CODEC_ID_SANM       = MKBETAG('S','A','N','M'),
+    CODEC_ID_PAF_VIDEO  = MKBETAG('P','A','F','V'),
+    CODEC_ID_SNOW       = AV_CODEC_ID_SNOW,
+
+    /* various PCM "codecs" */
+    CODEC_ID_FIRST_AUDIO = 0x10000,     ///< A dummy id pointing at the start of audio codecs
+    CODEC_ID_PCM_S16LE = 0x10000,
+    CODEC_ID_PCM_S16BE,
+    CODEC_ID_PCM_U16LE,
+    CODEC_ID_PCM_U16BE,
+    CODEC_ID_PCM_S8,
+    CODEC_ID_PCM_U8,
+    CODEC_ID_PCM_MULAW,
+    CODEC_ID_PCM_ALAW,
+    CODEC_ID_PCM_S32LE,
+    CODEC_ID_PCM_S32BE,
+    CODEC_ID_PCM_U32LE,
+    CODEC_ID_PCM_U32BE,
+    CODEC_ID_PCM_S24LE,
+    CODEC_ID_PCM_S24BE,
+    CODEC_ID_PCM_U24LE,
+    CODEC_ID_PCM_U24BE,
+    CODEC_ID_PCM_S24DAUD,
+    CODEC_ID_PCM_ZORK,
+    CODEC_ID_PCM_S16LE_PLANAR,
+    CODEC_ID_PCM_DVD,
+    CODEC_ID_PCM_F32BE,
+    CODEC_ID_PCM_F32LE,
+    CODEC_ID_PCM_F64BE,
+    CODEC_ID_PCM_F64LE,
+    CODEC_ID_PCM_BLURAY,
+    CODEC_ID_PCM_LXF,
+    CODEC_ID_S302M,
+    CODEC_ID_PCM_S8_PLANAR,
+
+    /* various ADPCM codecs */
+    CODEC_ID_ADPCM_IMA_QT = 0x11000,
+    CODEC_ID_ADPCM_IMA_WAV,
+    CODEC_ID_ADPCM_IMA_DK3,
+    CODEC_ID_ADPCM_IMA_DK4,
+    CODEC_ID_ADPCM_IMA_WS,
+    CODEC_ID_ADPCM_IMA_SMJPEG,
+    CODEC_ID_ADPCM_MS,
+    CODEC_ID_ADPCM_4XM,
+    CODEC_ID_ADPCM_XA,
+    CODEC_ID_ADPCM_ADX,
+    CODEC_ID_ADPCM_EA,
+    CODEC_ID_ADPCM_G726,
+    CODEC_ID_ADPCM_CT,
+    CODEC_ID_ADPCM_SWF,
+    CODEC_ID_ADPCM_YAMAHA,
+    CODEC_ID_ADPCM_SBPRO_4,
+    CODEC_ID_ADPCM_SBPRO_3,
+    CODEC_ID_ADPCM_SBPRO_2,
+    CODEC_ID_ADPCM_THP,
+    CODEC_ID_ADPCM_IMA_AMV,
+    CODEC_ID_ADPCM_EA_R1,
+    CODEC_ID_ADPCM_EA_R3,
+    CODEC_ID_ADPCM_EA_R2,
+    CODEC_ID_ADPCM_IMA_EA_SEAD,
+    CODEC_ID_ADPCM_IMA_EA_EACS,
+    CODEC_ID_ADPCM_EA_XAS,
+    CODEC_ID_ADPCM_EA_MAXIS_XA,
+    CODEC_ID_ADPCM_IMA_ISS,
+    CODEC_ID_ADPCM_G722,
+    CODEC_ID_ADPCM_IMA_APC,
+    CODEC_ID_VIMA       = MKBETAG('V','I','M','A'),
+
+    /* AMR */
+    CODEC_ID_AMR_NB = 0x12000,
+    CODEC_ID_AMR_WB,
+
+    /* RealAudio codecs*/
+    CODEC_ID_RA_144 = 0x13000,
+    CODEC_ID_RA_288,
+
+    /* various DPCM codecs */
+    CODEC_ID_ROQ_DPCM = 0x14000,
+    CODEC_ID_INTERPLAY_DPCM,
+    CODEC_ID_XAN_DPCM,
+    CODEC_ID_SOL_DPCM,
+
+    /* audio codecs */
+    CODEC_ID_MP2 = 0x15000,
+    CODEC_ID_MP3, ///< preferred ID for decoding MPEG audio layer 1, 2 or 3
+    CODEC_ID_AAC,
+    CODEC_ID_AC3,
+    CODEC_ID_DTS,
+    CODEC_ID_VORBIS,
+    CODEC_ID_DVAUDIO,
+    CODEC_ID_WMAV1,
+    CODEC_ID_WMAV2,
+    CODEC_ID_MACE3,
+    CODEC_ID_MACE6,
+    CODEC_ID_VMDAUDIO,
+    CODEC_ID_FLAC,
+    CODEC_ID_MP3ADU,
+    CODEC_ID_MP3ON4,
+    CODEC_ID_SHORTEN,
+    CODEC_ID_ALAC,
+    CODEC_ID_WESTWOOD_SND1,
+    CODEC_ID_GSM, ///< as in Berlin toast format
+    CODEC_ID_QDM2,
+    CODEC_ID_COOK,
+    CODEC_ID_TRUESPEECH,
+    CODEC_ID_TTA,
+    CODEC_ID_SMACKAUDIO,
+    CODEC_ID_QCELP,
+    CODEC_ID_WAVPACK,
+    CODEC_ID_DSICINAUDIO,
+    CODEC_ID_IMC,
+    CODEC_ID_MUSEPACK7,
+    CODEC_ID_MLP,
+    CODEC_ID_GSM_MS, /* as found in WAV */
+    CODEC_ID_ATRAC3,
+    CODEC_ID_VOXWARE,
+    CODEC_ID_APE,
+    CODEC_ID_NELLYMOSER,
+    CODEC_ID_MUSEPACK8,
+    CODEC_ID_SPEEX,
+    CODEC_ID_WMAVOICE,
+    CODEC_ID_WMAPRO,
+    CODEC_ID_WMALOSSLESS,
+    CODEC_ID_ATRAC3P,
+    CODEC_ID_EAC3,
+    CODEC_ID_SIPR,
+    CODEC_ID_MP1,
+    CODEC_ID_TWINVQ,
+    CODEC_ID_TRUEHD,
+    CODEC_ID_MP4ALS,
+    CODEC_ID_ATRAC1,
+    CODEC_ID_BINKAUDIO_RDFT,
+    CODEC_ID_BINKAUDIO_DCT,
+    CODEC_ID_AAC_LATM,
+    CODEC_ID_QDMC,
+    CODEC_ID_CELT,
+    CODEC_ID_G723_1,
+    CODEC_ID_G729,
+    CODEC_ID_8SVX_EXP,
+    CODEC_ID_8SVX_FIB,
+    CODEC_ID_BMV_AUDIO,
+    CODEC_ID_RALF,
+    CODEC_ID_IAC,
+    CODEC_ID_ILBC,
+    CODEC_ID_FFWAVESYNTH = MKBETAG('F','F','W','S'),
+    CODEC_ID_SONIC       = MKBETAG('S','O','N','C'),
+    CODEC_ID_SONIC_LS    = MKBETAG('S','O','N','L'),
+    CODEC_ID_PAF_AUDIO   = MKBETAG('P','A','F','A'),
+    CODEC_ID_OPUS        = MKBETAG('O','P','U','S'),
+
+    /* subtitle codecs */
+    CODEC_ID_FIRST_SUBTITLE = 0x17000,          ///< A dummy ID pointing at the start of subtitle codecs.
+    CODEC_ID_DVD_SUBTITLE = 0x17000,
+    CODEC_ID_DVB_SUBTITLE,
+    CODEC_ID_TEXT,  ///< raw UTF-8 text
+    CODEC_ID_XSUB,
+    CODEC_ID_SSA,
+    CODEC_ID_MOV_TEXT,
+    CODEC_ID_HDMV_PGS_SUBTITLE,
+    CODEC_ID_DVB_TELETEXT,
+    CODEC_ID_SRT,
+    CODEC_ID_MICRODVD   = MKBETAG('m','D','V','D'),
+    CODEC_ID_EIA_608    = MKBETAG('c','6','0','8'),
+    CODEC_ID_JACOSUB    = MKBETAG('J','S','U','B'),
+    CODEC_ID_SAMI       = MKBETAG('S','A','M','I'),
+    CODEC_ID_REALTEXT   = MKBETAG('R','T','X','T'),
+    CODEC_ID_SUBVIEWER  = MKBETAG('S','u','b','V'),
+
+    /* other specific kind of codecs (generally used for attachments) */
+    CODEC_ID_FIRST_UNKNOWN = 0x18000,           ///< A dummy ID pointing at the start of various fake codecs.
+    CODEC_ID_TTF = 0x18000,
+    CODEC_ID_BINTEXT    = MKBETAG('B','T','X','T'),
+    CODEC_ID_XBIN       = MKBETAG('X','B','I','N'),
+    CODEC_ID_IDF        = MKBETAG( 0 ,'I','D','F'),
+    CODEC_ID_OTF        = MKBETAG( 0 ,'O','T','F'),
+
+    CODEC_ID_PROBE = 0x19000, ///< codec_id is not known (like CODEC_ID_NONE) but lavf should attempt to identify it
+
+    CODEC_ID_MPEG2TS = 0x20000, /**< _FAKE_ codec to indicate a raw MPEG-2 TS
+                                * stream (only used by libavformat) */
+    CODEC_ID_MPEG4SYSTEMS = 0x20001, /**< _FAKE_ codec to indicate a MPEG-4 Systems
+                                * stream (only used by libavformat) */
+    CODEC_ID_FFMETADATA = 0x21000,   ///< Dummy codec for streams containing only metadata information.
+
+#endif /* AVCODEC_OLD_CODEC_IDS_H */

+ 173 - 0
wave420l/code/ffmpeg/include/libavcodec/vaapi.h

@@ -0,0 +1,173 @@
+/*
+ * Video Acceleration API (shared data between FFmpeg and the video player)
+ * HW decode acceleration for MPEG-2, MPEG-4, H.264 and VC-1
+ *
+ * Copyright (C) 2008-2009 Splitted-Desktop Systems
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_VAAPI_H
+#define AVCODEC_VAAPI_H
+
+/**
+ * @file
+ * @ingroup lavc_codec_hwaccel_vaapi
+ * Public libavcodec VA API header.
+ */
+
+#include <stdint.h>
+
+/**
+ * @defgroup lavc_codec_hwaccel_vaapi VA API Decoding
+ * @ingroup lavc_codec_hwaccel
+ * @{
+ */
+
+/**
+ * This structure is used to share data between the FFmpeg library and
+ * the client video application.
+ * This shall be zero-allocated and available as
+ * AVCodecContext.hwaccel_context. All user members can be set once
+ * during initialization or through each AVCodecContext.get_buffer()
+ * function call. In any case, they must be valid prior to calling
+ * decoding functions.
+ */
+struct vaapi_context {
+    /**
+     * Window system dependent data
+     *
+     * - encoding: unused
+     * - decoding: Set by user
+     */
+    void *display;
+
+    /**
+     * Configuration ID
+     *
+     * - encoding: unused
+     * - decoding: Set by user
+     */
+    uint32_t config_id;
+
+    /**
+     * Context ID (video decode pipeline)
+     *
+     * - encoding: unused
+     * - decoding: Set by user
+     */
+    uint32_t context_id;
+
+    /**
+     * VAPictureParameterBuffer ID
+     *
+     * - encoding: unused
+     * - decoding: Set by libavcodec
+     */
+    uint32_t pic_param_buf_id;
+
+    /**
+     * VAIQMatrixBuffer ID
+     *
+     * - encoding: unused
+     * - decoding: Set by libavcodec
+     */
+    uint32_t iq_matrix_buf_id;
+
+    /**
+     * VABitPlaneBuffer ID (for VC-1 decoding)
+     *
+     * - encoding: unused
+     * - decoding: Set by libavcodec
+     */
+    uint32_t bitplane_buf_id;
+
+    /**
+     * Slice parameter/data buffer IDs
+     *
+     * - encoding: unused
+     * - decoding: Set by libavcodec
+     */
+    uint32_t *slice_buf_ids;
+
+    /**
+     * Number of effective slice buffer IDs to send to the HW
+     *
+     * - encoding: unused
+     * - decoding: Set by libavcodec
+     */
+    unsigned int n_slice_buf_ids;
+
+    /**
+     * Size of pre-allocated slice_buf_ids
+     *
+     * - encoding: unused
+     * - decoding: Set by libavcodec
+     */
+    unsigned int slice_buf_ids_alloc;
+
+    /**
+     * Pointer to VASliceParameterBuffers
+     *
+     * - encoding: unused
+     * - decoding: Set by libavcodec
+     */
+    void *slice_params;
+
+    /**
+     * Size of a VASliceParameterBuffer element
+     *
+     * - encoding: unused
+     * - decoding: Set by libavcodec
+     */
+    unsigned int slice_param_size;
+
+    /**
+     * Size of pre-allocated slice_params
+     *
+     * - encoding: unused
+     * - decoding: Set by libavcodec
+     */
+    unsigned int slice_params_alloc;
+
+    /**
+     * Number of slices currently filled in
+     *
+     * - encoding: unused
+     * - decoding: Set by libavcodec
+     */
+    unsigned int slice_count;
+
+    /**
+     * Pointer to slice data buffer base
+     * - encoding: unused
+     * - decoding: Set by libavcodec
+     */
+    const uint8_t *slice_data;
+
+    /**
+     * Current size of slice data
+     *
+     * - encoding: unused
+     * - decoding: Set by libavcodec
+     */
+    uint32_t slice_data_size;
+};
+
+/* @} */
+
+#endif /* AVCODEC_VAAPI_H */

+ 162 - 0
wave420l/code/ffmpeg/include/libavcodec/vda.h

@@ -0,0 +1,162 @@
+/*
+ * VDA HW acceleration
+ *
+ * copyright (c) 2011 Sebastien Zwickert
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_VDA_H
+#define AVCODEC_VDA_H
+
+/**
+ * @file
+ * @ingroup lavc_codec_hwaccel_vda
+ * Public libavcodec VDA header.
+ */
+
+#include <stdint.h>
+
+// emmintrin.h is unable to compile with -std=c99 -Werror=missing-prototypes
+// http://openradar.appspot.com/8026390
+#undef __GNUC_STDC_INLINE__
+
+#define Picture QuickdrawPicture
+#include <VideoDecodeAcceleration/VDADecoder.h>
+#undef Picture
+
+#include "libavcodec/version.h"
+
+/**
+ * @defgroup lavc_codec_hwaccel_vda VDA
+ * @ingroup lavc_codec_hwaccel
+ *
+ * @{
+ */
+
+/**
+ * This structure is used to provide the necessary configurations and data
+ * to the VDA FFmpeg HWAccel implementation.
+ *
+ * The application must make it available as AVCodecContext.hwaccel_context.
+ */
+struct vda_context {
+    /**
+     * VDA decoder object.
+     *
+     * - encoding: unused
+     * - decoding: Set/Unset by libavcodec.
+     */
+    VDADecoder          decoder;
+
+    /**
+     * The Core Video pixel buffer that contains the current image data.
+     *
+     * encoding: unused
+     * decoding: Set by libavcodec. Unset by user.
+     */
+    CVPixelBufferRef    cv_buffer;
+
+    /**
+     * Use the hardware decoder in synchronous mode.
+     *
+     * encoding: unused
+     * decoding: Set by user.
+     */
+    int                 use_sync_decoding;
+
+    /**
+     * The frame width.
+     *
+     * - encoding: unused
+     * - decoding: Set/Unset by user.
+     */
+    int                 width;
+
+    /**
+     * The frame height.
+     *
+     * - encoding: unused
+     * - decoding: Set/Unset by user.
+     */
+    int                 height;
+
+    /**
+     * The frame format.
+     *
+     * - encoding: unused
+     * - decoding: Set/Unset by user.
+     */
+    int                 format;
+
+    /**
+     * The pixel format for output image buffers.
+     *
+     * - encoding: unused
+     * - decoding: Set/Unset by user.
+     */
+    OSType              cv_pix_fmt_type;
+
+    /**
+     * The current bitstream buffer.
+     *
+     * - encoding: unused
+     * - decoding: Set/Unset by libavcodec.
+     */
+    uint8_t             *priv_bitstream;
+
+    /**
+     * The current size of the bitstream.
+     *
+     * - encoding: unused
+     * - decoding: Set/Unset by libavcodec.
+     */
+    int                 priv_bitstream_size;
+
+    /**
+     * The reference size used for fast reallocation.
+     *
+     * - encoding: unused
+     * - decoding: Set/Unset by libavcodec.
+     */
+    int                 priv_allocated_size;
+
+    /**
+     * Use av_buffer to manage buffer.
+     * When the flag is set, the CVPixelBuffers returned by the decoder will
+     * be released automatically, so you have to retain them if necessary.
+     * Not setting this flag may cause memory leak.
+     *
+     * encoding: unused
+     * decoding: Set by user.
+     */
+    int                 use_ref_buffer;
+};
+
+/** Create the video decoder. */
+int ff_vda_create_decoder(struct vda_context *vda_ctx,
+                          uint8_t *extradata,
+                          int extradata_size);
+
+/** Destroy the video decoder. */
+int ff_vda_destroy_decoder(struct vda_context *vda_ctx);
+
+/**
+ * @}
+ */
+
+#endif /* AVCODEC_VDA_H */

+ 195 - 0
wave420l/code/ffmpeg/include/libavcodec/vdpau.h

@@ -0,0 +1,195 @@
+/*
+ * The Video Decode and Presentation API for UNIX (VDPAU) is used for
+ * hardware-accelerated decoding of MPEG-1/2, H.264 and VC-1.
+ *
+ * Copyright (C) 2008 NVIDIA
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_VDPAU_H
+#define AVCODEC_VDPAU_H
+
+/**
+ * @file
+ * @ingroup lavc_codec_hwaccel_vdpau
+ * Public libavcodec VDPAU header.
+ */
+
+
+/**
+ * @defgroup lavc_codec_hwaccel_vdpau VDPAU Decoder and Renderer
+ * @ingroup lavc_codec_hwaccel
+ *
+ * VDPAU hardware acceleration has two modules
+ * - VDPAU decoding
+ * - VDPAU presentation
+ *
+ * The VDPAU decoding module parses all headers using FFmpeg
+ * parsing mechanisms and uses VDPAU for the actual decoding.
+ *
+ * As per the current implementation, the actual decoding
+ * and rendering (API calls) are done as part of the VDPAU
+ * presentation (vo_vdpau.c) module.
+ *
+ * @{
+ */
+
+#include <vdpau/vdpau.h>
+#include <vdpau/vdpau_x11.h>
+#include "libavutil/avconfig.h"
+#include "libavutil/attributes.h"
+
+#ifndef FF_API_CAP_VDPAU
+#define FF_API_CAP_VDPAU 1
+#endif
+#ifndef FF_API_BUFS_VDPAU
+#define FF_API_BUFS_VDPAU 1
+#endif
+
+#if FF_API_BUFS_VDPAU
+union AVVDPAUPictureInfo {
+    VdpPictureInfoH264        h264;
+    VdpPictureInfoMPEG1Or2    mpeg;
+    VdpPictureInfoVC1          vc1;
+    VdpPictureInfoMPEG4Part2 mpeg4;
+};
+#endif
+
+struct AVCodecContext;
+struct AVFrame;
+
+typedef int (*AVVDPAU_Render2)(struct AVCodecContext *, struct AVFrame *,
+                               const VdpPictureInfo *, uint32_t,
+                               const VdpBitstreamBuffer *);
+
+/**
+ * This structure is used to share data between the libavcodec library and
+ * the client video application.
+ * The user shall allocate the structure via the av_alloc_vdpau_hwaccel
+ * function and make it available as
+ * AVCodecContext.hwaccel_context. Members can be set by the user once
+ * during initialization or through each AVCodecContext.get_buffer()
+ * function call. In any case, they must be valid prior to calling
+ * decoding functions.
+ */
+typedef struct AVVDPAUContext {
+    /**
+     * VDPAU decoder handle
+     *
+     * Set by user.
+     */
+    VdpDecoder decoder;
+
+    /**
+     * VDPAU decoder render callback
+     *
+     * Set by the user.
+     */
+    VdpDecoderRender *render;
+
+#if FF_API_BUFS_VDPAU
+    /**
+     * VDPAU picture information
+     *
+     * Set by libavcodec.
+     */
+    attribute_deprecated
+    union AVVDPAUPictureInfo info;
+
+    /**
+     * Allocated size of the bitstream_buffers table.
+     *
+     * Set by libavcodec.
+     */
+    attribute_deprecated
+    int bitstream_buffers_allocated;
+
+    /**
+     * Useful bitstream buffers in the bitstream buffers table.
+     *
+     * Set by libavcodec.
+     */
+    attribute_deprecated
+    int bitstream_buffers_used;
+
+   /**
+     * Table of bitstream buffers.
+     * The user is responsible for freeing this buffer using av_freep().
+     *
+     * Set by libavcodec.
+     */
+    attribute_deprecated
+    VdpBitstreamBuffer *bitstream_buffers;
+#endif
+    AVVDPAU_Render2 render2;
+} AVVDPAUContext;
+
+/**
+ * @brief allocation function for AVVDPAUContext
+ *
+ * Allows extending the struct without breaking API/ABI
+ */
+AVVDPAUContext *av_alloc_vdpaucontext(void);
+
+AVVDPAU_Render2 av_vdpau_hwaccel_get_render2(const AVVDPAUContext *);
+void av_vdpau_hwaccel_set_render2(AVVDPAUContext *, AVVDPAU_Render2);
+
+#if FF_API_CAP_VDPAU
+/** @brief The videoSurface is used for rendering. */
+#define FF_VDPAU_STATE_USED_FOR_RENDER 1
+
+/**
+ * @brief The videoSurface is needed for reference/prediction.
+ * The codec manipulates this.
+ */
+#define FF_VDPAU_STATE_USED_FOR_REFERENCE 2
+
+/**
+ * @brief This structure is used as a callback between the FFmpeg
+ * decoder (vd_) and presentation (vo_) module.
+ * This is used for defining a video frame containing surface,
+ * picture parameter, bitstream information etc which are passed
+ * between the FFmpeg decoder and its clients.
+ */
+struct vdpau_render_state {
+    VdpVideoSurface surface; ///< Used as rendered surface, never changed.
+
+    int state; ///< Holds FF_VDPAU_STATE_* values.
+
+#if AV_HAVE_INCOMPATIBLE_LIBAV_ABI
+    /** picture parameter information for all supported codecs */
+    union AVVDPAUPictureInfo info;
+#endif
+
+    /** Describe size/location of the compressed video data.
+        Set to 0 when freeing bitstream_buffers. */
+    int bitstream_buffers_allocated;
+    int bitstream_buffers_used;
+    /** The user is responsible for freeing this buffer using av_freep(). */
+    VdpBitstreamBuffer *bitstream_buffers;
+
+#if !AV_HAVE_INCOMPATIBLE_LIBAV_ABI
+    /** picture parameter information for all supported codecs */
+    union AVVDPAUPictureInfo info;
+#endif
+};
+#endif
+
+/* @}*/
+
+#endif /* AVCODEC_VDPAU_H */

+ 104 - 0
wave420l/code/ffmpeg/include/libavcodec/version.h

@@ -0,0 +1,104 @@
+/*
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_VERSION_H
+#define AVCODEC_VERSION_H
+
+/**
+ * @file
+ * @ingroup libavc
+ * Libavcodec version macros.
+ */
+
+#include "libavutil/avutil.h"
+
+#define LIBAVCODEC_VERSION_MAJOR 55
+#define LIBAVCODEC_VERSION_MINOR  39
+#define LIBAVCODEC_VERSION_MICRO 101
+
+#define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
+                                               LIBAVCODEC_VERSION_MINOR, \
+                                               LIBAVCODEC_VERSION_MICRO)
+#define LIBAVCODEC_VERSION      AV_VERSION(LIBAVCODEC_VERSION_MAJOR,    \
+                                           LIBAVCODEC_VERSION_MINOR,    \
+                                           LIBAVCODEC_VERSION_MICRO)
+#define LIBAVCODEC_BUILD        LIBAVCODEC_VERSION_INT
+
+#define LIBAVCODEC_IDENT        "Lavc" AV_STRINGIFY(LIBAVCODEC_VERSION)
+
+/**
+ * FF_API_* defines may be placed below to indicate public API that will be
+ * dropped at a future version bump. The defines themselves are not part of
+ * the public API and may change, break or disappear at any time.
+ */
+
+#ifndef FF_API_REQUEST_CHANNELS
+#define FF_API_REQUEST_CHANNELS (LIBAVCODEC_VERSION_MAJOR < 56)
+#endif
+#ifndef FF_API_ALLOC_CONTEXT
+#define FF_API_ALLOC_CONTEXT    (LIBAVCODEC_VERSION_MAJOR < 55)
+#endif
+#ifndef FF_API_AVCODEC_OPEN
+#define FF_API_AVCODEC_OPEN     (LIBAVCODEC_VERSION_MAJOR < 55)
+#endif
+#ifndef FF_API_OLD_DECODE_AUDIO
+#define FF_API_OLD_DECODE_AUDIO (LIBAVCODEC_VERSION_MAJOR < 56)
+#endif
+#ifndef FF_API_OLD_TIMECODE
+#define FF_API_OLD_TIMECODE (LIBAVCODEC_VERSION_MAJOR < 55)
+#endif
+
+#ifndef FF_API_OLD_ENCODE_AUDIO
+#define FF_API_OLD_ENCODE_AUDIO (LIBAVCODEC_VERSION_MAJOR < 56)
+#endif
+#ifndef FF_API_OLD_ENCODE_VIDEO
+#define FF_API_OLD_ENCODE_VIDEO (LIBAVCODEC_VERSION_MAJOR < 56)
+#endif
+#ifndef FF_API_CODEC_ID
+#define FF_API_CODEC_ID          (LIBAVCODEC_VERSION_MAJOR < 56)
+#endif
+#ifndef FF_API_AVCODEC_RESAMPLE
+#define FF_API_AVCODEC_RESAMPLE  (LIBAVCODEC_VERSION_MAJOR < 56)
+#endif
+#ifndef FF_API_DEINTERLACE
+#define FF_API_DEINTERLACE       (LIBAVCODEC_VERSION_MAJOR < 56)
+#endif
+#ifndef FF_API_DESTRUCT_PACKET
+#define FF_API_DESTRUCT_PACKET   (LIBAVCODEC_VERSION_MAJOR < 56)
+#endif
+#ifndef FF_API_GET_BUFFER
+#define FF_API_GET_BUFFER        (LIBAVCODEC_VERSION_MAJOR < 56)
+#endif
+#ifndef FF_API_MISSING_SAMPLE
+#define FF_API_MISSING_SAMPLE    (LIBAVCODEC_VERSION_MAJOR < 56)
+#endif
+#ifndef FF_API_LOWRES
+#define FF_API_LOWRES            (LIBAVCODEC_VERSION_MAJOR < 56)
+#endif
+#ifndef FF_API_CAP_VDPAU
+#define FF_API_CAP_VDPAU         (LIBAVCODEC_VERSION_MAJOR < 56)
+#endif
+#ifndef FF_API_BUFS_VDPAU
+#define FF_API_BUFS_VDPAU        (LIBAVCODEC_VERSION_MAJOR < 56)
+#endif
+#ifndef FF_API_VOXWARE
+#define FF_API_VOXWARE           (LIBAVCODEC_VERSION_MAJOR < 56)
+#endif
+
+#endif /* AVCODEC_VERSION_H */

+ 168 - 0
wave420l/code/ffmpeg/include/libavcodec/xvmc.h

@@ -0,0 +1,168 @@
+/*
+ * Copyright (C) 2003 Ivan Kalvachev
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_XVMC_H
+#define AVCODEC_XVMC_H
+
+/**
+ * @file
+ * @ingroup lavc_codec_hwaccel_xvmc
+ * Public libavcodec XvMC header.
+ */
+
+#include <X11/extensions/XvMC.h>
+
+#include "avcodec.h"
+
+/**
+ * @defgroup lavc_codec_hwaccel_xvmc XvMC
+ * @ingroup lavc_codec_hwaccel
+ *
+ * @{
+ */
+
+#define AV_XVMC_ID                    0x1DC711C0  /**< special value to ensure that regular pixel routines haven't corrupted the struct
+                                                       the number is 1337 speak for the letters IDCT MCo (motion compensation) */
+
+struct xvmc_pix_fmt {
+    /** The field contains the special constant value AV_XVMC_ID.
+        It is used as a test that the application correctly uses the API,
+        and that there is no corruption caused by pixel routines.
+        - application - set during initialization
+        - libavcodec  - unchanged
+    */
+    int             xvmc_id;
+
+    /** Pointer to the block array allocated by XvMCCreateBlocks().
+        The array has to be freed by XvMCDestroyBlocks().
+        Each group of 64 values represents one data block of differential
+        pixel information (in MoCo mode) or coefficients for IDCT.
+        - application - set the pointer during initialization
+        - libavcodec  - fills coefficients/pixel data into the array
+    */
+    short*          data_blocks;
+
+    /** Pointer to the macroblock description array allocated by
+        XvMCCreateMacroBlocks() and freed by XvMCDestroyMacroBlocks().
+        - application - set the pointer during initialization
+        - libavcodec  - fills description data into the array
+    */
+    XvMCMacroBlock* mv_blocks;
+
+    /** Number of macroblock descriptions that can be stored in the mv_blocks
+        array.
+        - application - set during initialization
+        - libavcodec  - unchanged
+    */
+    int             allocated_mv_blocks;
+
+    /** Number of blocks that can be stored at once in the data_blocks array.
+        - application - set during initialization
+        - libavcodec  - unchanged
+    */
+    int             allocated_data_blocks;
+
+    /** Indicate that the hardware would interpret data_blocks as IDCT
+        coefficients and perform IDCT on them.
+        - application - set during initialization
+        - libavcodec  - unchanged
+    */
+    int             idct;
+
+    /** In MoCo mode it indicates that intra macroblocks are assumed to be in
+        unsigned format; same as the XVMC_INTRA_UNSIGNED flag.
+        - application - set during initialization
+        - libavcodec  - unchanged
+    */
+    int             unsigned_intra;
+
+    /** Pointer to the surface allocated by XvMCCreateSurface().
+        It has to be freed by XvMCDestroySurface() on application exit.
+        It identifies the frame and its state on the video hardware.
+        - application - set during initialization
+        - libavcodec  - unchanged
+    */
+    XvMCSurface*    p_surface;
+
+/** Set by the decoder before calling ff_draw_horiz_band(),
+    needed by the XvMCRenderSurface function. */
+//@{
+    /** Pointer to the surface used as past reference
+        - application - unchanged
+        - libavcodec  - set
+    */
+    XvMCSurface*    p_past_surface;
+
+    /** Pointer to the surface used as future reference
+        - application - unchanged
+        - libavcodec  - set
+    */
+    XvMCSurface*    p_future_surface;
+
+    /** top/bottom field or frame
+        - application - unchanged
+        - libavcodec  - set
+    */
+    unsigned int    picture_structure;
+
+    /** XVMC_SECOND_FIELD - 1st or 2nd field in the sequence
+        - application - unchanged
+        - libavcodec  - set
+    */
+    unsigned int    flags;
+//}@
+
+    /** Number of macroblock descriptions in the mv_blocks array
+        that have already been passed to the hardware.
+        - application - zeroes it on get_buffer().
+                        A successful ff_draw_horiz_band() may increment it
+                        with filled_mb_block_num or zero both.
+        - libavcodec  - unchanged
+    */
+    int             start_mv_blocks_num;
+
+    /** Number of new macroblock descriptions in the mv_blocks array (after
+        start_mv_blocks_num) that are filled by libavcodec and have to be
+        passed to the hardware.
+        - application - zeroes it on get_buffer() or after successful
+                        ff_draw_horiz_band().
+        - libavcodec  - increment with one of each stored MB
+    */
+    int             filled_mv_blocks_num;
+
+    /** Number of the next free data block; one data block consists of
+        64 short values in the data_blocks array.
+        All blocks before this one have already been claimed by placing their
+        position into the corresponding block description structure field,
+        that are part of the mv_blocks array.
+        - application - zeroes it on get_buffer().
+                        A successful ff_draw_horiz_band() may zero it together
+                        with start_mb_blocks_num.
+        - libavcodec  - each decoded macroblock increases it by the number
+                        of coded blocks it contains.
+    */
+    int             next_free_data_block_num;
+};
+
+/**
+ * @}
+ */
+
+#endif /* AVCODEC_XVMC_H */

+ 2239 - 0
wave420l/code/ffmpeg/include/libavformat/avformat.h

@@ -0,0 +1,2239 @@
+/*
+ * copyright (c) 2001 Fabrice Bellard
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVFORMAT_AVFORMAT_H
+#define AVFORMAT_AVFORMAT_H
+
+/**
+ * @file
+ * @ingroup libavf
+ * Main libavformat public API header
+ */
+
+/**
+ * @defgroup libavf I/O and Muxing/Demuxing Library
+ * @{
+ *
+ * Libavformat (lavf) is a library for dealing with various media container
+ * formats. Its main two purposes are demuxing - i.e. splitting a media file
+ * into component streams, and the reverse process of muxing - writing supplied
+ * data in a specified container format. It also has an @ref lavf_io
+ * "I/O module" which supports a number of protocols for accessing the data (e.g.
+ * file, tcp, http and others). Before using lavf, you need to call
+ * av_register_all() to register all compiled muxers, demuxers and protocols.
+ * Unless you are absolutely sure you won't use libavformat's network
+ * capabilities, you should also call avformat_network_init().
+ *
+ * A supported input format is described by an AVInputFormat struct, conversely
+ * an output format is described by AVOutputFormat. You can iterate over all
+ * registered input/output formats using the av_iformat_next() /
+ * av_oformat_next() functions. The protocols layer is not part of the public
+ * API, so you can only get the names of supported protocols with the
+ * avio_enum_protocols() function.
+ *
+ * Main lavf structure used for both muxing and demuxing is AVFormatContext,
+ * which exports all information about the file being read or written. As with
+ * most Libavformat structures, its size is not part of public ABI, so it cannot be
+ * allocated on stack or directly with av_malloc(). To create an
+ * AVFormatContext, use avformat_alloc_context() (some functions, like
+ * avformat_open_input() might do that for you).
+ *
+ * Most importantly an AVFormatContext contains:
+ * @li the @ref AVFormatContext.iformat "input" or @ref AVFormatContext.oformat
+ * "output" format. It is either autodetected or set by user for input;
+ * always set by user for output.
+ * @li an @ref AVFormatContext.streams "array" of AVStreams, which describe all
+ * elementary streams stored in the file. AVStreams are typically referred to
+ * using their index in this array.
+ * @li an @ref AVFormatContext.pb "I/O context". It is either opened by lavf or
+ * set by user for input, always set by user for output (unless you are dealing
+ * with an AVFMT_NOFILE format).
+ *
+ * @section lavf_options Passing options to (de)muxers
+ * Lavf allows to configure muxers and demuxers using the @ref avoptions
+ * mechanism. Generic (format-independent) libavformat options are provided by
+ * AVFormatContext, they can be examined from a user program by calling
+ * av_opt_next() / av_opt_find() on an allocated AVFormatContext (or its AVClass
+ * from avformat_get_class()). Private (format-specific) options are provided by
+ * AVFormatContext.priv_data if and only if AVInputFormat.priv_class /
+ * AVOutputFormat.priv_class of the corresponding format struct is non-NULL.
+ * Further options may be provided by the @ref AVFormatContext.pb "I/O context",
+ * if its AVClass is non-NULL, and the protocols layer. See the discussion on
+ * nesting in @ref avoptions documentation to learn how to access those.
+ *
+ * @defgroup lavf_decoding Demuxing
+ * @{
+ * Demuxers read a media file and split it into chunks of data (@em packets). A
+ * @ref AVPacket "packet" contains one or more encoded frames which belongs to a
+ * single elementary stream. In the lavf API this process is represented by the
+ * avformat_open_input() function for opening a file, av_read_frame() for
+ * reading a single packet and finally avformat_close_input(), which does the
+ * cleanup.
+ *
+ * @section lavf_decoding_open Opening a media file
+ * The minimum information required to open a file is its URL or filename, which
+ * is passed to avformat_open_input(), as in the following code:
+ * @code
+ * const char    *url = "in.mp3";
+ * AVFormatContext *s = NULL;
+ * int ret = avformat_open_input(&s, url, NULL, NULL);
+ * if (ret < 0)
+ *     abort();
+ * @endcode
+ * The above code attempts to allocate an AVFormatContext, open the
+ * specified file (autodetecting the format) and read the header, exporting the
+ * information stored there into s. Some formats do not have a header or do not
+ * store enough information there, so it is recommended that you call the
+ * avformat_find_stream_info() function which tries to read and decode a few
+ * frames to find missing information.
+ *
+ * In some cases you might want to preallocate an AVFormatContext yourself with
+ * avformat_alloc_context() and do some tweaking on it before passing it to
+ * avformat_open_input(). One such case is when you want to use custom functions
+ * for reading input data instead of lavf internal I/O layer.
+ * To do that, create your own AVIOContext with avio_alloc_context(), passing
+ * your reading callbacks to it. Then set the @em pb field of your
+ * AVFormatContext to newly created AVIOContext.
+ *
+ * Since the format of the opened file is in general not known until after
+ * avformat_open_input() has returned, it is not possible to set demuxer private
+ * options on a preallocated context. Instead, the options should be passed to
+ * avformat_open_input() wrapped in an AVDictionary:
+ * @code
+ * AVDictionary *options = NULL;
+ * av_dict_set(&options, "video_size", "640x480", 0);
+ * av_dict_set(&options, "pixel_format", "rgb24", 0);
+ *
+ * if (avformat_open_input(&s, url, NULL, &options) < 0)
+ *     abort();
+ * av_dict_free(&options);
+ * @endcode
+ * This code passes the private options 'video_size' and 'pixel_format' to the
+ * demuxer. They would be necessary for e.g. the rawvideo demuxer, since it
+ * cannot know how to interpret raw video data otherwise. If the format turns
+ * out to be something different than raw video, those options will not be
+ * recognized by the demuxer and therefore will not be applied. Such unrecognized
+ * options are then returned in the options dictionary (recognized options are
+ * consumed). The calling program can handle such unrecognized options as it
+ * wishes, e.g.
+ * @code
+ * AVDictionaryEntry *e;
+ * if (e = av_dict_get(options, "", NULL, AV_DICT_IGNORE_SUFFIX)) {
+ *     fprintf(stderr, "Option %s not recognized by the demuxer.\n", e->key);
+ *     abort();
+ * }
+ * @endcode
+ *
+ * After you have finished reading the file, you must close it with
+ * avformat_close_input(). It will free everything associated with the file.
+ *
+ * @section lavf_decoding_read Reading from an opened file
+ * Reading data from an opened AVFormatContext is done by repeatedly calling
+ * av_read_frame() on it. Each call, if successful, will return an AVPacket
+ * containing encoded data for one AVStream, identified by
+ * AVPacket.stream_index. This packet may be passed straight into the libavcodec
+ * decoding functions avcodec_decode_video2(), avcodec_decode_audio4() or
+ * avcodec_decode_subtitle2() if the caller wishes to decode the data.
+ *
+ * AVPacket.pts, AVPacket.dts and AVPacket.duration timing information will be
+ * set if known. They may also be unset (i.e. AV_NOPTS_VALUE for
+ * pts/dts, 0 for duration) if the stream does not provide them. The timing
+ * information will be in AVStream.time_base units, i.e. it has to be
+ * multiplied by the timebase to convert them to seconds.
+ *
+ * If AVPacket.buf is set on the returned packet, then the packet is
+ * allocated dynamically and the user may keep it indefinitely.
+ * Otherwise, if AVPacket.buf is NULL, the packet data is backed by a
+ * static storage somewhere inside the demuxer and the packet is only valid
+ * until the next av_read_frame() call or closing the file. If the caller
+ * requires a longer lifetime, av_dup_packet() will make an av_malloc()ed copy
+ * of it.
+ * In both cases, the packet must be freed with av_free_packet() when it is no
+ * longer needed.
+ *
+ * @section lavf_decoding_seek Seeking
+ * @}
+ *
+ * @defgroup lavf_encoding Muxing
+ * @{
+ * @}
+ *
+ * @defgroup lavf_io I/O Read/Write
+ * @{
+ * @}
+ *
+ * @defgroup lavf_codec Demuxers
+ * @{
+ * @defgroup lavf_codec_native Native Demuxers
+ * @{
+ * @}
+ * @defgroup lavf_codec_wrappers External library wrappers
+ * @{
+ * @}
+ * @}
+ * @defgroup lavf_protos I/O Protocols
+ * @{
+ * @}
+ * @defgroup lavf_internal Internal
+ * @{
+ * @}
+ * @}
+ *
+ */
+
+#include <time.h>
+#include <stdio.h>  /* FILE */
+#include "libavcodec/avcodec.h"
+#include "libavutil/dict.h"
+#include "libavutil/log.h"
+
+#include "avio.h"
+#include "libavformat/version.h"
+
+struct AVFormatContext;
+
+
+/**
+ * @defgroup metadata_api Public Metadata API
+ * @{
+ * @ingroup libavf
+ * The metadata API allows libavformat to export metadata tags to a client
+ * application when demuxing. Conversely it allows a client application to
+ * set metadata when muxing.
+ *
+ * Metadata is exported or set as pairs of key/value strings in the 'metadata'
+ * fields of the AVFormatContext, AVStream, AVChapter and AVProgram structs
+ * using the @ref lavu_dict "AVDictionary" API. Like all strings in FFmpeg,
+ * metadata is assumed to be UTF-8 encoded Unicode. Note that metadata
+ * exported by demuxers isn't checked to be valid UTF-8 in most cases.
+ *
+ * Important concepts to keep in mind:
+ * -  Keys are unique; there can never be 2 tags with the same key. This is
+ *    also meant semantically, i.e., a demuxer should not knowingly produce
+ *    several keys that are literally different but semantically identical.
+ *    E.g., key=Author5, key=Author6. In this example, all authors must be
+ *    placed in the same tag.
+ * -  Metadata is flat, not hierarchical; there are no subtags. If you
+ *    want to store, e.g., the email address of the child of producer Alice
+ *    and actor Bob, that could have key=alice_and_bobs_childs_email_address.
+ * -  Several modifiers can be applied to the tag name. This is done by
+ *    appending a dash character ('-') and the modifier name in the order
+ *    they appear in the list below -- e.g. foo-eng-sort, not foo-sort-eng.
+ *    -  language -- a tag whose value is localized for a particular language
+ *       is appended with the ISO 639-2/B 3-letter language code.
+ *       For example: Author-ger=Michael, Author-eng=Mike
+ *       The original/default language is in the unqualified "Author" tag.
+ *       A demuxer should set a default if it sets any translated tag.
+ *    -  sorting  -- a modified version of a tag that should be used for
+ *       sorting will have '-sort' appended. E.g. artist="The Beatles",
+ *       artist-sort="Beatles, The".
+ *
+ * -  Demuxers attempt to export metadata in a generic format, however tags
+ *    with no generic equivalents are left as they are stored in the container.
+ *    Follows a list of generic tag names:
+ *
+ @verbatim
+ album        -- name of the set this work belongs to
+ album_artist -- main creator of the set/album, if different from artist.
+                 e.g. "Various Artists" for compilation albums.
+ artist       -- main creator of the work
+ comment      -- any additional description of the file.
+ composer     -- who composed the work, if different from artist.
+ copyright    -- name of copyright holder.
+ creation_time-- date when the file was created, preferably in ISO 8601.
+ date         -- date when the work was created, preferably in ISO 8601.
+ disc         -- number of a subset, e.g. disc in a multi-disc collection.
+ encoder      -- name/settings of the software/hardware that produced the file.
+ encoded_by   -- person/group who created the file.
+ filename     -- original name of the file.
+ genre        -- <self-evident>.
+ language     -- main language in which the work is performed, preferably
+                 in ISO 639-2 format. Multiple languages can be specified by
+                 separating them with commas.
+ performer    -- artist who performed the work, if different from artist.
+                 E.g for "Also sprach Zarathustra", artist would be "Richard
+                 Strauss" and performer "London Philharmonic Orchestra".
+ publisher    -- name of the label/publisher.
+ service_name     -- name of the service in broadcasting (channel name).
+ service_provider -- name of the service provider in broadcasting.
+ title        -- name of the work.
+ track        -- number of this work in the set, can be in form current/total.
+ variant_bitrate -- the total bitrate of the bitrate variant that the current stream is part of
+ @endverbatim
+ *
+ * Look in the examples section for an application example how to use the Metadata API.
+ *
+ * @}
+ */
+
+/* packet functions */
+
+
+/**
+ * Allocate and read the payload of a packet and initialize its
+ * fields with default values.
+ *
+ * @param pkt packet
+ * @param size desired payload size
+ * @return >0 (read size) if OK, AVERROR_xxx otherwise
+ */
+int av_get_packet(AVIOContext *s, AVPacket *pkt, int size);
+
+
+/**
+ * Read data and append it to the current content of the AVPacket.
+ * If pkt->size is 0 this is identical to av_get_packet.
+ * Note that this uses av_grow_packet and thus involves a realloc
+ * which is inefficient. Thus this function should only be used
+ * when there is no reasonable way to know (an upper bound of)
+ * the final size.
+ *
+ * @param pkt packet
+ * @param size amount of data to read
+ * @return >0 (read size) if OK, AVERROR_xxx otherwise, previous data
+ *         will not be lost even if an error occurs.
+ */
+int av_append_packet(AVIOContext *s, AVPacket *pkt, int size);
+
+/*************************************************/
+/* fractional numbers for exact pts handling */
+
+/**
+ * The exact value of the fractional number is: 'val + num / den'.
+ * num is assumed to be 0 <= num < den.
+ */
+typedef struct AVFrac {
+    int64_t val, num, den;
+} AVFrac;
+
+/*************************************************/
+/* input/output formats */
+
+struct AVCodecTag;
+
+/**
+ * This structure contains the data a format has to probe a file.
+ */
+typedef struct AVProbeData {
+    const char *filename;
+    unsigned char *buf; /**< Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero. */
+    int buf_size;       /**< Size of buf except extra allocated bytes */
+} AVProbeData;
+
+#define AVPROBE_SCORE_RETRY (AVPROBE_SCORE_MAX/4)
+#define AVPROBE_SCORE_EXTENSION  50 ///< score for file extension
+#define AVPROBE_SCORE_MAX       100 ///< maximum score
+
+#define AVPROBE_PADDING_SIZE 32             ///< extra allocated bytes at the end of the probe buffer
+
+/// Demuxer will use avio_open, no opened file should be provided by the caller.
+#define AVFMT_NOFILE        0x0001
+#define AVFMT_NEEDNUMBER    0x0002 /**< Needs '%d' in filename. */
+#define AVFMT_SHOW_IDS      0x0008 /**< Show format stream IDs numbers. */
+#define AVFMT_RAWPICTURE    0x0020 /**< Format wants AVPicture structure for
+                                      raw picture data. */
+#define AVFMT_GLOBALHEADER  0x0040 /**< Format wants global header. */
+#define AVFMT_NOTIMESTAMPS  0x0080 /**< Format does not need / have any timestamps. */
+#define AVFMT_GENERIC_INDEX 0x0100 /**< Use generic index building code. */
+#define AVFMT_TS_DISCONT    0x0200 /**< Format allows timestamp discontinuities. Note, muxers always require valid (monotone) timestamps */
+#define AVFMT_VARIABLE_FPS  0x0400 /**< Format allows variable fps. */
+#define AVFMT_NODIMENSIONS  0x0800 /**< Format does not need width/height */
+#define AVFMT_NOSTREAMS     0x1000 /**< Format does not require any streams */
+#define AVFMT_NOBINSEARCH   0x2000 /**< Format does not allow to fall back on binary search via read_timestamp */
+#define AVFMT_NOGENSEARCH   0x4000 /**< Format does not allow to fall back on generic search */
+#define AVFMT_NO_BYTE_SEEK  0x8000 /**< Format does not allow seeking by bytes */
+#define AVFMT_ALLOW_FLUSH  0x10000 /**< Format allows flushing. If not set, the muxer will not receive a NULL packet in the write_packet function. */
+#if LIBAVFORMAT_VERSION_MAJOR <= 54
+#define AVFMT_TS_NONSTRICT 0x8020000 //we try to be compatible to the ABIs of ffmpeg and major forks
+#else
+#define AVFMT_TS_NONSTRICT 0x20000
+#endif
+                                   /**< Format does not require strictly
+                                        increasing timestamps, but they must
+                                        still be monotonic */
+#define AVFMT_TS_NEGATIVE  0x40000 /**< Format allows muxing negative
+                                        timestamps. If not set the timestamp
+                                        will be shifted in av_write_frame and
+                                        av_interleaved_write_frame so they
+                                        start from 0.
+                                        The user or muxer can override this through
+                                        AVFormatContext.avoid_negative_ts
+                                        */
+
+#define AVFMT_SEEK_TO_PTS   0x4000000 /**< Seeking is based on PTS */
+
+/**
+ * @addtogroup lavf_encoding
+ * @{
+ */
+typedef struct AVOutputFormat {
+    const char *name;
+    /**
+     * Descriptive name for the format, meant to be more human-readable
+     * than name. You should use the NULL_IF_CONFIG_SMALL() macro
+     * to define it.
+     */
+    const char *long_name;
+    const char *mime_type;
+    const char *extensions; /**< comma-separated filename extensions */
+    /* output support */
+    enum AVCodecID audio_codec;    /**< default audio codec */
+    enum AVCodecID video_codec;    /**< default video codec */
+    enum AVCodecID subtitle_codec; /**< default subtitle codec */
+    /**
+     * can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_RAWPICTURE,
+     * AVFMT_GLOBALHEADER, AVFMT_NOTIMESTAMPS, AVFMT_VARIABLE_FPS,
+     * AVFMT_NODIMENSIONS, AVFMT_NOSTREAMS, AVFMT_ALLOW_FLUSH,
+     * AVFMT_TS_NONSTRICT
+     */
+    int flags;
+
+    /**
+     * List of supported codec_id-codec_tag pairs, ordered by "better
+     * choice first". The arrays are all terminated by AV_CODEC_ID_NONE.
+     */
+    const struct AVCodecTag * const *codec_tag;
+
+
+    const AVClass *priv_class; ///< AVClass for the private context
+
+    /*****************************************************************
+     * No fields below this line are part of the public API. They
+     * may not be used outside of libavformat and can be changed and
+     * removed at will.
+     * New public fields should be added right above.
+     *****************************************************************
+     */
+    struct AVOutputFormat *next;
+    /**
+     * size of private data so that it can be allocated in the wrapper
+     */
+    int priv_data_size;
+
+    int (*write_header)(struct AVFormatContext *);
+    /**
+     * Write a packet. If AVFMT_ALLOW_FLUSH is set in flags,
+     * pkt can be NULL in order to flush data buffered in the muxer.
+     * When flushing, return 0 if there still is more data to flush,
+     * or 1 if everything was flushed and there is no more buffered
+     * data.
+     */
+    int (*write_packet)(struct AVFormatContext *, AVPacket *pkt);
+    int (*write_trailer)(struct AVFormatContext *);
+    /**
+     * Currently only used to set pixel format if not YUV420P.
+     */
+    int (*interleave_packet)(struct AVFormatContext *, AVPacket *out,
+                             AVPacket *in, int flush);
+    /**
+     * Test if the given codec can be stored in this container.
+     *
+     * @return 1 if the codec is supported, 0 if it is not.
+     *         A negative number if unknown.
+     *         MKTAG('A', 'P', 'I', 'C') if the codec is only supported as AV_DISPOSITION_ATTACHED_PIC
+     */
+    int (*query_codec)(enum AVCodecID id, int std_compliance);
+
+    void (*get_output_timestamp)(struct AVFormatContext *s, int stream,
+                                 int64_t *dts, int64_t *wall);
+} AVOutputFormat;
+/**
+ * @}
+ */
+
+/**
+ * @addtogroup lavf_decoding
+ * @{
+ */
+typedef struct AVInputFormat {
+    /**
+     * A comma separated list of short names for the format. New names
+     * may be appended with a minor bump.
+     */
+    const char *name;
+
+    /**
+     * Descriptive name for the format, meant to be more human-readable
+     * than name. You should use the NULL_IF_CONFIG_SMALL() macro
+     * to define it.
+     */
+    const char *long_name;
+
+    /**
+     * Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_SHOW_IDS,
+     * AVFMT_GENERIC_INDEX, AVFMT_TS_DISCONT, AVFMT_NOBINSEARCH,
+     * AVFMT_NOGENSEARCH, AVFMT_NO_BYTE_SEEK, AVFMT_SEEK_TO_PTS.
+     */
+    int flags;
+
+    /**
+     * If extensions are defined, then no probe is done. You should
+     * usually not use extension format guessing because it is not
+     * reliable enough
+     */
+    const char *extensions;
+
+    const struct AVCodecTag * const *codec_tag;
+
+    const AVClass *priv_class; ///< AVClass for the private context
+
+    /*****************************************************************
+     * No fields below this line are part of the public API. They
+     * may not be used outside of libavformat and can be changed and
+     * removed at will.
+     * New public fields should be added right above.
+     *****************************************************************
+     */
+    struct AVInputFormat *next;
+
+    /**
+     * Raw demuxers store their codec ID here.
+     */
+    int raw_codec_id;
+
+    /**
+     * Size of private data so that it can be allocated in the wrapper.
+     */
+    int priv_data_size;
+
+    /**
+     * Tell if a given file has a chance of being parsed as this format.
+     * The buffer provided is guaranteed to be AVPROBE_PADDING_SIZE bytes
+     * big so you do not have to check for that unless you need more.
+     */
+    int (*read_probe)(AVProbeData *);
+
+    /**
+     * Read the format header and initialize the AVFormatContext
+     * structure. Return 0 if OK. Only used in raw format right
+     * now. 'avformat_new_stream' should be called to create new streams.
+     */
+    int (*read_header)(struct AVFormatContext *);
+
+    /**
+     * Read one packet and put it in 'pkt'. pts and flags are also
+     * set. 'avformat_new_stream' can be called only if the flag
+     * AVFMTCTX_NOHEADER is used and only in the calling thread (not in a
+     * background thread).
+     * @return 0 on success, < 0 on error.
+     *         When returning an error, pkt must not have been allocated
+     *         or must be freed before returning
+     */
+    int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
+
+    /**
+     * Close the stream. The AVFormatContext and AVStreams are not
+     * freed by this function
+     */
+    int (*read_close)(struct AVFormatContext *);
+
+    /**
+     * Seek to a given timestamp relative to the frames in
+     * stream component stream_index.
+     * @param stream_index Must not be -1.
+     * @param flags Selects which direction should be preferred if no exact
+     *              match is available.
+     * @return >= 0 on success (but not necessarily the new offset)
+     */
+    int (*read_seek)(struct AVFormatContext *,
+                     int stream_index, int64_t timestamp, int flags);
+
+    /**
+     * Get the next timestamp in stream[stream_index].time_base units.
+     * @return the timestamp or AV_NOPTS_VALUE if an error occurred
+     */
+    int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index,
+                              int64_t *pos, int64_t pos_limit);
+
+    /**
+     * Start/resume playing - only meaningful if using a network-based format
+     * (RTSP).
+     */
+    int (*read_play)(struct AVFormatContext *);
+
+    /**
+     * Pause playing - only meaningful if using a network-based format
+     * (RTSP).
+     */
+    int (*read_pause)(struct AVFormatContext *);
+
+    /**
+     * Seek to timestamp ts.
+     * Seeking will be done so that the point from which all active streams
+     * can be presented successfully will be closest to ts and within min/max_ts.
+     * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
+     */
+    int (*read_seek2)(struct AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
+} AVInputFormat;
+/**
+ * @}
+ */
+
+enum AVStreamParseType {
+    AVSTREAM_PARSE_NONE,
+    AVSTREAM_PARSE_FULL,       /**< full parsing and repack */
+    AVSTREAM_PARSE_HEADERS,    /**< Only parse headers, do not repack. */
+    AVSTREAM_PARSE_TIMESTAMPS, /**< full parsing and interpolation of timestamps for frames not starting on a packet boundary */
+    AVSTREAM_PARSE_FULL_ONCE,  /**< full parsing and repack of the first frame only, only implemented for H.264 currently */
+    AVSTREAM_PARSE_FULL_RAW=MKTAG(0,'R','A','W'),       /**< full parsing and repack with timestamp and position generation by parser for raw
+                                                             this assumes that each packet in the file contains no demuxer level headers and
+                                                             just codec level data, otherwise position generation would fail */
+};
+
+typedef struct AVIndexEntry {
+    int64_t pos;
+    int64_t timestamp;        /**<
+                               * Timestamp in AVStream.time_base units, preferably the time from which on correctly decoded frames are available
+                               * when seeking to this entry. That means preferable PTS on keyframe based formats.
+                               * But demuxers can choose to store a different timestamp, if it is more convenient for the implementation or nothing better
+                               * is known
+                               */
+#define AVINDEX_KEYFRAME 0x0001
+    int flags:2;
+    int size:30; //Yeah, trying to keep the size of this small to reduce memory requirements (it is 24 vs. 32 bytes due to possible 8-byte alignment).
+    int min_distance;         /**< Minimum distance between this and the previous keyframe, used to avoid unneeded searching. */
+} AVIndexEntry;
+
+#define AV_DISPOSITION_DEFAULT   0x0001
+#define AV_DISPOSITION_DUB       0x0002
+#define AV_DISPOSITION_ORIGINAL  0x0004
+#define AV_DISPOSITION_COMMENT   0x0008
+#define AV_DISPOSITION_LYRICS    0x0010
+#define AV_DISPOSITION_KARAOKE   0x0020
+
+/**
+ * Track should be used during playback by default.
+ * Useful for subtitle track that should be displayed
+ * even when user did not explicitly ask for subtitles.
+ */
+#define AV_DISPOSITION_FORCED    0x0040
+#define AV_DISPOSITION_HEARING_IMPAIRED  0x0080  /**< stream for hearing impaired audiences */
+#define AV_DISPOSITION_VISUAL_IMPAIRED   0x0100  /**< stream for visual impaired audiences */
+#define AV_DISPOSITION_CLEAN_EFFECTS     0x0200  /**< stream without voice */
+/**
+ * The stream is stored in the file as an attached picture/"cover art" (e.g.
+ * APIC frame in ID3v2). The single packet associated with it will be returned
+ * among the first few packets read from the file unless seeking takes place.
+ * It can also be accessed at any time in AVStream.attached_pic.
+ */
+#define AV_DISPOSITION_ATTACHED_PIC      0x0400
+
+/**
+ * To specify text track kind (different from subtitles default).
+ */
+#define AV_DISPOSITION_CAPTIONS     0x10000
+#define AV_DISPOSITION_DESCRIPTIONS 0x20000
+#define AV_DISPOSITION_METADATA     0x40000
+
+/**
+ * Options for behavior on timestamp wrap detection.
+ */
+#define AV_PTS_WRAP_IGNORE      0   ///< ignore the wrap
+#define AV_PTS_WRAP_ADD_OFFSET  1   ///< add the format specific offset on wrap detection
+#define AV_PTS_WRAP_SUB_OFFSET  -1  ///< subtract the format specific offset on wrap detection
+
+/**
+ * Stream structure.
+ * New fields can be added to the end with minor version bumps.
+ * Removal, reordering and changes to existing fields require a major
+ * version bump.
+ * sizeof(AVStream) must not be used outside libav*.
+ */
+typedef struct AVStream {
+    int index;    /**< stream index in AVFormatContext */
+    /**
+     * Format-specific stream ID.
+     * decoding: set by libavformat
+     * encoding: set by the user, replaced by libavformat if left unset
+     */
+    int id;
+    /**
+     * Codec context associated with this stream. Allocated and freed by
+     * libavformat.
+     *
+     * - decoding: The demuxer exports codec information stored in the headers
+     *             here.
+     * - encoding: The user sets codec information, the muxer writes it to the
+     *             output. Mandatory fields as specified in AVCodecContext
+     *             documentation must be set even if this AVCodecContext is
+     *             not actually used for encoding.
+     */
+    AVCodecContext *codec;
+    void *priv_data;
+
+    /**
+     * encoding: pts generation when outputting stream
+     */
+    struct AVFrac pts;
+
+    /**
+     * This is the fundamental unit of time (in seconds) in terms
+     * of which frame timestamps are represented.
+     *
+     * decoding: set by libavformat
+     * encoding: set by libavformat in avformat_write_header. The muxer may use the
+     * user-provided value of @ref AVCodecContext.time_base "codec->time_base"
+     * as a hint.
+     */
+    AVRational time_base;
+
+    /**
+     * Decoding: pts of the first frame of the stream in presentation order, in stream time base.
+     * Only set this if you are absolutely 100% sure that the value you set
+     * it to really is the pts of the first frame.
+     * This may be undefined (AV_NOPTS_VALUE).
+     * @note The ASF header does NOT contain a correct start_time the ASF
+     * demuxer must NOT set this.
+     */
+    int64_t start_time;
+
+    /**
+     * Decoding: duration of the stream, in stream time base.
+     * If a source file does not specify a duration, but does specify
+     * a bitrate, this value will be estimated from bitrate and file size.
+     */
+    int64_t duration;
+
+    int64_t nb_frames;                 ///< number of frames in this stream if known or 0
+
+    int disposition; /**< AV_DISPOSITION_* bit field */
+
+    enum AVDiscard discard; ///< Selects which packets can be discarded at will and do not need to be demuxed.
+
+    /**
+     * sample aspect ratio (0 if unknown)
+     * - encoding: Set by user.
+     * - decoding: Set by libavformat.
+     */
+    AVRational sample_aspect_ratio;
+
+    AVDictionary *metadata;
+
+    /**
+     * Average framerate
+     */
+    AVRational avg_frame_rate;
+
+    /**
+     * For streams with AV_DISPOSITION_ATTACHED_PIC disposition, this packet
+     * will contain the attached picture.
+     *
+     * decoding: set by libavformat, must not be modified by the caller.
+     * encoding: unused
+     */
+    AVPacket attached_pic;
+
+    /*****************************************************************
+     * All fields below this line are not part of the public API. They
+     * may not be used outside of libavformat and can be changed and
+     * removed at will.
+     * New public fields should be added right above.
+     *****************************************************************
+     */
+
+    /**
+     * Stream information used internally by av_find_stream_info()
+     */
+#define MAX_STD_TIMEBASES (60*12+6)
+    struct {
+        int64_t last_dts;
+        int64_t duration_gcd;
+        int duration_count;
+        double (*duration_error)[2][MAX_STD_TIMEBASES];
+        int64_t codec_info_duration;
+        int64_t codec_info_duration_fields;
+        int found_decoder;
+
+        int64_t last_duration;
+
+        /**
+         * Those are used for average framerate estimation.
+         */
+        int64_t fps_first_dts;
+        int     fps_first_dts_idx;
+        int64_t fps_last_dts;
+        int     fps_last_dts_idx;
+
+    } *info;
+
+    int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */
+
+    // Timestamp generation support:
+    /**
+     * Timestamp corresponding to the last dts sync point.
+     *
+     * Initialized when AVCodecParserContext.dts_sync_point >= 0 and
+     * a DTS is received from the underlying container. Otherwise set to
+     * AV_NOPTS_VALUE by default.
+     */
+    int64_t reference_dts;
+    int64_t first_dts;
+    int64_t cur_dts;
+    int64_t last_IP_pts;
+    int last_IP_duration;
+
+    /**
+     * Number of packets to buffer for codec probing
+     */
+#define MAX_PROBE_PACKETS 2500
+    int probe_packets;
+
+    /**
+     * Number of frames that have been demuxed during av_find_stream_info()
+     */
+    int codec_info_nb_frames;
+
+    /* av_read_frame() support */
+    enum AVStreamParseType need_parsing;
+    struct AVCodecParserContext *parser;
+
+    /**
+     * last packet in packet_buffer for this stream when muxing.
+     */
+    struct AVPacketList *last_in_packet_buffer;
+    AVProbeData probe_data;
+#define MAX_REORDER_DELAY 16
+    int64_t pts_buffer[MAX_REORDER_DELAY+1];
+
+    AVIndexEntry *index_entries; /**< Only used if the format does not
+                                    support seeking natively. */
+    int nb_index_entries;
+    unsigned int index_entries_allocated_size;
+
+    /**
+     * Real base framerate of the stream.
+     * This is the lowest framerate with which all timestamps can be
+     * represented accurately (it is the least common multiple of all
+     * framerates in the stream). Note, this value is just a guess!
+     * For example, if the time base is 1/90000 and all frames have either
+     * approximately 3600 or 1800 timer ticks, then r_frame_rate will be 50/1.
+     *
+     * Code outside avformat should access this field using:
+     * av_stream_get/set_r_frame_rate(stream)
+     */
+    AVRational r_frame_rate;
+
+    /**
+     * Stream Identifier
+     * This is the MPEG-TS stream identifier +1
+     * 0 means unknown
+     */
+    int stream_identifier;
+
+    int64_t interleaver_chunk_size;
+    int64_t interleaver_chunk_duration;
+
+    /**
+     * stream probing state
+     * -1   -> probing finished
+     *  0   -> no probing requested
+     * rest -> perform probing with request_probe being the minimum score to accept.
+     * NOT PART OF PUBLIC API
+     */
+    int request_probe;
+    /**
+     * Indicates that everything up to the next keyframe
+     * should be discarded.
+     */
+    int skip_to_keyframe;
+
+    /**
+     * Number of samples to skip at the start of the frame decoded from the next packet.
+     */
+    int skip_samples;
+
+    /**
+     * Number of internally decoded frames, used internally in libavformat, do not access
+     * its lifetime differs from info which is why it is not in that structure.
+     */
+    int nb_decoded_frames;
+
+    /**
+     * Timestamp offset added to timestamps before muxing
+     * NOT PART OF PUBLIC API
+     */
+    int64_t mux_ts_offset;
+
+    /**
+     * Internal data to check for wrapping of the time stamp
+     */
+    int64_t pts_wrap_reference;
+
+    /**
+     * Options for behavior, when a wrap is detected.
+     *
+     * Defined by AV_PTS_WRAP_ values.
+     *
+     * If correction is enabled, there are two possibilities:
+     * If the first time stamp is near the wrap point, the wrap offset
+     * will be subtracted, which will create negative time stamps.
+     * Otherwise the offset will be added.
+     */
+    int pts_wrap_behavior;
+
+} AVStream;
+
+AVRational av_stream_get_r_frame_rate(const AVStream *s);
+void       av_stream_set_r_frame_rate(AVStream *s, AVRational r);
+
+#define AV_PROGRAM_RUNNING 1
+
+/**
+ * New fields can be added to the end with minor version bumps.
+ * Removal, reordering and changes to existing fields require a major
+ * version bump.
+ * sizeof(AVProgram) must not be used outside libav*.
+ */
+typedef struct AVProgram {
+    int            id;
+    int            flags;
+    enum AVDiscard discard;        ///< selects which program to discard and which to feed to the caller
+    unsigned int   *stream_index;
+    unsigned int   nb_stream_indexes;
+    AVDictionary *metadata;
+
+    int program_num;
+    int pmt_pid;
+    int pcr_pid;
+
+    /*****************************************************************
+     * All fields below this line are not part of the public API. They
+     * may not be used outside of libavformat and can be changed and
+     * removed at will.
+     * New public fields should be added right above.
+     *****************************************************************
+     */
+    int64_t start_time;
+    int64_t end_time;
+
+    int64_t pts_wrap_reference;    ///< reference dts for wrap detection
+    int pts_wrap_behavior;         ///< behavior on wrap detection
+} AVProgram;
+
+#define AVFMTCTX_NOHEADER      0x0001 /**< signal that no header is present
+                                         (streams are added dynamically) */
+
+typedef struct AVChapter {
+    int id;                 ///< unique ID to identify the chapter
+    AVRational time_base;   ///< time base in which the start/end timestamps are specified
+    int64_t start, end;     ///< chapter start/end time in time_base units
+    AVDictionary *metadata;
+} AVChapter;
+
+
+/**
+ * The duration of a video can be estimated through various ways, and this enum can be used
+ * to know how the duration was estimated.
+ */
+enum AVDurationEstimationMethod {
+    AVFMT_DURATION_FROM_PTS,    ///< Duration accurately estimated from PTSes
+    AVFMT_DURATION_FROM_STREAM, ///< Duration estimated from a stream with a known duration
+    AVFMT_DURATION_FROM_BITRATE ///< Duration estimated from bitrate (less accurate)
+};
+
+/**
+ * Format I/O context.
+ * New fields can be added to the end with minor version bumps.
+ * Removal, reordering and changes to existing fields require a major
+ * version bump.
+ * sizeof(AVFormatContext) must not be used outside libav*, use
+ * avformat_alloc_context() to create an AVFormatContext.
+ */
+typedef struct AVFormatContext {
+    /**
+     * A class for logging and AVOptions. Set by avformat_alloc_context().
+     * Exports (de)muxer private options if they exist.
+     */
+    const AVClass *av_class;
+
+    /**
+     * Can only be iformat or oformat, not both at the same time.
+     *
+     * decoding: set by avformat_open_input().
+     * encoding: set by the user.
+     */
+    struct AVInputFormat *iformat;
+    struct AVOutputFormat *oformat;
+
+    /**
+     * Format private data. This is an AVOptions-enabled struct
+     * if and only if iformat/oformat.priv_class is not NULL.
+     */
+    void *priv_data;
+
+    /**
+     * I/O context.
+     *
+     * decoding: either set by the user before avformat_open_input() (then
+     * the user must close it manually) or set by avformat_open_input().
+     * encoding: set by the user.
+     *
+     * Do NOT set this field if AVFMT_NOFILE flag is set in
+     * iformat/oformat.flags. In such a case, the (de)muxer will handle
+     * I/O in some other way and this field will be NULL.
+     */
+    AVIOContext *pb;
+
+    /* stream info */
+    int ctx_flags; /**< Format-specific flags, see AVFMTCTX_xx */
+
+    /**
+     * A list of all streams in the file. New streams are created with
+     * avformat_new_stream().
+     *
+     * decoding: streams are created by libavformat in avformat_open_input().
+     * If AVFMTCTX_NOHEADER is set in ctx_flags, then new streams may also
+     * appear in av_read_frame().
+     * encoding: streams are created by the user before avformat_write_header().
+     */
+    unsigned int nb_streams;
+    AVStream **streams;
+
+    char filename[1024]; /**< input or output filename */
+
+    /**
+     * Decoding: position of the first frame of the component, in
+     * AV_TIME_BASE fractional seconds. NEVER set this value directly:
+     * It is deduced from the AVStream values.
+     */
+    int64_t start_time;
+
+    /**
+     * Decoding: duration of the stream, in AV_TIME_BASE fractional
+     * seconds. Only set this value if you know none of the individual stream
+     * durations and also do not set any of them. This is deduced from the
+     * AVStream values if not set.
+     */
+    int64_t duration;
+
+    /**
+     * Decoding: total stream bitrate in bit/s, 0 if not
+     * available. Never set it directly if the file_size and the
+     * duration are known as FFmpeg can compute it automatically.
+     */
+    int bit_rate;
+
+    unsigned int packet_size;
+    int max_delay;
+
+    int flags;
+#define AVFMT_FLAG_GENPTS       0x0001 ///< Generate missing pts even if it requires parsing future frames.
+#define AVFMT_FLAG_IGNIDX       0x0002 ///< Ignore index.
+#define AVFMT_FLAG_NONBLOCK     0x0004 ///< Do not block when reading packets from input.
+#define AVFMT_FLAG_IGNDTS       0x0008 ///< Ignore DTS on frames that contain both DTS & PTS
+#define AVFMT_FLAG_NOFILLIN     0x0010 ///< Do not infer any values from other values, just return what is stored in the container
+#define AVFMT_FLAG_NOPARSE      0x0020 ///< Do not use AVParsers, you also must set AVFMT_FLAG_NOFILLIN as the fillin code works on frames and no parsing -> no frames. Also seeking to frames can not work if parsing to find frame boundaries has been disabled
+#define AVFMT_FLAG_NOBUFFER     0x0040 ///< Do not buffer frames when possible
+#define AVFMT_FLAG_CUSTOM_IO    0x0080 ///< The caller has supplied a custom AVIOContext, don't avio_close() it.
+#define AVFMT_FLAG_DISCARD_CORRUPT  0x0100 ///< Discard frames marked corrupted
+#define AVFMT_FLAG_FLUSH_PACKETS    0x0200 ///< Flush the AVIOContext every packet.
+#define AVFMT_FLAG_MP4A_LATM    0x8000 ///< Enable RTP MP4A-LATM payload
+#define AVFMT_FLAG_SORT_DTS    0x10000 ///< try to interleave outputted packets by dts (using this flag can slow demuxing down)
+#define AVFMT_FLAG_PRIV_OPT    0x20000 ///< Enable use of private options by delaying codec open (this could be made default once all code is converted)
+#define AVFMT_FLAG_KEEP_SIDE_DATA 0x40000 ///< Don't merge side data but keep it separate.
+
+    /**
+     * decoding: size of data to probe; encoding: unused.
+     */
+    unsigned int probesize;
+
+    /**
+     * decoding: maximum time (in AV_TIME_BASE units) during which the input should
+     * be analyzed in avformat_find_stream_info().
+     */
+    int max_analyze_duration;
+
+    const uint8_t *key;
+    int keylen;
+
+    unsigned int nb_programs;
+    AVProgram **programs;
+
+    /**
+     * Forced video codec_id.
+     * Demuxing: Set by user.
+     */
+    enum AVCodecID video_codec_id;
+
+    /**
+     * Forced audio codec_id.
+     * Demuxing: Set by user.
+     */
+    enum AVCodecID audio_codec_id;
+
+    /**
+     * Forced subtitle codec_id.
+     * Demuxing: Set by user.
+     */
+    enum AVCodecID subtitle_codec_id;
+
+    /**
+     * Maximum amount of memory in bytes to use for the index of each stream.
+     * If the index exceeds this size, entries will be discarded as
+     * needed to maintain a smaller size. This can lead to slower or less
+     * accurate seeking (depends on demuxer).
+     * Demuxers for which a full in-memory index is mandatory will ignore
+     * this.
+     * muxing  : unused
+     * demuxing: set by user
+     */
+    unsigned int max_index_size;
+
+    /**
+     * Maximum amount of memory in bytes to use for buffering frames
+     * obtained from realtime capture devices.
+     */
+    unsigned int max_picture_buffer;
+
+    /**
+     * Number of chapters in AVChapter array.
+     * When muxing, chapters are normally written in the file header,
+     * so nb_chapters should normally be initialized before write_header
+     * is called. Some muxers (e.g. mov and mkv) can also write chapters
+     * in the trailer.  To write chapters in the trailer, nb_chapters
+     * must be zero when write_header is called and non-zero when
+     * write_trailer is called.
+     * muxing  : set by user
+     * demuxing: set by libavformat
+     */
+    unsigned int nb_chapters;
+    AVChapter **chapters;
+
+    AVDictionary *metadata;
+
+    /**
+     * Start time of the stream in real world time, in microseconds
+     * since the unix epoch (00:00 1st January 1970). That is, pts=0
+     * in the stream was captured at this real world time.
+     * - encoding: Set by user.
+     * - decoding: Unused.
+     */
+    int64_t start_time_realtime;
+
+    /**
+     * decoding: number of frames used to probe fps
+     */
+    int fps_probe_size;
+
+    /**
+     * Error recognition; higher values will detect more errors but may
+     * misdetect some more or less valid parts as errors.
+     * - encoding: unused
+     * - decoding: Set by user.
+     */
+    int error_recognition;
+
+    /**
+     * Custom interrupt callbacks for the I/O layer.
+     *
+     * decoding: set by the user before avformat_open_input().
+     * encoding: set by the user before avformat_write_header()
+     * (mainly useful for AVFMT_NOFILE formats). The callback
+     * should also be passed to avio_open2() if it's used to
+     * open the file.
+     */
+    AVIOInterruptCB interrupt_callback;
+
+    /**
+     * Flags to enable debugging.
+     */
+    int debug;
+#define FF_FDEBUG_TS        0x0001
+
+    /**
+     * Transport stream id.
+     * This will be moved into demuxer private options. Thus no API/ABI compatibility
+     */
+    int ts_id;
+
+    /**
+     * Audio preload in microseconds.
+     * Note, not all formats support this and unpredictable things may happen if it is used when not supported.
+     * - encoding: Set by user via AVOptions (NO direct access)
+     * - decoding: unused
+     */
+    int audio_preload;
+
+    /**
+     * Max chunk time in microseconds.
+     * Note, not all formats support this and unpredictable things may happen if it is used when not supported.
+     * - encoding: Set by user via AVOptions (NO direct access)
+     * - decoding: unused
+     */
+    int max_chunk_duration;
+
+    /**
+     * Max chunk size in bytes
+     * Note, not all formats support this and unpredictable things may happen if it is used when not supported.
+     * - encoding: Set by user via AVOptions (NO direct access)
+     * - decoding: unused
+     */
+    int max_chunk_size;
+
+    /**
+     * forces the use of wallclock timestamps as pts/dts of packets
+     * This has undefined results in the presence of B frames.
+     * - encoding: unused
+     * - decoding: Set by user via AVOptions (NO direct access)
+     */
+    int use_wallclock_as_timestamps;
+
+    /**
+     * Avoid negative timestamps during muxing.
+     *  0 -> allow negative timestamps
+     *  1 -> avoid negative timestamps
+     * -1 -> choose automatically (default)
+     * Note, this only works when interleave_packet_per_dts is in use.
+     * - encoding: Set by user via AVOptions (NO direct access)
+     * - decoding: unused
+     */
+    int avoid_negative_ts;
+
+    /**
+     * avio flags, used to force AVIO_FLAG_DIRECT.
+     * - encoding: unused
+     * - decoding: Set by user via AVOptions (NO direct access)
+     */
+    int avio_flags;
+
+    /**
+     * The duration field can be estimated through various ways, and this field can be used
+     * to know how the duration was estimated.
+     * - encoding: unused
+     * - decoding: Read by user via AVOptions (NO direct access)
+     */
+    enum AVDurationEstimationMethod duration_estimation_method;
+
+    /**
+     * Skip initial bytes when opening stream
+     * - encoding: unused
+     * - decoding: Set by user via AVOptions (NO direct access)
+     */
+    unsigned int skip_initial_bytes;
+
+    /**
+     * Correct single timestamp overflows
+     * - encoding: unused
+     * - decoding: Set by user via AVOPtions (NO direct access)
+     */
+    unsigned int correct_ts_overflow;
+
+    /**
+     * Force seeking to any (also non key) frames.
+     * - encoding: unused
+     * - decoding: Set by user via AVOPtions (NO direct access)
+     */
+    int seek2any;
+
+    /**
+     * Flush the I/O context after each packet.
+     * - encoding: Set by user via AVOptions (NO direct access)
+     * - decoding: unused
+     */
+    int flush_packets;
+
+    /**
+     * format probing score.
+     * The maximal score is AVPROBE_SCORE_MAX, its set when the demuxer probes
+     * the format.
+     * - encoding: unused
+     * - decoding: set by avformat, read by user via av_format_get_probe_score() (NO direct access)
+     */
+    int probe_score;
+
+    /*****************************************************************
+     * All fields below this line are not part of the public API. They
+     * may not be used outside of libavformat and can be changed and
+     * removed at will.
+     * New public fields should be added right above.
+     *****************************************************************
+     */
+
+    /**
+     * This buffer is only needed when packets were already buffered but
+     * not decoded, for example to get the codec parameters in MPEG
+     * streams.
+     */
+    struct AVPacketList *packet_buffer;
+    struct AVPacketList *packet_buffer_end;
+
+    /* av_seek_frame() support */
+    int64_t data_offset; /**< offset of the first packet */
+
+    /**
+     * Raw packets from the demuxer, prior to parsing and decoding.
+     * This buffer is used for buffering packets until the codec can
+     * be identified, as parsing cannot be done without knowing the
+     * codec.
+     */
+    struct AVPacketList *raw_packet_buffer;
+    struct AVPacketList *raw_packet_buffer_end;
+    /**
+     * Packets split by the parser get queued here.
+     */
+    struct AVPacketList *parse_queue;
+    struct AVPacketList *parse_queue_end;
+    /**
+     * Remaining size available for raw_packet_buffer, in bytes.
+     */
+#define RAW_PACKET_BUFFER_SIZE 2500000
+    int raw_packet_buffer_remaining_size;
+
+    /**
+     * Offset to remap timestamps to be non-negative.
+     * Expressed in timebase units.
+     * @see AVStream.mux_ts_offset
+     */
+    int64_t offset;
+
+    /**
+     * Timebase for the timestamp offset.
+     */
+    AVRational offset_timebase;
+
+    /**
+     * IO repositioned flag.
+     * This is set by avformat when the underlaying IO context read pointer
+     * is repositioned, for example when doing byte based seeking.
+     * Demuxers can use the flag to detect such changes.
+     */
+    int io_repositioned;
+
+    /**
+     * Forced video codec.
+     * This allows forcing a specific decoder, even when there are multiple with
+     * the same codec_id.
+     * Demuxing: Set by user via av_format_set_video_codec (NO direct access).
+     */
+    AVCodec *video_codec;
+
+    /**
+     * Forced audio codec.
+     * This allows forcing a specific decoder, even when there are multiple with
+     * the same codec_id.
+     * Demuxing: Set by user via av_format_set_audio_codec (NO direct access).
+     */
+    AVCodec *audio_codec;
+
+    /**
+     * Forced subtitle codec.
+     * This allows forcing a specific decoder, even when there are multiple with
+     * the same codec_id.
+     * Demuxing: Set by user via av_format_set_subtitle_codec (NO direct access).
+     */
+    AVCodec *subtitle_codec;
+} AVFormatContext;
+
+int av_format_get_probe_score(const AVFormatContext *s);
+AVCodec * av_format_get_video_codec(const AVFormatContext *s);
+void      av_format_set_video_codec(AVFormatContext *s, AVCodec *c);
+AVCodec * av_format_get_audio_codec(const AVFormatContext *s);
+void      av_format_set_audio_codec(AVFormatContext *s, AVCodec *c);
+AVCodec * av_format_get_subtitle_codec(const AVFormatContext *s);
+void      av_format_set_subtitle_codec(AVFormatContext *s, AVCodec *c);
+
+/**
+ * Returns the method used to set ctx->duration.
+ *
+ * @return AVFMT_DURATION_FROM_PTS, AVFMT_DURATION_FROM_STREAM, or AVFMT_DURATION_FROM_BITRATE.
+ */
+enum AVDurationEstimationMethod av_fmt_ctx_get_duration_estimation_method(const AVFormatContext* ctx);
+
+typedef struct AVPacketList {
+    AVPacket pkt;
+    struct AVPacketList *next;
+} AVPacketList;
+
+
+/**
+ * @defgroup lavf_core Core functions
+ * @ingroup libavf
+ *
+ * Functions for querying libavformat capabilities, allocating core structures,
+ * etc.
+ * @{
+ */
+
+/**
+ * Return the LIBAVFORMAT_VERSION_INT constant.
+ */
+unsigned avformat_version(void);
+
+/**
+ * Return the libavformat build-time configuration.
+ */
+const char *avformat_configuration(void);
+
+/**
+ * Return the libavformat license.
+ */
+const char *avformat_license(void);
+
+/**
+ * Initialize libavformat and register all the muxers, demuxers and
+ * protocols. If you do not call this function, then you can select
+ * exactly which formats you want to support.
+ *
+ * @see av_register_input_format()
+ * @see av_register_output_format()
+ */
+void av_register_all(void);
+
+void av_register_input_format(AVInputFormat *format);
+void av_register_output_format(AVOutputFormat *format);
+
+/**
+ * Do global initialization of network components. This is optional,
+ * but recommended, since it avoids the overhead of implicitly
+ * doing the setup for each session.
+ *
+ * Calling this function will become mandatory if using network
+ * protocols at some major version bump.
+ */
+int avformat_network_init(void);
+
+/**
+ * Undo the initialization done by avformat_network_init.
+ */
+int avformat_network_deinit(void);
+
+/**
+ * If f is NULL, returns the first registered input format,
+ * if f is non-NULL, returns the next registered input format after f
+ * or NULL if f is the last one.
+ */
+AVInputFormat  *av_iformat_next(AVInputFormat  *f);
+
+/**
+ * If f is NULL, returns the first registered output format,
+ * if f is non-NULL, returns the next registered output format after f
+ * or NULL if f is the last one.
+ */
+AVOutputFormat *av_oformat_next(AVOutputFormat *f);
+
+/**
+ * Allocate an AVFormatContext.
+ * avformat_free_context() can be used to free the context and everything
+ * allocated by the framework within it.
+ */
+AVFormatContext *avformat_alloc_context(void);
+
+/**
+ * Free an AVFormatContext and all its streams.
+ * @param s context to free
+ */
+void avformat_free_context(AVFormatContext *s);
+
+/**
+ * Get the AVClass for AVFormatContext. It can be used in combination with
+ * AV_OPT_SEARCH_FAKE_OBJ for examining options.
+ *
+ * @see av_opt_find().
+ */
+const AVClass *avformat_get_class(void);
+
+/**
+ * Add a new stream to a media file.
+ *
+ * When demuxing, it is called by the demuxer in read_header(). If the
+ * flag AVFMTCTX_NOHEADER is set in s.ctx_flags, then it may also
+ * be called in read_packet().
+ *
+ * When muxing, should be called by the user before avformat_write_header().
+ *
+ * User is required to call avcodec_close() and avformat_free_context() to
+ * clean up the allocation by avformat_new_stream().
+ *
+ * @param c If non-NULL, the AVCodecContext corresponding to the new stream
+ * will be initialized to use this codec. This is needed for e.g. codec-specific
+ * defaults to be set, so codec should be provided if it is known.
+ *
+ * @return newly created stream or NULL on error.
+ */
+AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c);
+
+AVProgram *av_new_program(AVFormatContext *s, int id);
+
+/**
+ * @}
+ */
+
+
+#if FF_API_ALLOC_OUTPUT_CONTEXT
+/**
+ * @deprecated deprecated in favor of avformat_alloc_output_context2()
+ */
+attribute_deprecated
+AVFormatContext *avformat_alloc_output_context(const char *format,
+                                               AVOutputFormat *oformat,
+                                               const char *filename);
+#endif
+
+/**
+ * Allocate an AVFormatContext for an output format.
+ * avformat_free_context() can be used to free the context and
+ * everything allocated by the framework within it.
+ *
+ * @param *ctx is set to the created format context, or to NULL in
+ * case of failure
+ * @param oformat format to use for allocating the context, if NULL
+ * format_name and filename are used instead
+ * @param format_name the name of output format to use for allocating the
+ * context, if NULL filename is used instead
+ * @param filename the name of the filename to use for allocating the
+ * context, may be NULL
+ * @return >= 0 in case of success, a negative AVERROR code in case of
+ * failure
+ */
+int avformat_alloc_output_context2(AVFormatContext **ctx, AVOutputFormat *oformat,
+                                   const char *format_name, const char *filename);
+
+/**
+ * @addtogroup lavf_decoding
+ * @{
+ */
+
+/**
+ * Find AVInputFormat based on the short name of the input format.
+ */
+AVInputFormat *av_find_input_format(const char *short_name);
+
+/**
+ * Guess the file format.
+ *
+ * @param is_opened Whether the file is already opened; determines whether
+ *                  demuxers with or without AVFMT_NOFILE are probed.
+ */
+AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
+
+/**
+ * Guess the file format.
+ *
+ * @param is_opened Whether the file is already opened; determines whether
+ *                  demuxers with or without AVFMT_NOFILE are probed.
+ * @param score_max A probe score larger that this is required to accept a
+ *                  detection, the variable is set to the actual detection
+ *                  score afterwards.
+ *                  If the score is <= AVPROBE_SCORE_MAX / 4 it is recommended
+ *                  to retry with a larger probe buffer.
+ */
+AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, int *score_max);
+
+/**
+ * Guess the file format.
+ *
+ * @param is_opened Whether the file is already opened; determines whether
+ *                  demuxers with or without AVFMT_NOFILE are probed.
+ * @param score_ret The score of the best detection.
+ */
+AVInputFormat *av_probe_input_format3(AVProbeData *pd, int is_opened, int *score_ret);
+
+/**
+ * Probe a bytestream to determine the input format. Each time a probe returns
+ * with a score that is too low, the probe buffer size is increased and another
+ * attempt is made. When the maximum probe size is reached, the input format
+ * with the highest score is returned.
+ *
+ * @param pb the bytestream to probe
+ * @param fmt the input format is put here
+ * @param filename the filename of the stream
+ * @param logctx the log context
+ * @param offset the offset within the bytestream to probe from
+ * @param max_probe_size the maximum probe buffer size (zero for default)
+ * @return the score in case of success, a negative value corresponding to an
+ *         the maximal score is AVPROBE_SCORE_MAX
+ * AVERROR code otherwise
+ */
+int av_probe_input_buffer2(AVIOContext *pb, AVInputFormat **fmt,
+                           const char *filename, void *logctx,
+                           unsigned int offset, unsigned int max_probe_size);
+
+/**
+ * Like av_probe_input_buffer2() but returns 0 on success
+ */
+int av_probe_input_buffer(AVIOContext *pb, AVInputFormat **fmt,
+                          const char *filename, void *logctx,
+                          unsigned int offset, unsigned int max_probe_size);
+
+/**
+ * Open an input stream and read the header. The codecs are not opened.
+ * The stream must be closed with avformat_close_input().
+ *
+ * @param ps Pointer to user-supplied AVFormatContext (allocated by avformat_alloc_context).
+ *           May be a pointer to NULL, in which case an AVFormatContext is allocated by this
+ *           function and written into ps.
+ *           Note that a user-supplied AVFormatContext will be freed on failure.
+ * @param filename Name of the stream to open.
+ * @param fmt If non-NULL, this parameter forces a specific input format.
+ *            Otherwise the format is autodetected.
+ * @param options  A dictionary filled with AVFormatContext and demuxer-private options.
+ *                 On return this parameter will be destroyed and replaced with a dict containing
+ *                 options that were not found. May be NULL.
+ *
+ * @return 0 on success, a negative AVERROR on failure.
+ *
+ * @note If you want to use custom IO, preallocate the format context and set its pb field.
+ */
+int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options);
+
+attribute_deprecated
+int av_demuxer_open(AVFormatContext *ic);
+
+#if FF_API_FORMAT_PARAMETERS
+/**
+ * Read packets of a media file to get stream information. This
+ * is useful for file formats with no headers such as MPEG. This
+ * function also computes the real framerate in case of MPEG-2 repeat
+ * frame mode.
+ * The logical file position is not changed by this function;
+ * examined packets may be buffered for later processing.
+ *
+ * @param ic media file handle
+ * @return >=0 if OK, AVERROR_xxx on error
+ * @todo Let the user decide somehow what information is needed so that
+ *       we do not waste time getting stuff the user does not need.
+ *
+ * @deprecated use avformat_find_stream_info.
+ */
+attribute_deprecated
+int av_find_stream_info(AVFormatContext *ic);
+#endif
+
+/**
+ * Read packets of a media file to get stream information. This
+ * is useful for file formats with no headers such as MPEG. This
+ * function also computes the real framerate in case of MPEG-2 repeat
+ * frame mode.
+ * The logical file position is not changed by this function;
+ * examined packets may be buffered for later processing.
+ *
+ * @param ic media file handle
+ * @param options  If non-NULL, an ic.nb_streams long array of pointers to
+ *                 dictionaries, where i-th member contains options for
+ *                 codec corresponding to i-th stream.
+ *                 On return each dictionary will be filled with options that were not found.
+ * @return >=0 if OK, AVERROR_xxx on error
+ *
+ * @note this function isn't guaranteed to open all the codecs, so
+ *       options being non-empty at return is a perfectly normal behavior.
+ *
+ * @todo Let the user decide somehow what information is needed so that
+ *       we do not waste time getting stuff the user does not need.
+ */
+int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options);
+
+/**
+ * Find the programs which belong to a given stream.
+ *
+ * @param ic    media file handle
+ * @param last  the last found program, the search will start after this
+ *              program, or from the beginning if it is NULL
+ * @param s     stream index
+ * @return the next program which belongs to s, NULL if no program is found or
+ *         the last program is not among the programs of ic.
+ */
+AVProgram *av_find_program_from_stream(AVFormatContext *ic, AVProgram *last, int s);
+
+/**
+ * Find the "best" stream in the file.
+ * The best stream is determined according to various heuristics as the most
+ * likely to be what the user expects.
+ * If the decoder parameter is non-NULL, av_find_best_stream will find the
+ * default decoder for the stream's codec; streams for which no decoder can
+ * be found are ignored.
+ *
+ * @param ic                media file handle
+ * @param type              stream type: video, audio, subtitles, etc.
+ * @param wanted_stream_nb  user-requested stream number,
+ *                          or -1 for automatic selection
+ * @param related_stream    try to find a stream related (eg. in the same
+ *                          program) to this one, or -1 if none
+ * @param decoder_ret       if non-NULL, returns the decoder for the
+ *                          selected stream
+ * @param flags             flags; none are currently defined
+ * @return  the non-negative stream number in case of success,
+ *          AVERROR_STREAM_NOT_FOUND if no stream with the requested type
+ *          could be found,
+ *          AVERROR_DECODER_NOT_FOUND if streams were found but no decoder
+ * @note  If av_find_best_stream returns successfully and decoder_ret is not
+ *        NULL, then *decoder_ret is guaranteed to be set to a valid AVCodec.
+ */
+int av_find_best_stream(AVFormatContext *ic,
+                        enum AVMediaType type,
+                        int wanted_stream_nb,
+                        int related_stream,
+                        AVCodec **decoder_ret,
+                        int flags);
+
+#if FF_API_READ_PACKET
+/**
+ * @deprecated use AVFMT_FLAG_NOFILLIN | AVFMT_FLAG_NOPARSE to read raw
+ * unprocessed packets
+ *
+ * Read a transport packet from a media file.
+ *
+ * This function is obsolete and should never be used.
+ * Use av_read_frame() instead.
+ *
+ * @param s media file handle
+ * @param pkt is filled
+ * @return 0 if OK, AVERROR_xxx on error
+ */
+attribute_deprecated
+int av_read_packet(AVFormatContext *s, AVPacket *pkt);
+#endif
+
+/**
+ * Return the next frame of a stream.
+ * This function returns what is stored in the file, and does not validate
+ * that what is there are valid frames for the decoder. It will split what is
+ * stored in the file into frames and return one for each call. It will not
+ * omit invalid data between valid frames so as to give the decoder the maximum
+ * information possible for decoding.
+ *
+ * If pkt->buf is NULL, then the packet is valid until the next
+ * av_read_frame() or until avformat_close_input(). Otherwise the packet
+ * is valid indefinitely. In both cases the packet must be freed with
+ * av_free_packet when it is no longer needed. For video, the packet contains
+ * exactly one frame. For audio, it contains an integer number of frames if each
+ * frame has a known fixed size (e.g. PCM or ADPCM data). If the audio frames
+ * have a variable size (e.g. MPEG audio), then it contains one frame.
+ *
+ * pkt->pts, pkt->dts and pkt->duration are always set to correct
+ * values in AVStream.time_base units (and guessed if the format cannot
+ * provide them). pkt->pts can be AV_NOPTS_VALUE if the video format
+ * has B-frames, so it is better to rely on pkt->dts if you do not
+ * decompress the payload.
+ *
+ * @return 0 if OK, < 0 on error or end of file
+ */
+int av_read_frame(AVFormatContext *s, AVPacket *pkt);
+
+/**
+ * Seek to the keyframe at timestamp.
+ * 'timestamp' in 'stream_index'.
+ * @param stream_index If stream_index is (-1), a default
+ * stream is selected, and timestamp is automatically converted
+ * from AV_TIME_BASE units to the stream specific time_base.
+ * @param timestamp Timestamp in AVStream.time_base units
+ *        or, if no stream is specified, in AV_TIME_BASE units.
+ * @param flags flags which select direction and seeking mode
+ * @return >= 0 on success
+ */
+int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp,
+                  int flags);
+
+/**
+ * Seek to timestamp ts.
+ * Seeking will be done so that the point from which all active streams
+ * can be presented successfully will be closest to ts and within min/max_ts.
+ * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
+ *
+ * If flags contain AVSEEK_FLAG_BYTE, then all timestamps are in bytes and
+ * are the file position (this may not be supported by all demuxers).
+ * If flags contain AVSEEK_FLAG_FRAME, then all timestamps are in frames
+ * in the stream with stream_index (this may not be supported by all demuxers).
+ * Otherwise all timestamps are in units of the stream selected by stream_index
+ * or if stream_index is -1, in AV_TIME_BASE units.
+ * If flags contain AVSEEK_FLAG_ANY, then non-keyframes are treated as
+ * keyframes (this may not be supported by all demuxers).
+ * If flags contain AVSEEK_FLAG_BACKWARD, it is ignored.
+ *
+ * @param stream_index index of the stream which is used as time base reference
+ * @param min_ts smallest acceptable timestamp
+ * @param ts target timestamp
+ * @param max_ts largest acceptable timestamp
+ * @param flags flags
+ * @return >=0 on success, error code otherwise
+ *
+ * @note This is part of the new seek API which is still under construction.
+ *       Thus do not use this yet. It may change at any time, do not expect
+ *       ABI compatibility yet!
+ */
+int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
+
+/**
+ * Start playing a network-based stream (e.g. RTSP stream) at the
+ * current position.
+ */
+int av_read_play(AVFormatContext *s);
+
+/**
+ * Pause a network-based stream (e.g. RTSP stream).
+ *
+ * Use av_read_play() to resume it.
+ */
+int av_read_pause(AVFormatContext *s);
+
+#if FF_API_CLOSE_INPUT_FILE
+/**
+ * @deprecated use avformat_close_input()
+ * Close a media file (but not its codecs).
+ *
+ * @param s media file handle
+ */
+attribute_deprecated
+void av_close_input_file(AVFormatContext *s);
+#endif
+
+/**
+ * Close an opened input AVFormatContext. Free it and all its contents
+ * and set *s to NULL.
+ */
+void avformat_close_input(AVFormatContext **s);
+/**
+ * @}
+ */
+
+#if FF_API_NEW_STREAM
+/**
+ * Add a new stream to a media file.
+ *
+ * Can only be called in the read_header() function. If the flag
+ * AVFMTCTX_NOHEADER is in the format context, then new streams
+ * can be added in read_packet too.
+ *
+ * @param s media file handle
+ * @param id file-format-dependent stream ID
+ */
+attribute_deprecated
+AVStream *av_new_stream(AVFormatContext *s, int id);
+#endif
+
+#if FF_API_SET_PTS_INFO
+/**
+ * @deprecated this function is not supposed to be called outside of lavf
+ */
+attribute_deprecated
+void av_set_pts_info(AVStream *s, int pts_wrap_bits,
+                     unsigned int pts_num, unsigned int pts_den);
+#endif
+
+#define AVSEEK_FLAG_BACKWARD 1 ///< seek backward
+#define AVSEEK_FLAG_BYTE     2 ///< seeking based on position in bytes
+#define AVSEEK_FLAG_ANY      4 ///< seek to any frame, even non-keyframes
+#define AVSEEK_FLAG_FRAME    8 ///< seeking based on frame number
+
+/**
+ * @addtogroup lavf_encoding
+ * @{
+ */
+/**
+ * Allocate the stream private data and write the stream header to
+ * an output media file.
+ *
+ * @param s Media file handle, must be allocated with avformat_alloc_context().
+ *          Its oformat field must be set to the desired output format;
+ *          Its pb field must be set to an already opened AVIOContext.
+ * @param options  An AVDictionary filled with AVFormatContext and muxer-private options.
+ *                 On return this parameter will be destroyed and replaced with a dict containing
+ *                 options that were not found. May be NULL.
+ *
+ * @return 0 on success, negative AVERROR on failure.
+ *
+ * @see av_opt_find, av_dict_set, avio_open, av_oformat_next.
+ */
+int avformat_write_header(AVFormatContext *s, AVDictionary **options);
+
+/**
+ * Write a packet to an output media file.
+ *
+ * The packet shall contain one audio or video frame.
+ * The packet must be correctly interleaved according to the container
+ * specification, if not then av_interleaved_write_frame must be used.
+ *
+ * @param s media file handle
+ * @param pkt The packet, which contains the stream_index, buf/buf_size,
+ *            dts/pts, ...
+ *            This can be NULL (at any time, not just at the end), in
+ *            order to immediately flush data buffered within the muxer,
+ *            for muxers that buffer up data internally before writing it
+ *            to the output.
+ * @return < 0 on error, = 0 if OK, 1 if flushed and there is no more data to flush
+ */
+int av_write_frame(AVFormatContext *s, AVPacket *pkt);
+
+/**
+ * Write a packet to an output media file ensuring correct interleaving.
+ *
+ * The packet must contain one audio or video frame.
+ * If the packets are already correctly interleaved, the application should
+ * call av_write_frame() instead as it is slightly faster. It is also important
+ * to keep in mind that completely non-interleaved input will need huge amounts
+ * of memory to interleave with this, so it is preferable to interleave at the
+ * demuxer level.
+ *
+ * @param s media file handle
+ * @param pkt The packet containing the data to be written. pkt->buf must be set
+ * to a valid AVBufferRef describing the packet data. Libavformat takes
+ * ownership of this reference and will unref it when it sees fit. The caller
+ * must not access the data through this reference after this function returns.
+ * This can be NULL (at any time, not just at the end), to flush the
+ * interleaving queues.
+ * Packet's @ref AVPacket.stream_index "stream_index" field must be set to the
+ * index of the corresponding stream in @ref AVFormatContext.streams
+ * "s.streams".
+ * It is very strongly recommended that timing information (@ref AVPacket.pts
+ * "pts", @ref AVPacket.dts "dts" @ref AVPacket.duration "duration") is set to
+ * correct values.
+ *
+ * @return 0 on success, a negative AVERROR on error.
+ */
+int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt);
+
+/**
+ * Write the stream trailer to an output media file and free the
+ * file private data.
+ *
+ * May only be called after a successful call to avformat_write_header.
+ *
+ * @param s media file handle
+ * @return 0 if OK, AVERROR_xxx on error
+ */
+int av_write_trailer(AVFormatContext *s);
+
+/**
+ * Return the output format in the list of registered output formats
+ * which best matches the provided parameters, or return NULL if
+ * there is no match.
+ *
+ * @param short_name if non-NULL checks if short_name matches with the
+ * names of the registered formats
+ * @param filename if non-NULL checks if filename terminates with the
+ * extensions of the registered formats
+ * @param mime_type if non-NULL checks if mime_type matches with the
+ * MIME type of the registered formats
+ */
+AVOutputFormat *av_guess_format(const char *short_name,
+                                const char *filename,
+                                const char *mime_type);
+
+/**
+ * Guess the codec ID based upon muxer and filename.
+ */
+enum AVCodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name,
+                            const char *filename, const char *mime_type,
+                            enum AVMediaType type);
+
+/**
+ * Get timing information for the data currently output.
+ * The exact meaning of "currently output" depends on the format.
+ * It is mostly relevant for devices that have an internal buffer and/or
+ * work in real time.
+ * @param s          media file handle
+ * @param stream     stream in the media file
+ * @param[out] dts   DTS of the last packet output for the stream, in stream
+ *                   time_base units
+ * @param[out] wall  absolute time when that packet whas output,
+ *                   in microsecond
+ * @return  0 if OK, AVERROR(ENOSYS) if the format does not support it
+ * Note: some formats or devices may not allow to measure dts and wall
+ * atomically.
+ */
+int av_get_output_timestamp(struct AVFormatContext *s, int stream,
+                            int64_t *dts, int64_t *wall);
+
+
+/**
+ * @}
+ */
+
+
+/**
+ * @defgroup lavf_misc Utility functions
+ * @ingroup libavf
+ * @{
+ *
+ * Miscellaneous utility functions related to both muxing and demuxing
+ * (or neither).
+ */
+
+/**
+ * Send a nice hexadecimal dump of a buffer to the specified file stream.
+ *
+ * @param f The file stream pointer where the dump should be sent to.
+ * @param buf buffer
+ * @param size buffer size
+ *
+ * @see av_hex_dump_log, av_pkt_dump2, av_pkt_dump_log2
+ */
+void av_hex_dump(FILE *f, const uint8_t *buf, int size);
+
+/**
+ * Send a nice hexadecimal dump of a buffer to the log.
+ *
+ * @param avcl A pointer to an arbitrary struct of which the first field is a
+ * pointer to an AVClass struct.
+ * @param level The importance level of the message, lower values signifying
+ * higher importance.
+ * @param buf buffer
+ * @param size buffer size
+ *
+ * @see av_hex_dump, av_pkt_dump2, av_pkt_dump_log2
+ */
+void av_hex_dump_log(void *avcl, int level, const uint8_t *buf, int size);
+
+/**
+ * Send a nice dump of a packet to the specified file stream.
+ *
+ * @param f The file stream pointer where the dump should be sent to.
+ * @param pkt packet to dump
+ * @param dump_payload True if the payload must be displayed, too.
+ * @param st AVStream that the packet belongs to
+ */
+void av_pkt_dump2(FILE *f, AVPacket *pkt, int dump_payload, AVStream *st);
+
+
+/**
+ * Send a nice dump of a packet to the log.
+ *
+ * @param avcl A pointer to an arbitrary struct of which the first field is a
+ * pointer to an AVClass struct.
+ * @param level The importance level of the message, lower values signifying
+ * higher importance.
+ * @param pkt packet to dump
+ * @param dump_payload True if the payload must be displayed, too.
+ * @param st AVStream that the packet belongs to
+ */
+void av_pkt_dump_log2(void *avcl, int level, AVPacket *pkt, int dump_payload,
+                      AVStream *st);
+
+/**
+ * Get the AVCodecID for the given codec tag tag.
+ * If no codec id is found returns AV_CODEC_ID_NONE.
+ *
+ * @param tags list of supported codec_id-codec_tag pairs, as stored
+ * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag
+ */
+enum AVCodecID av_codec_get_id(const struct AVCodecTag * const *tags, unsigned int tag);
+
+/**
+ * Get the codec tag for the given codec id id.
+ * If no codec tag is found returns 0.
+ *
+ * @param tags list of supported codec_id-codec_tag pairs, as stored
+ * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag
+ */
+unsigned int av_codec_get_tag(const struct AVCodecTag * const *tags, enum AVCodecID id);
+
+/**
+ * Get the codec tag for the given codec id.
+ *
+ * @param tags list of supported codec_id - codec_tag pairs, as stored
+ * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag
+ * @param id codec id that should be searched for in the list
+ * @param tag A pointer to the found tag
+ * @return 0 if id was not found in tags, > 0 if it was found
+ */
+int av_codec_get_tag2(const struct AVCodecTag * const *tags, enum AVCodecID id,
+                      unsigned int *tag);
+
+int av_find_default_stream_index(AVFormatContext *s);
+
+/**
+ * Get the index for a specific timestamp.
+ * @param flags if AVSEEK_FLAG_BACKWARD then the returned index will correspond
+ *                 to the timestamp which is <= the requested one, if backward
+ *                 is 0, then it will be >=
+ *              if AVSEEK_FLAG_ANY seek to any frame, only keyframes otherwise
+ * @return < 0 if no such timestamp could be found
+ */
+int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
+
+/**
+ * Add an index entry into a sorted list. Update the entry if the list
+ * already contains it.
+ *
+ * @param timestamp timestamp in the time base of the given stream
+ */
+int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp,
+                       int size, int distance, int flags);
+
+
+/**
+ * Split a URL string into components.
+ *
+ * The pointers to buffers for storing individual components may be null,
+ * in order to ignore that component. Buffers for components not found are
+ * set to empty strings. If the port is not found, it is set to a negative
+ * value.
+ *
+ * @param proto the buffer for the protocol
+ * @param proto_size the size of the proto buffer
+ * @param authorization the buffer for the authorization
+ * @param authorization_size the size of the authorization buffer
+ * @param hostname the buffer for the host name
+ * @param hostname_size the size of the hostname buffer
+ * @param port_ptr a pointer to store the port number in
+ * @param path the buffer for the path
+ * @param path_size the size of the path buffer
+ * @param url the URL to split
+ */
+void av_url_split(char *proto,         int proto_size,
+                  char *authorization, int authorization_size,
+                  char *hostname,      int hostname_size,
+                  int *port_ptr,
+                  char *path,          int path_size,
+                  const char *url);
+
+
+void av_dump_format(AVFormatContext *ic,
+                    int index,
+                    const char *url,
+                    int is_output);
+
+/**
+ * Return in 'buf' the path with '%d' replaced by a number.
+ *
+ * Also handles the '%0nd' format where 'n' is the total number
+ * of digits and '%%'.
+ *
+ * @param buf destination buffer
+ * @param buf_size destination buffer size
+ * @param path numbered sequence string
+ * @param number frame number
+ * @return 0 if OK, -1 on format error
+ */
+int av_get_frame_filename(char *buf, int buf_size,
+                          const char *path, int number);
+
+/**
+ * Check whether filename actually is a numbered sequence generator.
+ *
+ * @param filename possible numbered sequence string
+ * @return 1 if a valid numbered sequence string, 0 otherwise
+ */
+int av_filename_number_test(const char *filename);
+
+/**
+ * Generate an SDP for an RTP session.
+ *
+ * Note, this overwrites the id values of AVStreams in the muxer contexts
+ * for getting unique dynamic payload types.
+ *
+ * @param ac array of AVFormatContexts describing the RTP streams. If the
+ *           array is composed by only one context, such context can contain
+ *           multiple AVStreams (one AVStream per RTP stream). Otherwise,
+ *           all the contexts in the array (an AVCodecContext per RTP stream)
+ *           must contain only one AVStream.
+ * @param n_files number of AVCodecContexts contained in ac
+ * @param buf buffer where the SDP will be stored (must be allocated by
+ *            the caller)
+ * @param size the size of the buffer
+ * @return 0 if OK, AVERROR_xxx on error
+ */
+int av_sdp_create(AVFormatContext *ac[], int n_files, char *buf, int size);
+
+/**
+ * Return a positive value if the given filename has one of the given
+ * extensions, 0 otherwise.
+ *
+ * @param extensions a comma-separated list of filename extensions
+ */
+int av_match_ext(const char *filename, const char *extensions);
+
+/**
+ * Test if the given container can store a codec.
+ *
+ * @param std_compliance standards compliance level, one of FF_COMPLIANCE_*
+ *
+ * @return 1 if codec with ID codec_id can be stored in ofmt, 0 if it cannot.
+ *         A negative number if this information is not available.
+ */
+int avformat_query_codec(AVOutputFormat *ofmt, enum AVCodecID codec_id, int std_compliance);
+
+/**
+ * @defgroup riff_fourcc RIFF FourCCs
+ * @{
+ * Get the tables mapping RIFF FourCCs to libavcodec AVCodecIDs. The tables are
+ * meant to be passed to av_codec_get_id()/av_codec_get_tag() as in the
+ * following code:
+ * @code
+ * uint32_t tag = MKTAG('H', '2', '6', '4');
+ * const struct AVCodecTag *table[] = { avformat_get_riff_video_tags(), 0 };
+ * enum AVCodecID id = av_codec_get_id(table, tag);
+ * @endcode
+ */
+/**
+ * @return the table mapping RIFF FourCCs for video to libavcodec AVCodecID.
+ */
+const struct AVCodecTag *avformat_get_riff_video_tags(void);
+/**
+ * @return the table mapping RIFF FourCCs for audio to AVCodecID.
+ */
+const struct AVCodecTag *avformat_get_riff_audio_tags(void);
+
+/**
+ * @}
+ */
+
+/**
+ * Guess the sample aspect ratio of a frame, based on both the stream and the
+ * frame aspect ratio.
+ *
+ * Since the frame aspect ratio is set by the codec but the stream aspect ratio
+ * is set by the demuxer, these two may not be equal. This function tries to
+ * return the value that you should use if you would like to display the frame.
+ *
+ * Basic logic is to use the stream aspect ratio if it is set to something sane
+ * otherwise use the frame aspect ratio. This way a container setting, which is
+ * usually easy to modify can override the coded value in the frames.
+ *
+ * @param format the format context which the stream is part of
+ * @param stream the stream which the frame is part of
+ * @param frame the frame with the aspect ratio to be determined
+ * @return the guessed (valid) sample_aspect_ratio, 0/1 if no idea
+ */
+AVRational av_guess_sample_aspect_ratio(AVFormatContext *format, AVStream *stream, AVFrame *frame);
+
+/**
+ * Guess the frame rate, based on both the container and codec information.
+ *
+ * @param ctx the format context which the stream is part of
+ * @param stream the stream which the frame is part of
+ * @param frame the frame for which the frame rate should be determined, may be NULL
+ * @return the guessed (valid) frame rate, 0/1 if no idea
+ */
+AVRational av_guess_frame_rate(AVFormatContext *ctx, AVStream *stream, AVFrame *frame);
+
+/**
+ * Check if the stream st contained in s is matched by the stream specifier
+ * spec.
+ *
+ * See the "stream specifiers" chapter in the documentation for the syntax
+ * of spec.
+ *
+ * @return  >0 if st is matched by spec;
+ *          0  if st is not matched by spec;
+ *          AVERROR code if spec is invalid
+ *
+ * @note  A stream specifier can match several streams in the format.
+ */
+int avformat_match_stream_specifier(AVFormatContext *s, AVStream *st,
+                                    const char *spec);
+
+int avformat_queue_attached_pictures(AVFormatContext *s);
+
+
+/**
+ * @}
+ */
+
+#endif /* AVFORMAT_AVFORMAT_H */

+ 481 - 0
wave420l/code/ffmpeg/include/libavformat/avio.h

@@ -0,0 +1,481 @@
+/*
+ * copyright (c) 2001 Fabrice Bellard
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#ifndef AVFORMAT_AVIO_H
+#define AVFORMAT_AVIO_H
+
+/**
+ * @file
+ * @ingroup lavf_io
+ * Buffered I/O operations
+ */
+
+#include <stdint.h>
+
+#include "libavutil/common.h"
+#include "libavutil/dict.h"
+#include "libavutil/log.h"
+
+#include "libavformat/version.h"
+
+
+#define AVIO_SEEKABLE_NORMAL 0x0001 /**< Seeking works like for a local file */
+
+/**
+ * Callback for checking whether to abort blocking functions.
+ * AVERROR_EXIT is returned in this case by the interrupted
+ * function. During blocking operations, callback is called with
+ * opaque as parameter. If the callback returns 1, the
+ * blocking operation will be aborted.
+ *
+ * No members can be added to this struct without a major bump, if
+ * new elements have been added after this struct in AVFormatContext
+ * or AVIOContext.
+ */
+typedef struct AVIOInterruptCB {
+    int (*callback)(void*);
+    void *opaque;
+} AVIOInterruptCB;
+
+/**
+ * Bytestream IO Context.
+ * New fields can be added to the end with minor version bumps.
+ * Removal, reordering and changes to existing fields require a major
+ * version bump.
+ * sizeof(AVIOContext) must not be used outside libav*.
+ *
+ * @note None of the function pointers in AVIOContext should be called
+ *       directly, they should only be set by the client application
+ *       when implementing custom I/O. Normally these are set to the
+ *       function pointers specified in avio_alloc_context()
+ */
+typedef struct AVIOContext {
+    /**
+     * A class for private options.
+     *
+     * If this AVIOContext is created by avio_open2(), av_class is set and
+     * passes the options down to protocols.
+     *
+     * If this AVIOContext is manually allocated, then av_class may be set by
+     * the caller.
+     *
+     * warning -- this field can be NULL, be sure to not pass this AVIOContext
+     * to any av_opt_* functions in that case.
+     */
+    const AVClass *av_class;
+    unsigned char *buffer;  /**< Start of the buffer. */
+    int buffer_size;        /**< Maximum buffer size */
+    unsigned char *buf_ptr; /**< Current position in the buffer */
+    unsigned char *buf_end; /**< End of the data, may be less than
+                                 buffer+buffer_size if the read function returned
+                                 less data than requested, e.g. for streams where
+                                 no more data has been received yet. */
+    void *opaque;           /**< A private pointer, passed to the read/write/seek/...
+                                 functions. */
+    int (*read_packet)(void *opaque, uint8_t *buf, int buf_size);
+    int (*write_packet)(void *opaque, uint8_t *buf, int buf_size);
+    int64_t (*seek)(void *opaque, int64_t offset, int whence);
+    int64_t pos;            /**< position in the file of the current buffer */
+    int must_flush;         /**< true if the next seek should flush */
+    int eof_reached;        /**< true if eof reached */
+    int write_flag;         /**< true if open for writing */
+    int max_packet_size;
+    unsigned long checksum;
+    unsigned char *checksum_ptr;
+    unsigned long (*update_checksum)(unsigned long checksum, const uint8_t *buf, unsigned int size);
+    int error;              /**< contains the error code or 0 if no error happened */
+    /**
+     * Pause or resume playback for network streaming protocols - e.g. MMS.
+     */
+    int (*read_pause)(void *opaque, int pause);
+    /**
+     * Seek to a given timestamp in stream with the specified stream_index.
+     * Needed for some network streaming protocols which don't support seeking
+     * to byte position.
+     */
+    int64_t (*read_seek)(void *opaque, int stream_index,
+                         int64_t timestamp, int flags);
+    /**
+     * A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
+     */
+    int seekable;
+
+    /**
+     * max filesize, used to limit allocations
+     * This field is internal to libavformat and access from outside is not allowed.
+     */
+    int64_t maxsize;
+
+    /**
+     * avio_read and avio_write should if possible be satisfied directly
+     * instead of going through a buffer, and avio_seek will always
+     * call the underlying seek function directly.
+     */
+    int direct;
+
+    /**
+     * Bytes read statistic
+     * This field is internal to libavformat and access from outside is not allowed.
+     */
+    int64_t bytes_read;
+
+    /**
+     * seek statistic
+     * This field is internal to libavformat and access from outside is not allowed.
+     */
+    int seek_count;
+
+    /**
+     * writeout statistic
+     * This field is internal to libavformat and access from outside is not allowed.
+     */
+    int writeout_count;
+} AVIOContext;
+
+/* unbuffered I/O */
+
+/**
+ * Return AVIO_FLAG_* access flags corresponding to the access permissions
+ * of the resource in url, or a negative value corresponding to an
+ * AVERROR code in case of failure. The returned access flags are
+ * masked by the value in flags.
+ *
+ * @note This function is intrinsically unsafe, in the sense that the
+ * checked resource may change its existence or permission status from
+ * one call to another. Thus you should not trust the returned value,
+ * unless you are sure that no other processes are accessing the
+ * checked resource.
+ */
+int avio_check(const char *url, int flags);
+
+/**
+ * Allocate and initialize an AVIOContext for buffered I/O. It must be later
+ * freed with av_free().
+ *
+ * @param buffer Memory block for input/output operations via AVIOContext.
+ *        The buffer must be allocated with av_malloc() and friends.
+ * @param buffer_size The buffer size is very important for performance.
+ *        For protocols with fixed blocksize it should be set to this blocksize.
+ *        For others a typical size is a cache page, e.g. 4kb.
+ * @param write_flag Set to 1 if the buffer should be writable, 0 otherwise.
+ * @param opaque An opaque pointer to user-specific data.
+ * @param read_packet  A function for refilling the buffer, may be NULL.
+ * @param write_packet A function for writing the buffer contents, may be NULL.
+ *        The function may not change the input buffers content.
+ * @param seek A function for seeking to specified byte position, may be NULL.
+ *
+ * @return Allocated AVIOContext or NULL on failure.
+ */
+AVIOContext *avio_alloc_context(
+                  unsigned char *buffer,
+                  int buffer_size,
+                  int write_flag,
+                  void *opaque,
+                  int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
+                  int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
+                  int64_t (*seek)(void *opaque, int64_t offset, int whence));
+
+void avio_w8(AVIOContext *s, int b);
+void avio_write(AVIOContext *s, const unsigned char *buf, int size);
+void avio_wl64(AVIOContext *s, uint64_t val);
+void avio_wb64(AVIOContext *s, uint64_t val);
+void avio_wl32(AVIOContext *s, unsigned int val);
+void avio_wb32(AVIOContext *s, unsigned int val);
+void avio_wl24(AVIOContext *s, unsigned int val);
+void avio_wb24(AVIOContext *s, unsigned int val);
+void avio_wl16(AVIOContext *s, unsigned int val);
+void avio_wb16(AVIOContext *s, unsigned int val);
+
+/**
+ * Write a NULL-terminated string.
+ * @return number of bytes written.
+ */
+int avio_put_str(AVIOContext *s, const char *str);
+
+/**
+ * Convert an UTF-8 string to UTF-16LE and write it.
+ * @return number of bytes written.
+ */
+int avio_put_str16le(AVIOContext *s, const char *str);
+
+/**
+ * Passing this as the "whence" parameter to a seek function causes it to
+ * return the filesize without seeking anywhere. Supporting this is optional.
+ * If it is not supported then the seek function will return <0.
+ */
+#define AVSEEK_SIZE 0x10000
+
+/**
+ * Oring this flag as into the "whence" parameter to a seek function causes it to
+ * seek by any means (like reopening and linear reading) or other normally unreasonable
+ * means that can be extremely slow.
+ * This may be ignored by the seek code.
+ */
+#define AVSEEK_FORCE 0x20000
+
+/**
+ * fseek() equivalent for AVIOContext.
+ * @return new position or AVERROR.
+ */
+int64_t avio_seek(AVIOContext *s, int64_t offset, int whence);
+
+/**
+ * Skip given number of bytes forward
+ * @return new position or AVERROR.
+ */
+int64_t avio_skip(AVIOContext *s, int64_t offset);
+
+/**
+ * ftell() equivalent for AVIOContext.
+ * @return position or AVERROR.
+ */
+static av_always_inline int64_t avio_tell(AVIOContext *s)
+{
+    return avio_seek(s, 0, SEEK_CUR);
+}
+
+/**
+ * Get the filesize.
+ * @return filesize or AVERROR
+ */
+int64_t avio_size(AVIOContext *s);
+
+/**
+ * feof() equivalent for AVIOContext.
+ * @return non zero if and only if end of file
+ */
+int url_feof(AVIOContext *s);
+
+/** @warning currently size is limited */
+int avio_printf(AVIOContext *s, const char *fmt, ...) av_printf_format(2, 3);
+
+/**
+ * Force flushing of buffered data to the output s.
+ *
+ * Force the buffered data to be immediately written to the output,
+ * without to wait to fill the internal buffer.
+ */
+void avio_flush(AVIOContext *s);
+
+/**
+ * Read size bytes from AVIOContext into buf.
+ * @return number of bytes read or AVERROR
+ */
+int avio_read(AVIOContext *s, unsigned char *buf, int size);
+
+/**
+ * @name Functions for reading from AVIOContext
+ * @{
+ *
+ * @note return 0 if EOF, so you cannot use it if EOF handling is
+ *       necessary
+ */
+int          avio_r8  (AVIOContext *s);
+unsigned int avio_rl16(AVIOContext *s);
+unsigned int avio_rl24(AVIOContext *s);
+unsigned int avio_rl32(AVIOContext *s);
+uint64_t     avio_rl64(AVIOContext *s);
+unsigned int avio_rb16(AVIOContext *s);
+unsigned int avio_rb24(AVIOContext *s);
+unsigned int avio_rb32(AVIOContext *s);
+uint64_t     avio_rb64(AVIOContext *s);
+/**
+ * @}
+ */
+
+/**
+ * Read a string from pb into buf. The reading will terminate when either
+ * a NULL character was encountered, maxlen bytes have been read, or nothing
+ * more can be read from pb. The result is guaranteed to be NULL-terminated, it
+ * will be truncated if buf is too small.
+ * Note that the string is not interpreted or validated in any way, it
+ * might get truncated in the middle of a sequence for multi-byte encodings.
+ *
+ * @return number of bytes read (is always <= maxlen).
+ * If reading ends on EOF or error, the return value will be one more than
+ * bytes actually read.
+ */
+int avio_get_str(AVIOContext *pb, int maxlen, char *buf, int buflen);
+
+/**
+ * Read a UTF-16 string from pb and convert it to UTF-8.
+ * The reading will terminate when either a null or invalid character was
+ * encountered or maxlen bytes have been read.
+ * @return number of bytes read (is always <= maxlen)
+ */
+int avio_get_str16le(AVIOContext *pb, int maxlen, char *buf, int buflen);
+int avio_get_str16be(AVIOContext *pb, int maxlen, char *buf, int buflen);
+
+
+/**
+ * @name URL open modes
+ * The flags argument to avio_open must be one of the following
+ * constants, optionally ORed with other flags.
+ * @{
+ */
+#define AVIO_FLAG_READ  1                                      /**< read-only */
+#define AVIO_FLAG_WRITE 2                                      /**< write-only */
+#define AVIO_FLAG_READ_WRITE (AVIO_FLAG_READ|AVIO_FLAG_WRITE)  /**< read-write pseudo flag */
+/**
+ * @}
+ */
+
+/**
+ * Use non-blocking mode.
+ * If this flag is set, operations on the context will return
+ * AVERROR(EAGAIN) if they can not be performed immediately.
+ * If this flag is not set, operations on the context will never return
+ * AVERROR(EAGAIN).
+ * Note that this flag does not affect the opening/connecting of the
+ * context. Connecting a protocol will always block if necessary (e.g. on
+ * network protocols) but never hang (e.g. on busy devices).
+ * Warning: non-blocking protocols is work-in-progress; this flag may be
+ * silently ignored.
+ */
+#define AVIO_FLAG_NONBLOCK 8
+
+/**
+ * Use direct mode.
+ * avio_read and avio_write should if possible be satisfied directly
+ * instead of going through a buffer, and avio_seek will always
+ * call the underlying seek function directly.
+ */
+#define AVIO_FLAG_DIRECT 0x8000
+
+/**
+ * Create and initialize a AVIOContext for accessing the
+ * resource indicated by url.
+ * @note When the resource indicated by url has been opened in
+ * read+write mode, the AVIOContext can be used only for writing.
+ *
+ * @param s Used to return the pointer to the created AVIOContext.
+ * In case of failure the pointed to value is set to NULL.
+ * @param flags flags which control how the resource indicated by url
+ * is to be opened
+ * @return >= 0 in case of success, a negative value corresponding to an
+ * AVERROR code in case of failure
+ */
+int avio_open(AVIOContext **s, const char *url, int flags);
+
+/**
+ * Create and initialize a AVIOContext for accessing the
+ * resource indicated by url.
+ * @note When the resource indicated by url has been opened in
+ * read+write mode, the AVIOContext can be used only for writing.
+ *
+ * @param s Used to return the pointer to the created AVIOContext.
+ * In case of failure the pointed to value is set to NULL.
+ * @param flags flags which control how the resource indicated by url
+ * is to be opened
+ * @param int_cb an interrupt callback to be used at the protocols level
+ * @param options  A dictionary filled with protocol-private options. On return
+ * this parameter will be destroyed and replaced with a dict containing options
+ * that were not found. May be NULL.
+ * @return >= 0 in case of success, a negative value corresponding to an
+ * AVERROR code in case of failure
+ */
+int avio_open2(AVIOContext **s, const char *url, int flags,
+               const AVIOInterruptCB *int_cb, AVDictionary **options);
+
+/**
+ * Close the resource accessed by the AVIOContext s and free it.
+ * This function can only be used if s was opened by avio_open().
+ *
+ * The internal buffer is automatically flushed before closing the
+ * resource.
+ *
+ * @return 0 on success, an AVERROR < 0 on error.
+ * @see avio_closep
+ */
+int avio_close(AVIOContext *s);
+
+/**
+ * Close the resource accessed by the AVIOContext *s, free it
+ * and set the pointer pointing to it to NULL.
+ * This function can only be used if s was opened by avio_open().
+ *
+ * The internal buffer is automatically flushed before closing the
+ * resource.
+ *
+ * @return 0 on success, an AVERROR < 0 on error.
+ * @see avio_close
+ */
+int avio_closep(AVIOContext **s);
+
+
+/**
+ * Open a write only memory stream.
+ *
+ * @param s new IO context
+ * @return zero if no error.
+ */
+int avio_open_dyn_buf(AVIOContext **s);
+
+/**
+ * Return the written size and a pointer to the buffer. The buffer
+ * must be freed with av_free().
+ * Padding of FF_INPUT_BUFFER_PADDING_SIZE is added to the buffer.
+ *
+ * @param s IO context
+ * @param pbuffer pointer to a byte buffer
+ * @return the length of the byte buffer
+ */
+int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer);
+
+/**
+ * Iterate through names of available protocols.
+ *
+ * @param opaque A private pointer representing current protocol.
+ *        It must be a pointer to NULL on first iteration and will
+ *        be updated by successive calls to avio_enum_protocols.
+ * @param output If set to 1, iterate over output protocols,
+ *               otherwise over input protocols.
+ *
+ * @return A static string containing the name of current protocol or NULL
+ */
+const char *avio_enum_protocols(void **opaque, int output);
+
+/**
+ * Pause and resume playing - only meaningful if using a network streaming
+ * protocol (e.g. MMS).
+ * @param pause 1 for pause, 0 for resume
+ */
+int     avio_pause(AVIOContext *h, int pause);
+
+/**
+ * Seek to a given timestamp relative to some component stream.
+ * Only meaningful if using a network streaming protocol (e.g. MMS.).
+ * @param stream_index The stream index that the timestamp is relative to.
+ *        If stream_index is (-1) the timestamp should be in AV_TIME_BASE
+ *        units from the beginning of the presentation.
+ *        If a stream_index >= 0 is used and the protocol does not support
+ *        seeking based on component streams, the call will fail.
+ * @param timestamp timestamp in AVStream.time_base units
+ *        or if there is no stream specified then in AV_TIME_BASE units.
+ * @param flags Optional combination of AVSEEK_FLAG_BACKWARD, AVSEEK_FLAG_BYTE
+ *        and AVSEEK_FLAG_ANY. The protocol may silently ignore
+ *        AVSEEK_FLAG_BACKWARD and AVSEEK_FLAG_ANY, but AVSEEK_FLAG_BYTE will
+ *        fail if used and not supported.
+ * @return >= 0 on success
+ * @see AVInputFormat::read_seek
+ */
+int64_t avio_seek_time(AVIOContext *h, int stream_index,
+                       int64_t timestamp, int flags);
+
+#endif /* AVFORMAT_AVIO_H */

+ 76 - 0
wave420l/code/ffmpeg/include/libavformat/version.h

@@ -0,0 +1,76 @@
+/*
+ * Version macros.
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVFORMAT_VERSION_H
+#define AVFORMAT_VERSION_H
+
+/**
+ * @file
+ * @ingroup libavf
+ * Libavformat version macros
+ */
+
+#include "libavutil/avutil.h"
+
+#define LIBAVFORMAT_VERSION_MAJOR 55
+#define LIBAVFORMAT_VERSION_MINOR 19
+#define LIBAVFORMAT_VERSION_MICRO 104
+
+#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
+                                               LIBAVFORMAT_VERSION_MINOR, \
+                                               LIBAVFORMAT_VERSION_MICRO)
+#define LIBAVFORMAT_VERSION     AV_VERSION(LIBAVFORMAT_VERSION_MAJOR,   \
+                                           LIBAVFORMAT_VERSION_MINOR,   \
+                                           LIBAVFORMAT_VERSION_MICRO)
+#define LIBAVFORMAT_BUILD       LIBAVFORMAT_VERSION_INT
+
+#define LIBAVFORMAT_IDENT       "Lavf" AV_STRINGIFY(LIBAVFORMAT_VERSION)
+
+/**
+ * FF_API_* defines may be placed below to indicate public API that will be
+ * dropped at a future version bump. The defines themselves are not part of
+ * the public API and may change, break or disappear at any time.
+ */
+
+#ifndef FF_API_ALLOC_OUTPUT_CONTEXT
+#define FF_API_ALLOC_OUTPUT_CONTEXT    (LIBAVFORMAT_VERSION_MAJOR < 56)
+#endif
+#ifndef FF_API_FORMAT_PARAMETERS
+#define FF_API_FORMAT_PARAMETERS       (LIBAVFORMAT_VERSION_MAJOR < 56)
+#endif
+#ifndef FF_API_NEW_STREAM
+#define FF_API_NEW_STREAM              (LIBAVFORMAT_VERSION_MAJOR < 56)
+#endif
+#ifndef FF_API_SET_PTS_INFO
+#define FF_API_SET_PTS_INFO            (LIBAVFORMAT_VERSION_MAJOR < 56)
+#endif
+#ifndef FF_API_CLOSE_INPUT_FILE
+#define FF_API_CLOSE_INPUT_FILE        (LIBAVFORMAT_VERSION_MAJOR < 56)
+#endif
+#ifndef FF_API_READ_PACKET
+#define FF_API_READ_PACKET             (LIBAVFORMAT_VERSION_MAJOR < 56)
+#endif
+#ifndef FF_API_ASS_SSA
+#define FF_API_ASS_SSA                 (LIBAVFORMAT_VERSION_MAJOR < 56)
+#endif
+#ifndef FF_API_R_FRAME_RATE
+#define FF_API_R_FRAME_RATE            1
+#endif
+#endif /* AVFORMAT_VERSION_H */

+ 52 - 0
wave420l/code/ffmpeg/include/libavutil/adler32.h

@@ -0,0 +1,52 @@
+/*
+ * copyright (c) 2006 Mans Rullgard
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_ADLER32_H
+#define AVUTIL_ADLER32_H
+
+#include <stdint.h>
+#include "attributes.h"
+
+/**
+ * @defgroup lavu_adler32 Adler32
+ * @ingroup lavu_crypto
+ * @{
+ */
+
+/**
+ * Calculate the Adler32 checksum of a buffer.
+ *
+ * Passing the return value to a subsequent av_adler32_update() call
+ * allows the checksum of multiple buffers to be calculated as though
+ * they were concatenated.
+ *
+ * @param adler initial checksum value
+ * @param buf   pointer to input buffer
+ * @param len   size of input buffer
+ * @return      updated checksum
+ */
+unsigned long av_adler32_update(unsigned long adler, const uint8_t *buf,
+                                unsigned int len) av_pure;
+
+/**
+ * @}
+ */
+
+#endif /* AVUTIL_ADLER32_H */

+ 65 - 0
wave420l/code/ffmpeg/include/libavutil/aes.h

@@ -0,0 +1,65 @@
+/*
+ * copyright (c) 2007 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_AES_H
+#define AVUTIL_AES_H
+
+#include <stdint.h>
+
+#include "attributes.h"
+#include "version.h"
+
+/**
+ * @defgroup lavu_aes AES
+ * @ingroup lavu_crypto
+ * @{
+ */
+
+extern const int av_aes_size;
+
+struct AVAES;
+
+/**
+ * Allocate an AVAES context.
+ */
+struct AVAES *av_aes_alloc(void);
+
+/**
+ * Initialize an AVAES context.
+ * @param key_bits 128, 192 or 256
+ * @param decrypt 0 for encryption, 1 for decryption
+ */
+int av_aes_init(struct AVAES *a, const uint8_t *key, int key_bits, int decrypt);
+
+/**
+ * Encrypt or decrypt a buffer using a previously initialized context.
+ * @param count number of 16 byte blocks
+ * @param dst destination array, can be equal to src
+ * @param src source array, can be equal to dst
+ * @param iv initialization vector for CBC mode, if NULL then ECB will be used
+ * @param decrypt 0 for encryption, 1 for decryption
+ */
+void av_aes_crypt(struct AVAES *a, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv, int decrypt);
+
+/**
+ * @}
+ */
+
+#endif /* AVUTIL_AES_H */

+ 160 - 0
wave420l/code/ffmpeg/include/libavutil/attributes.h

@@ -0,0 +1,160 @@
+/*
+ * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * Macro definitions for various function/variable attributes
+ */
+
+#ifndef AVUTIL_ATTRIBUTES_H
+#define AVUTIL_ATTRIBUTES_H
+
+#ifdef __GNUC__
+#    define AV_GCC_VERSION_AT_LEAST(x,y) (__GNUC__ > x || __GNUC__ == x && __GNUC_MINOR__ >= y)
+#else
+#    define AV_GCC_VERSION_AT_LEAST(x,y) 0
+#endif
+
+#ifndef av_always_inline
+#if AV_GCC_VERSION_AT_LEAST(3,1)
+#    define av_always_inline __attribute__((always_inline)) inline
+#elif defined(_MSC_VER)
+#    define av_always_inline __forceinline
+#else
+#    define av_always_inline inline
+#endif
+#endif
+
+#ifndef av_extern_inline
+#if defined(__ICL) && __ICL >= 1210 || defined(__GNUC_STDC_INLINE__)
+#    define av_extern_inline extern inline
+#else
+#    define av_extern_inline inline
+#endif
+#endif
+
+#if AV_GCC_VERSION_AT_LEAST(3,1)
+#    define av_noinline __attribute__((noinline))
+#elif defined(_MSC_VER)
+#    define av_noinline __declspec(noinline)
+#else
+#    define av_noinline
+#endif
+
+#if AV_GCC_VERSION_AT_LEAST(3,1)
+#    define av_pure __attribute__((pure))
+#else
+#    define av_pure
+#endif
+
+#if AV_GCC_VERSION_AT_LEAST(2,6)
+#    define av_const __attribute__((const))
+#else
+#    define av_const
+#endif
+
+#if AV_GCC_VERSION_AT_LEAST(4,3)
+#    define av_cold __attribute__((cold))
+#else
+#    define av_cold
+#endif
+
+#if AV_GCC_VERSION_AT_LEAST(4,1)
+#    define av_flatten __attribute__((flatten))
+#else
+#    define av_flatten
+#endif
+
+#if AV_GCC_VERSION_AT_LEAST(3,1)
+#    define attribute_deprecated __attribute__((deprecated))
+#elif defined(_MSC_VER)
+#    define attribute_deprecated __declspec(deprecated)
+#else
+#    define attribute_deprecated
+#endif
+
+/**
+ * Disable warnings about deprecated features
+ * This is useful for sections of code kept for backward compatibility and
+ * scheduled for removal.
+ */
+#ifndef AV_NOWARN_DEPRECATED
+#if AV_GCC_VERSION_AT_LEAST(4,6)
+#    define AV_NOWARN_DEPRECATED(code) \
+        _Pragma("GCC diagnostic push") \
+        _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") \
+        code \
+        _Pragma("GCC diagnostic pop")
+#elif defined(_MSC_VER)
+#    define AV_NOWARN_DEPRECATED(code) \
+        __pragma(warning(push)) \
+        __pragma(warning(disable : 4996)) \
+        code; \
+        __pragma(warning(pop))
+#else
+#    define AV_NOWARN_DEPRECATED(code) code
+#endif
+#endif
+
+
+#if defined(__GNUC__)
+#    define av_unused __attribute__((unused))
+#else
+#    define av_unused
+#endif
+
+/**
+ * Mark a variable as used and prevent the compiler from optimizing it
+ * away.  This is useful for variables accessed only from inline
+ * assembler without the compiler being aware.
+ */
+#if AV_GCC_VERSION_AT_LEAST(3,1)
+#    define av_used __attribute__((used))
+#else
+#    define av_used
+#endif
+
+#if AV_GCC_VERSION_AT_LEAST(3,3)
+#   define av_alias __attribute__((may_alias))
+#else
+#   define av_alias
+#endif
+
+#if defined(__GNUC__) && !defined(__INTEL_COMPILER) && !defined(__clang__)
+#    define av_uninit(x) x=x
+#else
+#    define av_uninit(x) x
+#endif
+
+#ifdef __GNUC__
+#    define av_builtin_constant_p __builtin_constant_p
+#    define av_printf_format(fmtpos, attrpos) __attribute__((__format__(__printf__, fmtpos, attrpos)))
+#else
+#    define av_builtin_constant_p(x) 0
+#    define av_printf_format(fmtpos, attrpos)
+#endif
+
+#if AV_GCC_VERSION_AT_LEAST(2,5)
+#    define av_noreturn __attribute__((noreturn))
+#else
+#    define av_noreturn
+#endif
+
+#endif /* AVUTIL_ATTRIBUTES_H */

+ 149 - 0
wave420l/code/ffmpeg/include/libavutil/audio_fifo.h

@@ -0,0 +1,149 @@
+/*
+ * Audio FIFO
+ * Copyright (c) 2012 Justin Ruggles <justin.ruggles@gmail.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * Audio FIFO Buffer
+ */
+
+#ifndef AVUTIL_AUDIO_FIFO_H
+#define AVUTIL_AUDIO_FIFO_H
+
+#include "avutil.h"
+#include "fifo.h"
+#include "samplefmt.h"
+
+/**
+ * @addtogroup lavu_audio
+ * @{
+ */
+
+/**
+ * Context for an Audio FIFO Buffer.
+ *
+ * - Operates at the sample level rather than the byte level.
+ * - Supports multiple channels with either planar or packed sample format.
+ * - Automatic reallocation when writing to a full buffer.
+ */
+typedef struct AVAudioFifo AVAudioFifo;
+
+/**
+ * Free an AVAudioFifo.
+ *
+ * @param af  AVAudioFifo to free
+ */
+void av_audio_fifo_free(AVAudioFifo *af);
+
+/**
+ * Allocate an AVAudioFifo.
+ *
+ * @param sample_fmt  sample format
+ * @param channels    number of channels
+ * @param nb_samples  initial allocation size, in samples
+ * @return            newly allocated AVAudioFifo, or NULL on error
+ */
+AVAudioFifo *av_audio_fifo_alloc(enum AVSampleFormat sample_fmt, int channels,
+                                 int nb_samples);
+
+/**
+ * Reallocate an AVAudioFifo.
+ *
+ * @param af          AVAudioFifo to reallocate
+ * @param nb_samples  new allocation size, in samples
+ * @return            0 if OK, or negative AVERROR code on failure
+ */
+int av_audio_fifo_realloc(AVAudioFifo *af, int nb_samples);
+
+/**
+ * Write data to an AVAudioFifo.
+ *
+ * The AVAudioFifo will be reallocated automatically if the available space
+ * is less than nb_samples.
+ *
+ * @see enum AVSampleFormat
+ * The documentation for AVSampleFormat describes the data layout.
+ *
+ * @param af          AVAudioFifo to write to
+ * @param data        audio data plane pointers
+ * @param nb_samples  number of samples to write
+ * @return            number of samples actually written, or negative AVERROR
+ *                    code on failure. If successful, the number of samples
+ *                    actually written will always be nb_samples.
+ */
+int av_audio_fifo_write(AVAudioFifo *af, void **data, int nb_samples);
+
+/**
+ * Read data from an AVAudioFifo.
+ *
+ * @see enum AVSampleFormat
+ * The documentation for AVSampleFormat describes the data layout.
+ *
+ * @param af          AVAudioFifo to read from
+ * @param data        audio data plane pointers
+ * @param nb_samples  number of samples to read
+ * @return            number of samples actually read, or negative AVERROR code
+ *                    on failure. The number of samples actually read will not
+ *                    be greater than nb_samples, and will only be less than
+ *                    nb_samples if av_audio_fifo_size is less than nb_samples.
+ */
+int av_audio_fifo_read(AVAudioFifo *af, void **data, int nb_samples);
+
+/**
+ * Drain data from an AVAudioFifo.
+ *
+ * Removes the data without reading it.
+ *
+ * @param af          AVAudioFifo to drain
+ * @param nb_samples  number of samples to drain
+ * @return            0 if OK, or negative AVERROR code on failure
+ */
+int av_audio_fifo_drain(AVAudioFifo *af, int nb_samples);
+
+/**
+ * Reset the AVAudioFifo buffer.
+ *
+ * This empties all data in the buffer.
+ *
+ * @param af  AVAudioFifo to reset
+ */
+void av_audio_fifo_reset(AVAudioFifo *af);
+
+/**
+ * Get the current number of samples in the AVAudioFifo available for reading.
+ *
+ * @param af  the AVAudioFifo to query
+ * @return    number of samples available for reading
+ */
+int av_audio_fifo_size(AVAudioFifo *af);
+
+/**
+ * Get the current number of samples in the AVAudioFifo available for writing.
+ *
+ * @param af  the AVAudioFifo to query
+ * @return    number of samples available for writing
+ */
+int av_audio_fifo_space(AVAudioFifo *af);
+
+/**
+ * @}
+ */
+
+#endif /* AVUTIL_AUDIO_FIFO_H */

+ 6 - 0
wave420l/code/ffmpeg/include/libavutil/audioconvert.h

@@ -0,0 +1,6 @@
+
+#include "version.h"
+
+#if FF_API_AUDIOCONVERT
+#include "channel_layout.h"
+#endif

+ 66 - 0
wave420l/code/ffmpeg/include/libavutil/avassert.h

@@ -0,0 +1,66 @@
+/*
+ * copyright (c) 2010 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * simple assert() macros that are a bit more flexible than ISO C assert().
+ * @author Michael Niedermayer <michaelni@gmx.at>
+ */
+
+#ifndef AVUTIL_AVASSERT_H
+#define AVUTIL_AVASSERT_H
+
+#include <stdlib.h>
+#include "avutil.h"
+#include "log.h"
+
+/**
+ * assert() equivalent, that is always enabled.
+ */
+#define av_assert0(cond) do {                                           \
+    if (!(cond)) {                                                      \
+        av_log(NULL, AV_LOG_PANIC, "Assertion %s failed at %s:%d\n",    \
+               AV_STRINGIFY(cond), __FILE__, __LINE__);                 \
+        abort();                                                        \
+    }                                                                   \
+} while (0)
+
+
+/**
+ * assert() equivalent, that does not lie in speed critical code.
+ * These asserts() thus can be enabled without fearing speedloss.
+ */
+#if defined(ASSERT_LEVEL) && ASSERT_LEVEL > 0
+#define av_assert1(cond) av_assert0(cond)
+#else
+#define av_assert1(cond) ((void)0)
+#endif
+
+
+/**
+ * assert() equivalent, that does lie in speed critical code.
+ */
+#if defined(ASSERT_LEVEL) && ASSERT_LEVEL > 1
+#define av_assert2(cond) av_assert0(cond)
+#else
+#define av_assert2(cond) ((void)0)
+#endif
+
+#endif /* AVUTIL_AVASSERT_H */

+ 8 - 0
wave420l/code/ffmpeg/include/libavutil/avconfig.h

@@ -0,0 +1,8 @@
+/* Generated by ffconf */
+#ifndef AVUTIL_AVCONFIG_H
+#define AVUTIL_AVCONFIG_H
+#define AV_HAVE_BIGENDIAN 0
+#define AV_HAVE_FAST_UNALIGNED 1
+#define AV_HAVE_INCOMPATIBLE_LIBAV_ABI 0
+#define AV_HAVE_INCOMPATIBLE_FORK_ABI 0
+#endif /* AVUTIL_AVCONFIG_H */

+ 302 - 0
wave420l/code/ffmpeg/include/libavutil/avstring.h

@@ -0,0 +1,302 @@
+/*
+ * Copyright (c) 2007 Mans Rullgard
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_AVSTRING_H
+#define AVUTIL_AVSTRING_H
+
+#include <stddef.h>
+#include "attributes.h"
+
+/**
+ * @addtogroup lavu_string
+ * @{
+ */
+
+/**
+ * Return non-zero if pfx is a prefix of str. If it is, *ptr is set to
+ * the address of the first character in str after the prefix.
+ *
+ * @param str input string
+ * @param pfx prefix to test
+ * @param ptr updated if the prefix is matched inside str
+ * @return non-zero if the prefix matches, zero otherwise
+ */
+int av_strstart(const char *str, const char *pfx, const char **ptr);
+
+/**
+ * Return non-zero if pfx is a prefix of str independent of case. If
+ * it is, *ptr is set to the address of the first character in str
+ * after the prefix.
+ *
+ * @param str input string
+ * @param pfx prefix to test
+ * @param ptr updated if the prefix is matched inside str
+ * @return non-zero if the prefix matches, zero otherwise
+ */
+int av_stristart(const char *str, const char *pfx, const char **ptr);
+
+/**
+ * Locate the first case-independent occurrence in the string haystack
+ * of the string needle.  A zero-length string needle is considered to
+ * match at the start of haystack.
+ *
+ * This function is a case-insensitive version of the standard strstr().
+ *
+ * @param haystack string to search in
+ * @param needle   string to search for
+ * @return         pointer to the located match within haystack
+ *                 or a null pointer if no match
+ */
+char *av_stristr(const char *haystack, const char *needle);
+
+/**
+ * Locate the first occurrence of the string needle in the string haystack
+ * where not more than hay_length characters are searched. A zero-length
+ * string needle is considered to match at the start of haystack.
+ *
+ * This function is a length-limited version of the standard strstr().
+ *
+ * @param haystack   string to search in
+ * @param needle     string to search for
+ * @param hay_length length of string to search in
+ * @return           pointer to the located match within haystack
+ *                   or a null pointer if no match
+ */
+char *av_strnstr(const char *haystack, const char *needle, size_t hay_length);
+
+/**
+ * Copy the string src to dst, but no more than size - 1 bytes, and
+ * null-terminate dst.
+ *
+ * This function is the same as BSD strlcpy().
+ *
+ * @param dst destination buffer
+ * @param src source string
+ * @param size size of destination buffer
+ * @return the length of src
+ *
+ * @warning since the return value is the length of src, src absolutely
+ * _must_ be a properly 0-terminated string, otherwise this will read beyond
+ * the end of the buffer and possibly crash.
+ */
+size_t av_strlcpy(char *dst, const char *src, size_t size);
+
+/**
+ * Append the string src to the string dst, but to a total length of
+ * no more than size - 1 bytes, and null-terminate dst.
+ *
+ * This function is similar to BSD strlcat(), but differs when
+ * size <= strlen(dst).
+ *
+ * @param dst destination buffer
+ * @param src source string
+ * @param size size of destination buffer
+ * @return the total length of src and dst
+ *
+ * @warning since the return value use the length of src and dst, these
+ * absolutely _must_ be a properly 0-terminated strings, otherwise this
+ * will read beyond the end of the buffer and possibly crash.
+ */
+size_t av_strlcat(char *dst, const char *src, size_t size);
+
+/**
+ * Append output to a string, according to a format. Never write out of
+ * the destination buffer, and always put a terminating 0 within
+ * the buffer.
+ * @param dst destination buffer (string to which the output is
+ *  appended)
+ * @param size total size of the destination buffer
+ * @param fmt printf-compatible format string, specifying how the
+ *  following parameters are used
+ * @return the length of the string that would have been generated
+ *  if enough space had been available
+ */
+size_t av_strlcatf(char *dst, size_t size, const char *fmt, ...) av_printf_format(3, 4);
+
+/**
+ * Print arguments following specified format into a large enough auto
+ * allocated buffer. It is similar to GNU asprintf().
+ * @param fmt printf-compatible format string, specifying how the
+ *            following parameters are used.
+ * @return the allocated string
+ * @note You have to free the string yourself with av_free().
+ */
+char *av_asprintf(const char *fmt, ...) av_printf_format(1, 2);
+
+/**
+ * Convert a number to a av_malloced string.
+ */
+char *av_d2str(double d);
+
+/**
+ * Unescape the given string until a non escaped terminating char,
+ * and return the token corresponding to the unescaped string.
+ *
+ * The normal \ and ' escaping is supported. Leading and trailing
+ * whitespaces are removed, unless they are escaped with '\' or are
+ * enclosed between ''.
+ *
+ * @param buf the buffer to parse, buf will be updated to point to the
+ * terminating char
+ * @param term a 0-terminated list of terminating chars
+ * @return the malloced unescaped string, which must be av_freed by
+ * the user, NULL in case of allocation failure
+ */
+char *av_get_token(const char **buf, const char *term);
+
+/**
+ * Split the string into several tokens which can be accessed by
+ * successive calls to av_strtok().
+ *
+ * A token is defined as a sequence of characters not belonging to the
+ * set specified in delim.
+ *
+ * On the first call to av_strtok(), s should point to the string to
+ * parse, and the value of saveptr is ignored. In subsequent calls, s
+ * should be NULL, and saveptr should be unchanged since the previous
+ * call.
+ *
+ * This function is similar to strtok_r() defined in POSIX.1.
+ *
+ * @param s the string to parse, may be NULL
+ * @param delim 0-terminated list of token delimiters, must be non-NULL
+ * @param saveptr user-provided pointer which points to stored
+ * information necessary for av_strtok() to continue scanning the same
+ * string. saveptr is updated to point to the next character after the
+ * first delimiter found, or to NULL if the string was terminated
+ * @return the found token, or NULL when no token is found
+ */
+char *av_strtok(char *s, const char *delim, char **saveptr);
+
+/**
+ * Locale-independent conversion of ASCII isdigit.
+ */
+int av_isdigit(int c);
+
+/**
+ * Locale-independent conversion of ASCII isgraph.
+ */
+int av_isgraph(int c);
+
+/**
+ * Locale-independent conversion of ASCII isspace.
+ */
+int av_isspace(int c);
+
+/**
+ * Locale-independent conversion of ASCII characters to uppercase.
+ */
+static inline int av_toupper(int c)
+{
+    if (c >= 'a' && c <= 'z')
+        c ^= 0x20;
+    return c;
+}
+
+/**
+ * Locale-independent conversion of ASCII characters to lowercase.
+ */
+static inline int av_tolower(int c)
+{
+    if (c >= 'A' && c <= 'Z')
+        c ^= 0x20;
+    return c;
+}
+
+/**
+ * Locale-independent conversion of ASCII isxdigit.
+ */
+int av_isxdigit(int c);
+
+/**
+ * Locale-independent case-insensitive compare.
+ * @note This means only ASCII-range characters are case-insensitive
+ */
+int av_strcasecmp(const char *a, const char *b);
+
+/**
+ * Locale-independent case-insensitive compare.
+ * @note This means only ASCII-range characters are case-insensitive
+ */
+int av_strncasecmp(const char *a, const char *b, size_t n);
+
+
+/**
+ * Thread safe basename.
+ * @param path the path, on DOS both \ and / are considered separators.
+ * @return pointer to the basename substring.
+ */
+const char *av_basename(const char *path);
+
+/**
+ * Thread safe dirname.
+ * @param path the path, on DOS both \ and / are considered separators.
+ * @return the path with the separator replaced by the string terminator or ".".
+ * @note the function may change the input string.
+ */
+const char *av_dirname(char *path);
+
+enum AVEscapeMode {
+    AV_ESCAPE_MODE_AUTO,      ///< Use auto-selected escaping mode.
+    AV_ESCAPE_MODE_BACKSLASH, ///< Use backslash escaping.
+    AV_ESCAPE_MODE_QUOTE,     ///< Use single-quote escaping.
+};
+
+/**
+ * Consider spaces special and escape them even in the middle of the
+ * string.
+ *
+ * This is equivalent to adding the whitespace characters to the special
+ * characters lists, except it is guaranteed to use the exact same list
+ * of whitespace characters as the rest of libavutil.
+ */
+#define AV_ESCAPE_FLAG_WHITESPACE 0x01
+
+/**
+ * Escape only specified special characters.
+ * Without this flag, escape also any characters that may be considered
+ * special by av_get_token(), such as the single quote.
+ */
+#define AV_ESCAPE_FLAG_STRICT 0x02
+
+/**
+ * Escape string in src, and put the escaped string in an allocated
+ * string in *dst, which must be freed with av_free().
+ *
+ * @param dst           pointer where an allocated string is put
+ * @param src           string to escape, must be non-NULL
+ * @param special_chars string containing the special characters which
+ *                      need to be escaped, can be NULL
+ * @param mode          escape mode to employ, see AV_ESCAPE_MODE_* macros.
+ *                      Any unknown value for mode will be considered equivalent to
+ *                      AV_ESCAPE_MODE_BACKSLASH, but this behaviour can change without
+ *                      notice.
+ * @param flags         flags which control how to escape, see AV_ESCAPE_FLAG_ macros
+ * @return the length of the allocated string, or a negative error code in case of error
+ * @see av_bprint_escape()
+ */
+int av_escape(char **dst, const char *src, const char *special_chars,
+              enum AVEscapeMode mode, int flags);
+
+/**
+ * @}
+ */
+
+#endif /* AVUTIL_AVSTRING_H */

+ 320 - 0
wave420l/code/ffmpeg/include/libavutil/avutil.h

@@ -0,0 +1,320 @@
+/*
+ * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_AVUTIL_H
+#define AVUTIL_AVUTIL_H
+
+/**
+ * @file
+ * external API header
+ */
+
+/**
+ * @mainpage
+ *
+ * @section ffmpeg_intro Introduction
+ *
+ * This document describes the usage of the different libraries
+ * provided by FFmpeg.
+ *
+ * @li @ref libavc "libavcodec" encoding/decoding library
+ * @li @ref lavfi "libavfilter" graph-based frame editing library
+ * @li @ref libavf "libavformat" I/O and muxing/demuxing library
+ * @li @ref lavd "libavdevice" special devices muxing/demuxing library
+ * @li @ref lavu "libavutil" common utility library
+ * @li @ref lswr "libswresample" audio resampling, format conversion and mixing
+ * @li @ref lpp  "libpostproc" post processing library
+ * @li @ref lsws "libswscale" color conversion and scaling library
+ *
+ * @section ffmpeg_versioning Versioning and compatibility
+ *
+ * Each of the FFmpeg libraries contains a version.h header, which defines a
+ * major, minor and micro version number with the
+ * <em>LIBRARYNAME_VERSION_{MAJOR,MINOR,MICRO}</em> macros. The major version
+ * number is incremented with backward incompatible changes - e.g. removing
+ * parts of the public API, reordering public struct members, etc. The minor
+ * version number is incremented for backward compatible API changes or major
+ * new features - e.g. adding a new public function or a new decoder. The micro
+ * version number is incremented for smaller changes that a calling program
+ * might still want to check for - e.g. changing behavior in a previously
+ * unspecified situation.
+ *
+ * FFmpeg guarantees backward API and ABI compatibility for each library as long
+ * as its major version number is unchanged. This means that no public symbols
+ * will be removed or renamed. Types and names of the public struct members and
+ * values of public macros and enums will remain the same (unless they were
+ * explicitly declared as not part of the public API). Documented behavior will
+ * not change.
+ *
+ * In other words, any correct program that works with a given FFmpeg snapshot
+ * should work just as well without any changes with any later snapshot with the
+ * same major versions. This applies to both rebuilding the program against new
+ * FFmpeg versions or to replacing the dynamic FFmpeg libraries that a program
+ * links against.
+ *
+ * However, new public symbols may be added and new members may be appended to
+ * public structs whose size is not part of public ABI (most public structs in
+ * FFmpeg). New macros and enum values may be added. Behavior in undocumented
+ * situations may change slightly (and be documented). All those are accompanied
+ * by an entry in doc/APIchanges and incrementing either the minor or micro
+ * version number.
+ */
+
+/**
+ * @defgroup lavu Common utility functions
+ *
+ * @brief
+ * libavutil contains the code shared across all the other FFmpeg
+ * libraries
+ *
+ * @note In order to use the functions provided by avutil you must include
+ * the specific header.
+ *
+ * @{
+ *
+ * @defgroup lavu_crypto Crypto and Hashing
+ *
+ * @{
+ * @}
+ *
+ * @defgroup lavu_math Maths
+ * @{
+ *
+ * @}
+ *
+ * @defgroup lavu_string String Manipulation
+ *
+ * @{
+ *
+ * @}
+ *
+ * @defgroup lavu_mem Memory Management
+ *
+ * @{
+ *
+ * @}
+ *
+ * @defgroup lavu_data Data Structures
+ * @{
+ *
+ * @}
+ *
+ * @defgroup lavu_audio Audio related
+ *
+ * @{
+ *
+ * @}
+ *
+ * @defgroup lavu_error Error Codes
+ *
+ * @{
+ *
+ * @}
+ *
+ * @defgroup lavu_log Logging Facility
+ *
+ * @{
+ *
+ * @}
+ *
+ * @defgroup lavu_misc Other
+ *
+ * @{
+ *
+ * @defgroup lavu_internal Internal
+ *
+ * Not exported functions, for internal usage only
+ *
+ * @{
+ *
+ * @}
+ */
+
+
+/**
+ * @addtogroup lavu_ver
+ * @{
+ */
+
+/**
+ * Return the LIBAVUTIL_VERSION_INT constant.
+ */
+unsigned avutil_version(void);
+
+/**
+ * Return the libavutil build-time configuration.
+ */
+const char *avutil_configuration(void);
+
+/**
+ * Return the libavutil license.
+ */
+const char *avutil_license(void);
+
+/**
+ * @}
+ */
+
+/**
+ * @addtogroup lavu_media Media Type
+ * @brief Media Type
+ */
+
+enum AVMediaType {
+    AVMEDIA_TYPE_UNKNOWN = -1,  ///< Usually treated as AVMEDIA_TYPE_DATA
+    AVMEDIA_TYPE_VIDEO,
+    AVMEDIA_TYPE_AUDIO,
+    AVMEDIA_TYPE_DATA,          ///< Opaque data information usually continuous
+    AVMEDIA_TYPE_SUBTITLE,
+    AVMEDIA_TYPE_ATTACHMENT,    ///< Opaque data information usually sparse
+    AVMEDIA_TYPE_NB
+};
+
+/**
+ * Return a string describing the media_type enum, NULL if media_type
+ * is unknown.
+ */
+const char *av_get_media_type_string(enum AVMediaType media_type);
+
+/**
+ * @defgroup lavu_const Constants
+ * @{
+ *
+ * @defgroup lavu_enc Encoding specific
+ *
+ * @note those definition should move to avcodec
+ * @{
+ */
+
+#define FF_LAMBDA_SHIFT 7
+#define FF_LAMBDA_SCALE (1<<FF_LAMBDA_SHIFT)
+#define FF_QP2LAMBDA 118 ///< factor to convert from H.263 QP to lambda
+#define FF_LAMBDA_MAX (256*128-1)
+
+#define FF_QUALITY_SCALE FF_LAMBDA_SCALE //FIXME maybe remove
+
+/**
+ * @}
+ * @defgroup lavu_time Timestamp specific
+ *
+ * FFmpeg internal timebase and timestamp definitions
+ *
+ * @{
+ */
+
+/**
+ * @brief Undefined timestamp value
+ *
+ * Usually reported by demuxer that work on containers that do not provide
+ * either pts or dts.
+ */
+
+#define AV_NOPTS_VALUE          ((int64_t)UINT64_C(0x8000000000000000))
+
+/**
+ * Internal time base represented as integer
+ */
+
+#define AV_TIME_BASE            1000000
+
+/**
+ * Internal time base represented as fractional value
+ */
+
+#define AV_TIME_BASE_Q          (AVRational){1, AV_TIME_BASE}
+
+/**
+ * @}
+ * @}
+ * @defgroup lavu_picture Image related
+ *
+ * AVPicture types, pixel formats and basic image planes manipulation.
+ *
+ * @{
+ */
+
+enum AVPictureType {
+    AV_PICTURE_TYPE_NONE = 0, ///< Undefined
+    AV_PICTURE_TYPE_I,     ///< Intra
+    AV_PICTURE_TYPE_P,     ///< Predicted
+    AV_PICTURE_TYPE_B,     ///< Bi-dir predicted
+    AV_PICTURE_TYPE_S,     ///< S(GMC)-VOP MPEG4
+    AV_PICTURE_TYPE_SI,    ///< Switching Intra
+    AV_PICTURE_TYPE_SP,    ///< Switching Predicted
+    AV_PICTURE_TYPE_BI,    ///< BI type
+};
+
+/**
+ * Return a single letter to describe the given picture type
+ * pict_type.
+ *
+ * @param[in] pict_type the picture type @return a single character
+ * representing the picture type, '?' if pict_type is unknown
+ */
+char av_get_picture_type_char(enum AVPictureType pict_type);
+
+/**
+ * @}
+ */
+
+#include "common.h"
+#include "error.h"
+#include "version.h"
+#include "mathematics.h"
+#include "rational.h"
+#include "intfloat_readwrite.h"
+#include "log.h"
+#include "pixfmt.h"
+
+/**
+ * Return x default pointer in case p is NULL.
+ */
+static inline void *av_x_if_null(const void *p, const void *x)
+{
+    return (void *)(intptr_t)(p ? p : x);
+}
+
+/**
+ * Compute the length of an integer list.
+ *
+ * @param elsize  size in bytes of each list element (only 1, 2, 4 or 8)
+ * @param term    list terminator (usually 0 or -1)
+ * @param list    pointer to the list
+ * @return  length of the list, in elements, not counting the terminator
+ */
+unsigned av_int_list_length_for_size(unsigned elsize,
+                                     const void *list, uint64_t term) av_pure;
+
+/**
+ * Compute the length of an integer list.
+ *
+ * @param term  list terminator (usually 0 or -1)
+ * @param list  pointer to the list
+ * @return  length of the list, in elements, not counting the terminator
+ */
+#define av_int_list_length(list, term) \
+    av_int_list_length_for_size(sizeof(*(list)), list, term)
+
+/**
+ * @}
+ * @}
+ */
+
+#endif /* AVUTIL_AVUTIL_H */

+ 67 - 0
wave420l/code/ffmpeg/include/libavutil/base64.h

@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2006 Ryan Martell. (rdm4@martellventures.com)
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_BASE64_H
+#define AVUTIL_BASE64_H
+
+#include <stdint.h>
+
+/**
+ * @defgroup lavu_base64 Base64
+ * @ingroup lavu_crypto
+ * @{
+ */
+
+
+/**
+ * Decode a base64-encoded string.
+ *
+ * @param out      buffer for decoded data
+ * @param in       null-terminated input string
+ * @param out_size size in bytes of the out buffer, must be at
+ *                 least 3/4 of the length of in
+ * @return         number of bytes written, or a negative value in case of
+ *                 invalid input
+ */
+int av_base64_decode(uint8_t *out, const char *in, int out_size);
+
+/**
+ * Encode data to base64 and null-terminate.
+ *
+ * @param out      buffer for encoded data
+ * @param out_size size in bytes of the out buffer (including the
+ *                 null terminator), must be at least AV_BASE64_SIZE(in_size)
+ * @param in       input buffer containing the data to encode
+ * @param in_size  size in bytes of the in buffer
+ * @return         out or NULL in case of error
+ */
+char *av_base64_encode(char *out, int out_size, const uint8_t *in, int in_size);
+
+/**
+ * Calculate the output size needed to base64-encode x bytes to a
+ * null-terminated string.
+ */
+#define AV_BASE64_SIZE(x)  (((x)+2) / 3 * 4 + 1)
+
+ /**
+  * @}
+  */
+
+#endif /* AVUTIL_BASE64_H */

+ 77 - 0
wave420l/code/ffmpeg/include/libavutil/blowfish.h

@@ -0,0 +1,77 @@
+/*
+ * Blowfish algorithm
+ * Copyright (c) 2012 Samuel Pitoiset
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_BLOWFISH_H
+#define AVUTIL_BLOWFISH_H
+
+#include <stdint.h>
+
+/**
+ * @defgroup lavu_blowfish Blowfish
+ * @ingroup lavu_crypto
+ * @{
+ */
+
+#define AV_BF_ROUNDS 16
+
+typedef struct AVBlowfish {
+    uint32_t p[AV_BF_ROUNDS + 2];
+    uint32_t s[4][256];
+} AVBlowfish;
+
+/**
+ * Initialize an AVBlowfish context.
+ *
+ * @param ctx an AVBlowfish context
+ * @param key a key
+ * @param key_len length of the key
+ */
+void av_blowfish_init(struct AVBlowfish *ctx, const uint8_t *key, int key_len);
+
+/**
+ * Encrypt or decrypt a buffer using a previously initialized context.
+ *
+ * @param ctx an AVBlowfish context
+ * @param xl left four bytes halves of input to be encrypted
+ * @param xr right four bytes halves of input to be encrypted
+ * @param decrypt 0 for encryption, 1 for decryption
+ */
+void av_blowfish_crypt_ecb(struct AVBlowfish *ctx, uint32_t *xl, uint32_t *xr,
+                           int decrypt);
+
+/**
+ * Encrypt or decrypt a buffer using a previously initialized context.
+ *
+ * @param ctx an AVBlowfish context
+ * @param dst destination array, can be equal to src
+ * @param src source array, can be equal to dst
+ * @param count number of 8 byte blocks
+ * @param iv initialization vector for CBC mode, if NULL ECB will be used
+ * @param decrypt 0 for encryption, 1 for decryption
+ */
+void av_blowfish_crypt(struct AVBlowfish *ctx, uint8_t *dst, const uint8_t *src,
+                       int count, uint8_t *iv, int decrypt);
+
+/**
+ * @}
+ */
+
+#endif /* AVUTIL_BLOWFISH_H */

+ 216 - 0
wave420l/code/ffmpeg/include/libavutil/bprint.h

@@ -0,0 +1,216 @@
+/*
+ * Copyright (c) 2012 Nicolas George
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_BPRINT_H
+#define AVUTIL_BPRINT_H
+
+#include <stdarg.h>
+
+#include "attributes.h"
+#include "avstring.h"
+
+/**
+ * Define a structure with extra padding to a fixed size
+ * This helps ensuring binary compatibility with future versions.
+ */
+#define FF_PAD_STRUCTURE(size, ...) \
+    __VA_ARGS__ \
+    char reserved_padding[size - sizeof(struct { __VA_ARGS__ })];
+
+/**
+ * Buffer to print data progressively
+ *
+ * The string buffer grows as necessary and is always 0-terminated.
+ * The content of the string is never accessed, and thus is
+ * encoding-agnostic and can even hold binary data.
+ *
+ * Small buffers are kept in the structure itself, and thus require no
+ * memory allocation at all (unless the contents of the buffer is needed
+ * after the structure goes out of scope). This is almost as lightweight as
+ * declaring a local "char buf[512]".
+ *
+ * The length of the string can go beyond the allocated size: the buffer is
+ * then truncated, but the functions still keep account of the actual total
+ * length.
+ *
+ * In other words, buf->len can be greater than buf->size and records the
+ * total length of what would have been to the buffer if there had been
+ * enough memory.
+ *
+ * Append operations do not need to be tested for failure: if a memory
+ * allocation fails, data stop being appended to the buffer, but the length
+ * is still updated. This situation can be tested with
+ * av_bprint_is_complete().
+ *
+ * The size_max field determines several possible behaviours:
+ *
+ * size_max = -1 (= UINT_MAX) or any large value will let the buffer be
+ * reallocated as necessary, with an amortized linear cost.
+ *
+ * size_max = 0 prevents writing anything to the buffer: only the total
+ * length is computed. The write operations can then possibly be repeated in
+ * a buffer with exactly the necessary size
+ * (using size_init = size_max = len + 1).
+ *
+ * size_max = 1 is automatically replaced by the exact size available in the
+ * structure itself, thus ensuring no dynamic memory allocation. The
+ * internal buffer is large enough to hold a reasonable paragraph of text,
+ * such as the current paragraph.
+ */
+typedef struct AVBPrint {
+    FF_PAD_STRUCTURE(1024,
+    char *str;         /**< string so far */
+    unsigned len;      /**< length so far */
+    unsigned size;     /**< allocated memory */
+    unsigned size_max; /**< maximum allocated memory */
+    char reserved_internal_buffer[1];
+    )
+} AVBPrint;
+
+/**
+ * Convenience macros for special values for av_bprint_init() size_max
+ * parameter.
+ */
+#define AV_BPRINT_SIZE_UNLIMITED  ((unsigned)-1)
+#define AV_BPRINT_SIZE_AUTOMATIC  1
+#define AV_BPRINT_SIZE_COUNT_ONLY 0
+
+/**
+ * Init a print buffer.
+ *
+ * @param buf        buffer to init
+ * @param size_init  initial size (including the final 0)
+ * @param size_max   maximum size;
+ *                   0 means do not write anything, just count the length;
+ *                   1 is replaced by the maximum value for automatic storage;
+ *                   any large value means that the internal buffer will be
+ *                   reallocated as needed up to that limit; -1 is converted to
+ *                   UINT_MAX, the largest limit possible.
+ *                   Check also AV_BPRINT_SIZE_* macros.
+ */
+void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max);
+
+/**
+ * Init a print buffer using a pre-existing buffer.
+ *
+ * The buffer will not be reallocated.
+ *
+ * @param buf     buffer structure to init
+ * @param buffer  byte buffer to use for the string data
+ * @param size    size of buffer
+ */
+void av_bprint_init_for_buffer(AVBPrint *buf, char *buffer, unsigned size);
+
+/**
+ * Append a formatted string to a print buffer.
+ */
+void av_bprintf(AVBPrint *buf, const char *fmt, ...) av_printf_format(2, 3);
+
+/**
+ * Append a formatted string to a print buffer.
+ */
+void av_vbprintf(AVBPrint *buf, const char *fmt, va_list vl_arg);
+
+/**
+ * Append char c n times to a print buffer.
+ */
+void av_bprint_chars(AVBPrint *buf, char c, unsigned n);
+
+/**
+ * Append data to a print buffer.
+ *
+ * param buf  bprint buffer to use
+ * param data pointer to data
+ * param size size of data
+ */
+void av_bprint_append_data(AVBPrint *buf, const char *data, unsigned size);
+
+struct tm;
+/**
+ * Append a formatted date and time to a print buffer.
+ *
+ * param buf  bprint buffer to use
+ * param fmt  date and time format string, see strftime()
+ * param tm   broken-down time structure to translate
+ *
+ * @note due to poor design of the standard strftime function, it may
+ * produce poor results if the format string expands to a very long text and
+ * the bprint buffer is near the limit stated by the size_max option.
+ */
+void av_bprint_strftime(AVBPrint *buf, const char *fmt, const struct tm *tm);
+
+/**
+ * Allocate bytes in the buffer for external use.
+ *
+ * @param[in]  buf          buffer structure
+ * @param[in]  size         required size
+ * @param[out] mem          pointer to the memory area
+ * @param[out] actual_size  size of the memory area after allocation;
+ *                          can be larger or smaller than size
+ */
+void av_bprint_get_buffer(AVBPrint *buf, unsigned size,
+                          unsigned char **mem, unsigned *actual_size);
+
+/**
+ * Reset the string to "" but keep internal allocated data.
+ */
+void av_bprint_clear(AVBPrint *buf);
+
+/**
+ * Test if the print buffer is complete (not truncated).
+ *
+ * It may have been truncated due to a memory allocation failure
+ * or the size_max limit (compare size and size_max if necessary).
+ */
+static inline int av_bprint_is_complete(AVBPrint *buf)
+{
+    return buf->len < buf->size;
+}
+
+/**
+ * Finalize a print buffer.
+ *
+ * The print buffer can no longer be used afterwards,
+ * but the len and size fields are still valid.
+ *
+ * @arg[out] ret_str  if not NULL, used to return a permanent copy of the
+ *                    buffer contents, or NULL if memory allocation fails;
+ *                    if NULL, the buffer is discarded and freed
+ * @return  0 for success or error code (probably AVERROR(ENOMEM))
+ */
+int av_bprint_finalize(AVBPrint *buf, char **ret_str);
+
+/**
+ * Escape the content in src and append it to dstbuf.
+ *
+ * @param dstbuf        already inited destination bprint buffer
+ * @param src           string containing the text to escape
+ * @param special_chars string containing the special characters which
+ *                      need to be escaped, can be NULL
+ * @param mode          escape mode to employ, see AV_ESCAPE_MODE_* macros.
+ *                      Any unknown value for mode will be considered equivalent to
+ *                      AV_ESCAPE_MODE_BACKSLASH, but this behaviour can change without
+ *                      notice.
+ * @param flags         flags which control how to escape, see AV_ESCAPE_FLAG_* macros
+ */
+void av_bprint_escape(AVBPrint *dstbuf, const char *src, const char *special_chars,
+                      enum AVEscapeMode mode, int flags);
+
+#endif /* AVUTIL_BPRINT_H */

+ 109 - 0
wave420l/code/ffmpeg/include/libavutil/bswap.h

@@ -0,0 +1,109 @@
+/*
+ * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * byte swapping routines
+ */
+
+#ifndef AVUTIL_BSWAP_H
+#define AVUTIL_BSWAP_H
+
+#include <stdint.h>
+#include "libavutil/avconfig.h"
+#include "attributes.h"
+
+#ifdef HAVE_AV_CONFIG_H
+
+#include "config.h"
+
+#if   ARCH_ARM
+#   include "arm/bswap.h"
+#elif ARCH_AVR32
+#   include "avr32/bswap.h"
+#elif ARCH_BFIN
+#   include "bfin/bswap.h"
+#elif ARCH_SH4
+#   include "sh4/bswap.h"
+#elif ARCH_X86
+#   include "x86/bswap.h"
+#endif
+
+#endif /* HAVE_AV_CONFIG_H */
+
+#define AV_BSWAP16C(x) (((x) << 8 & 0xff00)  | ((x) >> 8 & 0x00ff))
+#define AV_BSWAP32C(x) (AV_BSWAP16C(x) << 16 | AV_BSWAP16C((x) >> 16))
+#define AV_BSWAP64C(x) (AV_BSWAP32C(x) << 32 | AV_BSWAP32C((x) >> 32))
+
+#define AV_BSWAPC(s, x) AV_BSWAP##s##C(x)
+
+#ifndef av_bswap16
+static av_always_inline av_const uint16_t av_bswap16(uint16_t x)
+{
+    x= (x>>8) | (x<<8);
+    return x;
+}
+#endif
+
+#ifndef av_bswap32
+static av_always_inline av_const uint32_t av_bswap32(uint32_t x)
+{
+    return AV_BSWAP32C(x);
+}
+#endif
+
+#ifndef av_bswap64
+static inline uint64_t av_const av_bswap64(uint64_t x)
+{
+    return (uint64_t)av_bswap32(x) << 32 | av_bswap32(x >> 32);
+}
+#endif
+
+// be2ne ... big-endian to native-endian
+// le2ne ... little-endian to native-endian
+
+#if AV_HAVE_BIGENDIAN
+#define av_be2ne16(x) (x)
+#define av_be2ne32(x) (x)
+#define av_be2ne64(x) (x)
+#define av_le2ne16(x) av_bswap16(x)
+#define av_le2ne32(x) av_bswap32(x)
+#define av_le2ne64(x) av_bswap64(x)
+#define AV_BE2NEC(s, x) (x)
+#define AV_LE2NEC(s, x) AV_BSWAPC(s, x)
+#else
+#define av_be2ne16(x) av_bswap16(x)
+#define av_be2ne32(x) av_bswap32(x)
+#define av_be2ne64(x) av_bswap64(x)
+#define av_le2ne16(x) (x)
+#define av_le2ne32(x) (x)
+#define av_le2ne64(x) (x)
+#define AV_BE2NEC(s, x) AV_BSWAPC(s, x)
+#define AV_LE2NEC(s, x) (x)
+#endif
+
+#define AV_BE2NE16C(x) AV_BE2NEC(16, x)
+#define AV_BE2NE32C(x) AV_BE2NEC(32, x)
+#define AV_BE2NE64C(x) AV_BE2NEC(64, x)
+#define AV_LE2NE16C(x) AV_LE2NEC(16, x)
+#define AV_LE2NE32C(x) AV_LE2NEC(32, x)
+#define AV_LE2NE64C(x) AV_LE2NEC(64, x)
+
+#endif /* AVUTIL_BSWAP_H */

+ 274 - 0
wave420l/code/ffmpeg/include/libavutil/buffer.h

@@ -0,0 +1,274 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * @ingroup lavu_buffer
+ * refcounted data buffer API
+ */
+
+#ifndef AVUTIL_BUFFER_H
+#define AVUTIL_BUFFER_H
+
+#include <stdint.h>
+
+/**
+ * @defgroup lavu_buffer AVBuffer
+ * @ingroup lavu_data
+ *
+ * @{
+ * AVBuffer is an API for reference-counted data buffers.
+ *
+ * There are two core objects in this API -- AVBuffer and AVBufferRef. AVBuffer
+ * represents the data buffer itself; it is opaque and not meant to be accessed
+ * by the caller directly, but only through AVBufferRef. However, the caller may
+ * e.g. compare two AVBuffer pointers to check whether two different references
+ * are describing the same data buffer. AVBufferRef represents a single
+ * reference to an AVBuffer and it is the object that may be manipulated by the
+ * caller directly.
+ *
+ * There are two functions provided for creating a new AVBuffer with a single
+ * reference -- av_buffer_alloc() to just allocate a new buffer, and
+ * av_buffer_create() to wrap an existing array in an AVBuffer. From an existing
+ * reference, additional references may be created with av_buffer_ref().
+ * Use av_buffer_unref() to free a reference (this will automatically free the
+ * data once all the references are freed).
+ *
+ * The convention throughout this API and the rest of FFmpeg is such that the
+ * buffer is considered writable if there exists only one reference to it (and
+ * it has not been marked as read-only). The av_buffer_is_writable() function is
+ * provided to check whether this is true and av_buffer_make_writable() will
+ * automatically create a new writable buffer when necessary.
+ * Of course nothing prevents the calling code from violating this convention,
+ * however that is safe only when all the existing references are under its
+ * control.
+ *
+ * @note Referencing and unreferencing the buffers is thread-safe and thus
+ * may be done from multiple threads simultaneously without any need for
+ * additional locking.
+ *
+ * @note Two different references to the same buffer can point to different
+ * parts of the buffer (i.e. their AVBufferRef.data will not be equal).
+ */
+
+/**
+ * A reference counted buffer type. It is opaque and is meant to be used through
+ * references (AVBufferRef).
+ */
+typedef struct AVBuffer AVBuffer;
+
+/**
+ * A reference to a data buffer.
+ *
+ * The size of this struct is not a part of the public ABI and it is not meant
+ * to be allocated directly.
+ */
+typedef struct AVBufferRef {
+    AVBuffer *buffer;
+
+    /**
+     * The data buffer. It is considered writable if and only if
+     * this is the only reference to the buffer, in which case
+     * av_buffer_is_writable() returns 1.
+     */
+    uint8_t *data;
+    /**
+     * Size of data in bytes.
+     */
+    int      size;
+} AVBufferRef;
+
+/**
+ * Allocate an AVBuffer of the given size using av_malloc().
+ *
+ * @return an AVBufferRef of given size or NULL when out of memory
+ */
+AVBufferRef *av_buffer_alloc(int size);
+
+/**
+ * Same as av_buffer_alloc(), except the returned buffer will be initialized
+ * to zero.
+ */
+AVBufferRef *av_buffer_allocz(int size);
+
+/**
+ * Always treat the buffer as read-only, even when it has only one
+ * reference.
+ */
+#define AV_BUFFER_FLAG_READONLY (1 << 0)
+
+/**
+ * Create an AVBuffer from an existing array.
+ *
+ * If this function is successful, data is owned by the AVBuffer. The caller may
+ * only access data through the returned AVBufferRef and references derived from
+ * it.
+ * If this function fails, data is left untouched.
+ * @param data   data array
+ * @param size   size of data in bytes
+ * @param free   a callback for freeing this buffer's data
+ * @param opaque parameter to be got for processing or passed to free
+ * @param flags  a combination of AV_BUFFER_FLAG_*
+ *
+ * @return an AVBufferRef referring to data on success, NULL on failure.
+ */
+AVBufferRef *av_buffer_create(uint8_t *data, int size,
+                              void (*free)(void *opaque, uint8_t *data),
+                              void *opaque, int flags);
+
+/**
+ * Default free callback, which calls av_free() on the buffer data.
+ * This function is meant to be passed to av_buffer_create(), not called
+ * directly.
+ */
+void av_buffer_default_free(void *opaque, uint8_t *data);
+
+/**
+ * Create a new reference to an AVBuffer.
+ *
+ * @return a new AVBufferRef referring to the same AVBuffer as buf or NULL on
+ * failure.
+ */
+AVBufferRef *av_buffer_ref(AVBufferRef *buf);
+
+/**
+ * Free a given reference and automatically free the buffer if there are no more
+ * references to it.
+ *
+ * @param buf the reference to be freed. The pointer is set to NULL on return.
+ */
+void av_buffer_unref(AVBufferRef **buf);
+
+/**
+ * @return 1 if the caller may write to the data referred to by buf (which is
+ * true if and only if buf is the only reference to the underlying AVBuffer).
+ * Return 0 otherwise.
+ * A positive answer is valid until av_buffer_ref() is called on buf.
+ */
+int av_buffer_is_writable(const AVBufferRef *buf);
+
+/**
+ * @return the opaque parameter set by av_buffer_create.
+ */
+void *av_buffer_get_opaque(const AVBufferRef *buf);
+
+int av_buffer_get_ref_count(const AVBufferRef *buf);
+
+/**
+ * Create a writable reference from a given buffer reference, avoiding data copy
+ * if possible.
+ *
+ * @param buf buffer reference to make writable. On success, buf is either left
+ *            untouched, or it is unreferenced and a new writable AVBufferRef is
+ *            written in its place. On failure, buf is left untouched.
+ * @return 0 on success, a negative AVERROR on failure.
+ */
+int av_buffer_make_writable(AVBufferRef **buf);
+
+/**
+ * Reallocate a given buffer.
+ *
+ * @param buf  a buffer reference to reallocate. On success, buf will be
+ *             unreferenced and a new reference with the required size will be
+ *             written in its place. On failure buf will be left untouched. *buf
+ *             may be NULL, then a new buffer is allocated.
+ * @param size required new buffer size.
+ * @return 0 on success, a negative AVERROR on failure.
+ *
+ * @note the buffer is actually reallocated with av_realloc() only if it was
+ * initially allocated through av_buffer_realloc(NULL) and there is only one
+ * reference to it (i.e. the one passed to this function). In all other cases
+ * a new buffer is allocated and the data is copied.
+ */
+int av_buffer_realloc(AVBufferRef **buf, int size);
+
+/**
+ * @}
+ */
+
+/**
+ * @defgroup lavu_bufferpool AVBufferPool
+ * @ingroup lavu_data
+ *
+ * @{
+ * AVBufferPool is an API for a lock-free thread-safe pool of AVBuffers.
+ *
+ * Frequently allocating and freeing large buffers may be slow. AVBufferPool is
+ * meant to solve this in cases when the caller needs a set of buffers of the
+ * same size (the most obvious use case being buffers for raw video or audio
+ * frames).
+ *
+ * At the beginning, the user must call av_buffer_pool_init() to create the
+ * buffer pool. Then whenever a buffer is needed, call av_buffer_pool_get() to
+ * get a reference to a new buffer, similar to av_buffer_alloc(). This new
+ * reference works in all aspects the same way as the one created by
+ * av_buffer_alloc(). However, when the last reference to this buffer is
+ * unreferenced, it is returned to the pool instead of being freed and will be
+ * reused for subsequent av_buffer_pool_get() calls.
+ *
+ * When the caller is done with the pool and no longer needs to allocate any new
+ * buffers, av_buffer_pool_uninit() must be called to mark the pool as freeable.
+ * Once all the buffers are released, it will automatically be freed.
+ *
+ * Allocating and releasing buffers with this API is thread-safe as long as
+ * either the default alloc callback is used, or the user-supplied one is
+ * thread-safe.
+ */
+
+/**
+ * The buffer pool. This structure is opaque and not meant to be accessed
+ * directly. It is allocated with av_buffer_pool_init() and freed with
+ * av_buffer_pool_uninit().
+ */
+typedef struct AVBufferPool AVBufferPool;
+
+/**
+ * Allocate and initialize a buffer pool.
+ *
+ * @param size size of each buffer in this pool
+ * @param alloc a function that will be used to allocate new buffers when the
+ * pool is empty. May be NULL, then the default allocator will be used
+ * (av_buffer_alloc()).
+ * @return newly created buffer pool on success, NULL on error.
+ */
+AVBufferPool *av_buffer_pool_init(int size, AVBufferRef* (*alloc)(int size));
+
+/**
+ * Mark the pool as being available for freeing. It will actually be freed only
+ * once all the allocated buffers associated with the pool are released. Thus it
+ * is safe to call this function while some of the allocated buffers are still
+ * in use.
+ *
+ * @param pool pointer to the pool to be freed. It will be set to NULL.
+ * @see av_buffer_pool_can_uninit()
+ */
+void av_buffer_pool_uninit(AVBufferPool **pool);
+
+/**
+ * Allocate a new AVBuffer, reusing an old buffer from the pool when available.
+ * This function may be called simultaneously from multiple threads.
+ *
+ * @return a reference to the new buffer on success, NULL on error.
+ */
+AVBufferRef *av_buffer_pool_get(AVBufferPool *pool);
+
+/**
+ * @}
+ */
+
+#endif /* AVUTIL_BUFFER_H */

+ 221 - 0
wave420l/code/ffmpeg/include/libavutil/channel_layout.h

@@ -0,0 +1,221 @@
+/*
+ * Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
+ * Copyright (c) 2008 Peter Ross
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_CHANNEL_LAYOUT_H
+#define AVUTIL_CHANNEL_LAYOUT_H
+
+#include <stdint.h>
+
+/**
+ * @file
+ * audio channel layout utility functions
+ */
+
+/**
+ * @addtogroup lavu_audio
+ * @{
+ */
+
+/**
+ * @defgroup channel_masks Audio channel masks
+ *
+ * A channel layout is a 64-bits integer with a bit set for every channel.
+ * The number of bits set must be equal to the number of channels.
+ * The value 0 means that the channel layout is not known.
+ * @note this data structure is not powerful enough to handle channels
+ * combinations that have the same channel multiple times, such as
+ * dual-mono.
+ *
+ * @{
+ */
+#define AV_CH_FRONT_LEFT             0x00000001
+#define AV_CH_FRONT_RIGHT            0x00000002
+#define AV_CH_FRONT_CENTER           0x00000004
+#define AV_CH_LOW_FREQUENCY          0x00000008
+#define AV_CH_BACK_LEFT              0x00000010
+#define AV_CH_BACK_RIGHT             0x00000020
+#define AV_CH_FRONT_LEFT_OF_CENTER   0x00000040
+#define AV_CH_FRONT_RIGHT_OF_CENTER  0x00000080
+#define AV_CH_BACK_CENTER            0x00000100
+#define AV_CH_SIDE_LEFT              0x00000200
+#define AV_CH_SIDE_RIGHT             0x00000400
+#define AV_CH_TOP_CENTER             0x00000800
+#define AV_CH_TOP_FRONT_LEFT         0x00001000
+#define AV_CH_TOP_FRONT_CENTER       0x00002000
+#define AV_CH_TOP_FRONT_RIGHT        0x00004000
+#define AV_CH_TOP_BACK_LEFT          0x00008000
+#define AV_CH_TOP_BACK_CENTER        0x00010000
+#define AV_CH_TOP_BACK_RIGHT         0x00020000
+#define AV_CH_STEREO_LEFT            0x20000000  ///< Stereo downmix.
+#define AV_CH_STEREO_RIGHT           0x40000000  ///< See AV_CH_STEREO_LEFT.
+#define AV_CH_WIDE_LEFT              0x0000000080000000ULL
+#define AV_CH_WIDE_RIGHT             0x0000000100000000ULL
+#define AV_CH_SURROUND_DIRECT_LEFT   0x0000000200000000ULL
+#define AV_CH_SURROUND_DIRECT_RIGHT  0x0000000400000000ULL
+#define AV_CH_LOW_FREQUENCY_2        0x0000000800000000ULL
+
+/** Channel mask value used for AVCodecContext.request_channel_layout
+    to indicate that the user requests the channel order of the decoder output
+    to be the native codec channel order. */
+#define AV_CH_LAYOUT_NATIVE          0x8000000000000000ULL
+
+/**
+ * @}
+ * @defgroup channel_mask_c Audio channel convenience macros
+ * @{
+ * */
+#define AV_CH_LAYOUT_MONO              (AV_CH_FRONT_CENTER)
+#define AV_CH_LAYOUT_STEREO            (AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT)
+#define AV_CH_LAYOUT_2POINT1           (AV_CH_LAYOUT_STEREO|AV_CH_LOW_FREQUENCY)
+#define AV_CH_LAYOUT_2_1               (AV_CH_LAYOUT_STEREO|AV_CH_BACK_CENTER)
+#define AV_CH_LAYOUT_SURROUND          (AV_CH_LAYOUT_STEREO|AV_CH_FRONT_CENTER)
+#define AV_CH_LAYOUT_3POINT1           (AV_CH_LAYOUT_SURROUND|AV_CH_LOW_FREQUENCY)
+#define AV_CH_LAYOUT_4POINT0           (AV_CH_LAYOUT_SURROUND|AV_CH_BACK_CENTER)
+#define AV_CH_LAYOUT_4POINT1           (AV_CH_LAYOUT_4POINT0|AV_CH_LOW_FREQUENCY)
+#define AV_CH_LAYOUT_2_2               (AV_CH_LAYOUT_STEREO|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT)
+#define AV_CH_LAYOUT_QUAD              (AV_CH_LAYOUT_STEREO|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT)
+#define AV_CH_LAYOUT_5POINT0           (AV_CH_LAYOUT_SURROUND|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT)
+#define AV_CH_LAYOUT_5POINT1           (AV_CH_LAYOUT_5POINT0|AV_CH_LOW_FREQUENCY)
+#define AV_CH_LAYOUT_5POINT0_BACK      (AV_CH_LAYOUT_SURROUND|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT)
+#define AV_CH_LAYOUT_5POINT1_BACK      (AV_CH_LAYOUT_5POINT0_BACK|AV_CH_LOW_FREQUENCY)
+#define AV_CH_LAYOUT_6POINT0           (AV_CH_LAYOUT_5POINT0|AV_CH_BACK_CENTER)
+#define AV_CH_LAYOUT_6POINT0_FRONT     (AV_CH_LAYOUT_2_2|AV_CH_FRONT_LEFT_OF_CENTER|AV_CH_FRONT_RIGHT_OF_CENTER)
+#define AV_CH_LAYOUT_HEXAGONAL         (AV_CH_LAYOUT_5POINT0_BACK|AV_CH_BACK_CENTER)
+#define AV_CH_LAYOUT_6POINT1           (AV_CH_LAYOUT_5POINT1|AV_CH_BACK_CENTER)
+#define AV_CH_LAYOUT_6POINT1_BACK      (AV_CH_LAYOUT_5POINT1_BACK|AV_CH_BACK_CENTER)
+#define AV_CH_LAYOUT_6POINT1_FRONT     (AV_CH_LAYOUT_6POINT0_FRONT|AV_CH_LOW_FREQUENCY)
+#define AV_CH_LAYOUT_7POINT0           (AV_CH_LAYOUT_5POINT0|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT)
+#define AV_CH_LAYOUT_7POINT0_FRONT     (AV_CH_LAYOUT_5POINT0|AV_CH_FRONT_LEFT_OF_CENTER|AV_CH_FRONT_RIGHT_OF_CENTER)
+#define AV_CH_LAYOUT_7POINT1           (AV_CH_LAYOUT_5POINT1|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT)
+#define AV_CH_LAYOUT_7POINT1_WIDE      (AV_CH_LAYOUT_5POINT1|AV_CH_FRONT_LEFT_OF_CENTER|AV_CH_FRONT_RIGHT_OF_CENTER)
+#define AV_CH_LAYOUT_7POINT1_WIDE_BACK (AV_CH_LAYOUT_5POINT1_BACK|AV_CH_FRONT_LEFT_OF_CENTER|AV_CH_FRONT_RIGHT_OF_CENTER)
+#define AV_CH_LAYOUT_OCTAGONAL         (AV_CH_LAYOUT_5POINT0|AV_CH_BACK_LEFT|AV_CH_BACK_CENTER|AV_CH_BACK_RIGHT)
+#define AV_CH_LAYOUT_STEREO_DOWNMIX    (AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT)
+
+enum AVMatrixEncoding {
+    AV_MATRIX_ENCODING_NONE,
+    AV_MATRIX_ENCODING_DOLBY,
+    AV_MATRIX_ENCODING_DPLII,
+    AV_MATRIX_ENCODING_NB
+};
+
+/**
+ * @}
+ */
+
+/**
+ * Return a channel layout id that matches name, or 0 if no match is found.
+ *
+ * name can be one or several of the following notations,
+ * separated by '+' or '|':
+ * - the name of an usual channel layout (mono, stereo, 4.0, quad, 5.0,
+ *   5.0(side), 5.1, 5.1(side), 7.1, 7.1(wide), downmix);
+ * - the name of a single channel (FL, FR, FC, LFE, BL, BR, FLC, FRC, BC,
+ *   SL, SR, TC, TFL, TFC, TFR, TBL, TBC, TBR, DL, DR);
+ * - a number of channels, in decimal, optionally followed by 'c', yielding
+ *   the default channel layout for that number of channels (@see
+ *   av_get_default_channel_layout);
+ * - a channel layout mask, in hexadecimal starting with "0x" (see the
+ *   AV_CH_* macros).
+ *
+ * @warning Starting from the next major bump the trailing character
+ * 'c' to specify a number of channels will be required, while a
+ * channel layout mask could also be specified as a decimal number
+ * (if and only if not followed by "c").
+ *
+ * Example: "stereo+FC" = "2c+FC" = "2c+1c" = "0x7"
+ */
+uint64_t av_get_channel_layout(const char *name);
+
+/**
+ * Return a description of a channel layout.
+ * If nb_channels is <= 0, it is guessed from the channel_layout.
+ *
+ * @param buf put here the string containing the channel layout
+ * @param buf_size size in bytes of the buffer
+ */
+void av_get_channel_layout_string(char *buf, int buf_size, int nb_channels, uint64_t channel_layout);
+
+struct AVBPrint;
+/**
+ * Append a description of a channel layout to a bprint buffer.
+ */
+void av_bprint_channel_layout(struct AVBPrint *bp, int nb_channels, uint64_t channel_layout);
+
+/**
+ * Return the number of channels in the channel layout.
+ */
+int av_get_channel_layout_nb_channels(uint64_t channel_layout);
+
+/**
+ * Return default channel layout for a given number of channels.
+ */
+int64_t av_get_default_channel_layout(int nb_channels);
+
+/**
+ * Get the index of a channel in channel_layout.
+ *
+ * @param channel a channel layout describing exactly one channel which must be
+ *                present in channel_layout.
+ *
+ * @return index of channel in channel_layout on success, a negative AVERROR
+ *         on error.
+ */
+int av_get_channel_layout_channel_index(uint64_t channel_layout,
+                                        uint64_t channel);
+
+/**
+ * Get the channel with the given index in channel_layout.
+ */
+uint64_t av_channel_layout_extract_channel(uint64_t channel_layout, int index);
+
+/**
+ * Get the name of a given channel.
+ *
+ * @return channel name on success, NULL on error.
+ */
+const char *av_get_channel_name(uint64_t channel);
+
+/**
+ * Get the description of a given channel.
+ *
+ * @param channel  a channel layout with a single channel
+ * @return  channel description on success, NULL on error
+ */
+const char *av_get_channel_description(uint64_t channel);
+
+/**
+ * Get the value and name of a standard channel layout.
+ *
+ * @param[in]  index   index in an internal list, starting at 0
+ * @param[out] layout  channel layout mask
+ * @param[out] name    name of the layout
+ * @return  0  if the layout exists,
+ *          <0 if index is beyond the limits
+ */
+int av_get_standard_channel_layout(unsigned index, uint64_t *layout,
+                                   const char **name);
+
+/**
+ * @}
+ */
+
+#endif /* AVUTIL_CHANNEL_LAYOUT_H */

+ 464 - 0
wave420l/code/ffmpeg/include/libavutil/common.h

@@ -0,0 +1,464 @@
+/*
+ * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * common internal and external API header
+ */
+
+#ifndef AVUTIL_COMMON_H
+#define AVUTIL_COMMON_H
+
+#include <errno.h>
+#include <inttypes.h>
+#include <limits.h>
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "attributes.h"
+#include "version.h"
+#include "libavutil/avconfig.h"
+
+#if AV_HAVE_BIGENDIAN
+#   define AV_NE(be, le) (be)
+#else
+#   define AV_NE(be, le) (le)
+#endif
+
+//rounded division & shift
+#define RSHIFT(a,b) ((a) > 0 ? ((a) + ((1<<(b))>>1))>>(b) : ((a) + ((1<<(b))>>1)-1)>>(b))
+/* assume b>0 */
+#define ROUNDED_DIV(a,b) (((a)>0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b))
+/* assume a>0 and b>0 */
+#define FF_CEIL_RSHIFT(a,b) (!av_builtin_constant_p(b) ? -((-(a)) >> (b)) \
+                                                       : ((a) + (1<<(b)) - 1) >> (b))
+#define FFUDIV(a,b) (((a)>0 ?(a):(a)-(b)+1) / (b))
+#define FFUMOD(a,b) ((a)-(b)*FFUDIV(a,b))
+#define FFABS(a) ((a) >= 0 ? (a) : (-(a)))
+#define FFSIGN(a) ((a) > 0 ? 1 : -1)
+
+#define FFMAX(a,b) ((a) > (b) ? (a) : (b))
+#define FFMAX3(a,b,c) FFMAX(FFMAX(a,b),c)
+#define FFMIN(a,b) ((a) > (b) ? (b) : (a))
+#define FFMIN3(a,b,c) FFMIN(FFMIN(a,b),c)
+
+#define FFSWAP(type,a,b) do{type SWAP_tmp= b; b= a; a= SWAP_tmp;}while(0)
+#define FF_ARRAY_ELEMS(a) (sizeof(a) / sizeof((a)[0]))
+#define FFALIGN(x, a) (((x)+(a)-1)&~((a)-1))
+
+/* misc math functions */
+
+/**
+ * Reverse the order of the bits of an 8-bits unsigned integer.
+ */
+#if FF_API_AV_REVERSE
+extern attribute_deprecated const uint8_t av_reverse[256];
+#endif
+
+#ifdef HAVE_AV_CONFIG_H
+#   include "config.h"
+#   include "intmath.h"
+#endif
+
+/* Pull in unguarded fallback defines at the end of this file. */
+#include "common.h"
+
+#ifndef av_log2
+av_const int av_log2(unsigned v);
+#endif
+
+#ifndef av_log2_16bit
+av_const int av_log2_16bit(unsigned v);
+#endif
+
+/**
+ * Clip a signed integer value into the amin-amax range.
+ * @param a value to clip
+ * @param amin minimum value of the clip range
+ * @param amax maximum value of the clip range
+ * @return clipped value
+ */
+static av_always_inline av_const int av_clip_c(int a, int amin, int amax)
+{
+#if defined(HAVE_AV_CONFIG_H) && defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2
+    if (amin > amax) abort();
+#endif
+    if      (a < amin) return amin;
+    else if (a > amax) return amax;
+    else               return a;
+}
+
+/**
+ * Clip a signed 64bit integer value into the amin-amax range.
+ * @param a value to clip
+ * @param amin minimum value of the clip range
+ * @param amax maximum value of the clip range
+ * @return clipped value
+ */
+static av_always_inline av_const int64_t av_clip64_c(int64_t a, int64_t amin, int64_t amax)
+{
+#if defined(HAVE_AV_CONFIG_H) && defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2
+    if (amin > amax) abort();
+#endif
+    if      (a < amin) return amin;
+    else if (a > amax) return amax;
+    else               return a;
+}
+
+/**
+ * Clip a signed integer value into the 0-255 range.
+ * @param a value to clip
+ * @return clipped value
+ */
+static av_always_inline av_const uint8_t av_clip_uint8_c(int a)
+{
+    if (a&(~0xFF)) return (-a)>>31;
+    else           return a;
+}
+
+/**
+ * Clip a signed integer value into the -128,127 range.
+ * @param a value to clip
+ * @return clipped value
+ */
+static av_always_inline av_const int8_t av_clip_int8_c(int a)
+{
+    if ((a+0x80) & ~0xFF) return (a>>31) ^ 0x7F;
+    else                  return a;
+}
+
+/**
+ * Clip a signed integer value into the 0-65535 range.
+ * @param a value to clip
+ * @return clipped value
+ */
+static av_always_inline av_const uint16_t av_clip_uint16_c(int a)
+{
+    if (a&(~0xFFFF)) return (-a)>>31;
+    else             return a;
+}
+
+/**
+ * Clip a signed integer value into the -32768,32767 range.
+ * @param a value to clip
+ * @return clipped value
+ */
+static av_always_inline av_const int16_t av_clip_int16_c(int a)
+{
+    if ((a+0x8000) & ~0xFFFF) return (a>>31) ^ 0x7FFF;
+    else                      return a;
+}
+
+/**
+ * Clip a signed 64-bit integer value into the -2147483648,2147483647 range.
+ * @param a value to clip
+ * @return clipped value
+ */
+static av_always_inline av_const int32_t av_clipl_int32_c(int64_t a)
+{
+    if ((a+0x80000000u) & ~UINT64_C(0xFFFFFFFF)) return (int32_t)((a>>63) ^ 0x7FFFFFFF);
+    else                                         return (int32_t)a;
+}
+
+/**
+ * Clip a signed integer to an unsigned power of two range.
+ * @param  a value to clip
+ * @param  p bit position to clip at
+ * @return clipped value
+ */
+static av_always_inline av_const unsigned av_clip_uintp2_c(int a, int p)
+{
+    if (a & ~((1<<p) - 1)) return -a >> 31 & ((1<<p) - 1);
+    else                   return  a;
+}
+
+/**
+ * Add two signed 32-bit values with saturation.
+ *
+ * @param  a one value
+ * @param  b another value
+ * @return sum with signed saturation
+ */
+static av_always_inline int av_sat_add32_c(int a, int b)
+{
+    return av_clipl_int32((int64_t)a + b);
+}
+
+/**
+ * Add a doubled value to another value with saturation at both stages.
+ *
+ * @param  a first value
+ * @param  b value doubled and added to a
+ * @return sum with signed saturation
+ */
+static av_always_inline int av_sat_dadd32_c(int a, int b)
+{
+    return av_sat_add32(a, av_sat_add32(b, b));
+}
+
+/**
+ * Clip a float value into the amin-amax range.
+ * @param a value to clip
+ * @param amin minimum value of the clip range
+ * @param amax maximum value of the clip range
+ * @return clipped value
+ */
+static av_always_inline av_const float av_clipf_c(float a, float amin, float amax)
+{
+#if defined(HAVE_AV_CONFIG_H) && defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2
+    if (amin > amax) abort();
+#endif
+    if      (a < amin) return amin;
+    else if (a > amax) return amax;
+    else               return a;
+}
+
+/**
+ * Clip a double value into the amin-amax range.
+ * @param a value to clip
+ * @param amin minimum value of the clip range
+ * @param amax maximum value of the clip range
+ * @return clipped value
+ */
+static av_always_inline av_const double av_clipd_c(double a, double amin, double amax)
+{
+#if defined(HAVE_AV_CONFIG_H) && defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2
+    if (amin > amax) abort();
+#endif
+    if      (a < amin) return amin;
+    else if (a > amax) return amax;
+    else               return a;
+}
+
+/** Compute ceil(log2(x)).
+ * @param x value used to compute ceil(log2(x))
+ * @return computed ceiling of log2(x)
+ */
+static av_always_inline av_const int av_ceil_log2_c(int x)
+{
+    return av_log2((x - 1) << 1);
+}
+
+/**
+ * Count number of bits set to one in x
+ * @param x value to count bits of
+ * @return the number of bits set to one in x
+ */
+static av_always_inline av_const int av_popcount_c(uint32_t x)
+{
+    x -= (x >> 1) & 0x55555555;
+    x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
+    x = (x + (x >> 4)) & 0x0F0F0F0F;
+    x += x >> 8;
+    return (x + (x >> 16)) & 0x3F;
+}
+
+/**
+ * Count number of bits set to one in x
+ * @param x value to count bits of
+ * @return the number of bits set to one in x
+ */
+static av_always_inline av_const int av_popcount64_c(uint64_t x)
+{
+    return av_popcount((uint32_t)x) + av_popcount((uint32_t)(x >> 32));
+}
+
+#define MKTAG(a,b,c,d) ((a) | ((b) << 8) | ((c) << 16) | ((unsigned)(d) << 24))
+#define MKBETAG(a,b,c,d) ((d) | ((c) << 8) | ((b) << 16) | ((unsigned)(a) << 24))
+
+/**
+ * Convert a UTF-8 character (up to 4 bytes) to its 32-bit UCS-4 encoded form.
+ *
+ * @param val      Output value, must be an lvalue of type uint32_t.
+ * @param GET_BYTE Expression reading one byte from the input.
+ *                 Evaluated up to 7 times (4 for the currently
+ *                 assigned Unicode range).  With a memory buffer
+ *                 input, this could be *ptr++.
+ * @param ERROR    Expression to be evaluated on invalid input,
+ *                 typically a goto statement.
+ *
+ * @warning ERROR should not contain a loop control statement which
+ * could interact with the internal while loop, and should force an
+ * exit from the macro code (e.g. through a goto or a return) in order
+ * to prevent undefined results.
+ */
+#define GET_UTF8(val, GET_BYTE, ERROR)\
+    val= GET_BYTE;\
+    {\
+        uint32_t top = (val & 128) >> 1;\
+        if ((val & 0xc0) == 0x80 || val >= 0xFE)\
+            ERROR\
+        while (val & top) {\
+            int tmp= GET_BYTE - 128;\
+            if(tmp>>6)\
+                ERROR\
+            val= (val<<6) + tmp;\
+            top <<= 5;\
+        }\
+        val &= (top << 1) - 1;\
+    }
+
+/**
+ * Convert a UTF-16 character (2 or 4 bytes) to its 32-bit UCS-4 encoded form.
+ *
+ * @param val       Output value, must be an lvalue of type uint32_t.
+ * @param GET_16BIT Expression returning two bytes of UTF-16 data converted
+ *                  to native byte order.  Evaluated one or two times.
+ * @param ERROR     Expression to be evaluated on invalid input,
+ *                  typically a goto statement.
+ */
+#define GET_UTF16(val, GET_16BIT, ERROR)\
+    val = GET_16BIT;\
+    {\
+        unsigned int hi = val - 0xD800;\
+        if (hi < 0x800) {\
+            val = GET_16BIT - 0xDC00;\
+            if (val > 0x3FFU || hi > 0x3FFU)\
+                ERROR\
+            val += (hi<<10) + 0x10000;\
+        }\
+    }\
+
+/**
+ * @def PUT_UTF8(val, tmp, PUT_BYTE)
+ * Convert a 32-bit Unicode character to its UTF-8 encoded form (up to 4 bytes long).
+ * @param val is an input-only argument and should be of type uint32_t. It holds
+ * a UCS-4 encoded Unicode character that is to be converted to UTF-8. If
+ * val is given as a function it is executed only once.
+ * @param tmp is a temporary variable and should be of type uint8_t. It
+ * represents an intermediate value during conversion that is to be
+ * output by PUT_BYTE.
+ * @param PUT_BYTE writes the converted UTF-8 bytes to any proper destination.
+ * It could be a function or a statement, and uses tmp as the input byte.
+ * For example, PUT_BYTE could be "*output++ = tmp;" PUT_BYTE will be
+ * executed up to 4 times for values in the valid UTF-8 range and up to
+ * 7 times in the general case, depending on the length of the converted
+ * Unicode character.
+ */
+#define PUT_UTF8(val, tmp, PUT_BYTE)\
+    {\
+        int bytes, shift;\
+        uint32_t in = val;\
+        if (in < 0x80) {\
+            tmp = in;\
+            PUT_BYTE\
+        } else {\
+            bytes = (av_log2(in) + 4) / 5;\
+            shift = (bytes - 1) * 6;\
+            tmp = (256 - (256 >> bytes)) | (in >> shift);\
+            PUT_BYTE\
+            while (shift >= 6) {\
+                shift -= 6;\
+                tmp = 0x80 | ((in >> shift) & 0x3f);\
+                PUT_BYTE\
+            }\
+        }\
+    }
+
+/**
+ * @def PUT_UTF16(val, tmp, PUT_16BIT)
+ * Convert a 32-bit Unicode character to its UTF-16 encoded form (2 or 4 bytes).
+ * @param val is an input-only argument and should be of type uint32_t. It holds
+ * a UCS-4 encoded Unicode character that is to be converted to UTF-16. If
+ * val is given as a function it is executed only once.
+ * @param tmp is a temporary variable and should be of type uint16_t. It
+ * represents an intermediate value during conversion that is to be
+ * output by PUT_16BIT.
+ * @param PUT_16BIT writes the converted UTF-16 data to any proper destination
+ * in desired endianness. It could be a function or a statement, and uses tmp
+ * as the input byte.  For example, PUT_BYTE could be "*output++ = tmp;"
+ * PUT_BYTE will be executed 1 or 2 times depending on input character.
+ */
+#define PUT_UTF16(val, tmp, PUT_16BIT)\
+    {\
+        uint32_t in = val;\
+        if (in < 0x10000) {\
+            tmp = in;\
+            PUT_16BIT\
+        } else {\
+            tmp = 0xD800 | ((in - 0x10000) >> 10);\
+            PUT_16BIT\
+            tmp = 0xDC00 | ((in - 0x10000) & 0x3FF);\
+            PUT_16BIT\
+        }\
+    }\
+
+
+
+#include "mem.h"
+
+#ifdef HAVE_AV_CONFIG_H
+#    include "internal.h"
+#endif /* HAVE_AV_CONFIG_H */
+
+#endif /* AVUTIL_COMMON_H */
+
+/*
+ * The following definitions are outside the multiple inclusion guard
+ * to ensure they are immediately available in intmath.h.
+ */
+
+#ifndef av_ceil_log2
+#   define av_ceil_log2     av_ceil_log2_c
+#endif
+#ifndef av_clip
+#   define av_clip          av_clip_c
+#endif
+#ifndef av_clip64
+#   define av_clip64        av_clip64_c
+#endif
+#ifndef av_clip_uint8
+#   define av_clip_uint8    av_clip_uint8_c
+#endif
+#ifndef av_clip_int8
+#   define av_clip_int8     av_clip_int8_c
+#endif
+#ifndef av_clip_uint16
+#   define av_clip_uint16   av_clip_uint16_c
+#endif
+#ifndef av_clip_int16
+#   define av_clip_int16    av_clip_int16_c
+#endif
+#ifndef av_clipl_int32
+#   define av_clipl_int32   av_clipl_int32_c
+#endif
+#ifndef av_clip_uintp2
+#   define av_clip_uintp2   av_clip_uintp2_c
+#endif
+#ifndef av_sat_add32
+#   define av_sat_add32     av_sat_add32_c
+#endif
+#ifndef av_sat_dadd32
+#   define av_sat_dadd32    av_sat_dadd32_c
+#endif
+#ifndef av_clipf
+#   define av_clipf         av_clipf_c
+#endif
+#ifndef av_clipd
+#   define av_clipd         av_clipd_c
+#endif
+#ifndef av_popcount
+#   define av_popcount      av_popcount_c
+#endif
+#ifndef av_popcount64
+#   define av_popcount64    av_popcount64_c
+#endif

+ 111 - 0
wave420l/code/ffmpeg/include/libavutil/cpu.h

@@ -0,0 +1,111 @@
+/*
+ * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_CPU_H
+#define AVUTIL_CPU_H
+
+#include "attributes.h"
+
+#define AV_CPU_FLAG_FORCE    0x80000000 /* force usage of selected flags (OR) */
+
+    /* lower 16 bits - CPU features */
+#define AV_CPU_FLAG_MMX          0x0001 ///< standard MMX
+#define AV_CPU_FLAG_MMXEXT       0x0002 ///< SSE integer functions or AMD MMX ext
+#define AV_CPU_FLAG_MMX2         0x0002 ///< SSE integer functions or AMD MMX ext
+#define AV_CPU_FLAG_3DNOW        0x0004 ///< AMD 3DNOW
+#define AV_CPU_FLAG_SSE          0x0008 ///< SSE functions
+#define AV_CPU_FLAG_SSE2         0x0010 ///< PIV SSE2 functions
+#define AV_CPU_FLAG_SSE2SLOW 0x40000000 ///< SSE2 supported, but usually not faster
+                                        ///< than regular MMX/SSE (e.g. Core1)
+#define AV_CPU_FLAG_3DNOWEXT     0x0020 ///< AMD 3DNowExt
+#define AV_CPU_FLAG_SSE3         0x0040 ///< Prescott SSE3 functions
+#define AV_CPU_FLAG_SSE3SLOW 0x20000000 ///< SSE3 supported, but usually not faster
+                                        ///< than regular MMX/SSE (e.g. Core1)
+#define AV_CPU_FLAG_SSSE3        0x0080 ///< Conroe SSSE3 functions
+#define AV_CPU_FLAG_ATOM     0x10000000 ///< Atom processor, some SSSE3 instructions are slower
+#define AV_CPU_FLAG_SSE4         0x0100 ///< Penryn SSE4.1 functions
+#define AV_CPU_FLAG_SSE42        0x0200 ///< Nehalem SSE4.2 functions
+#define AV_CPU_FLAG_AVX          0x4000 ///< AVX functions: requires OS support even if YMM registers aren't used
+#define AV_CPU_FLAG_XOP          0x0400 ///< Bulldozer XOP functions
+#define AV_CPU_FLAG_FMA4         0x0800 ///< Bulldozer FMA4 functions
+// #if LIBAVUTIL_VERSION_MAJOR <52
+#define AV_CPU_FLAG_CMOV      0x1001000 ///< supports cmov instruction
+// #else
+// #define AV_CPU_FLAG_CMOV         0x1000 ///< supports cmov instruction
+// #endif
+#define AV_CPU_FLAG_AVX2         0x8000 ///< AVX2 functions: requires OS support even if YMM registers aren't used
+
+#define AV_CPU_FLAG_ALTIVEC      0x0001 ///< standard
+
+#define AV_CPU_FLAG_ARMV5TE      (1 << 0)
+#define AV_CPU_FLAG_ARMV6        (1 << 1)
+#define AV_CPU_FLAG_ARMV6T2      (1 << 2)
+#define AV_CPU_FLAG_VFP          (1 << 3)
+#define AV_CPU_FLAG_VFPV3        (1 << 4)
+#define AV_CPU_FLAG_NEON         (1 << 5)
+
+/**
+ * Return the flags which specify extensions supported by the CPU.
+ * The returned value is affected by av_force_cpu_flags() if that was used
+ * before. So av_get_cpu_flags() can easily be used in a application to
+ * detect the enabled cpu flags.
+ */
+int av_get_cpu_flags(void);
+
+/**
+ * Disables cpu detection and forces the specified flags.
+ * -1 is a special case that disables forcing of specific flags.
+ */
+void av_force_cpu_flags(int flags);
+
+/**
+ * Set a mask on flags returned by av_get_cpu_flags().
+ * This function is mainly useful for testing.
+ * Please use av_force_cpu_flags() and av_get_cpu_flags() instead which are more flexible
+ *
+ * @warning this function is not thread safe.
+ */
+attribute_deprecated void av_set_cpu_flags_mask(int mask);
+
+/**
+ * Parse CPU flags from a string.
+ *
+ * The returned flags contain the specified flags as well as related unspecified flags.
+ *
+ * This function exists only for compatibility with libav.
+ * Please use av_parse_cpu_caps() when possible.
+ * @return a combination of AV_CPU_* flags, negative on error.
+ */
+attribute_deprecated
+int av_parse_cpu_flags(const char *s);
+
+/**
+ * Parse CPU caps from a string and update the given AV_CPU_* flags based on that.
+ *
+ * @return negative on error.
+ */
+int av_parse_cpu_caps(unsigned *flags, const char *s);
+
+/**
+ * @return the number of logical CPU cores present.
+ */
+int av_cpu_count(void);
+
+#endif /* AVUTIL_CPU_H */

+ 85 - 0
wave420l/code/ffmpeg/include/libavutil/crc.h

@@ -0,0 +1,85 @@
+/*
+ * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_CRC_H
+#define AVUTIL_CRC_H
+
+#include <stdint.h>
+#include <stddef.h>
+#include "attributes.h"
+
+/**
+ * @defgroup lavu_crc32 CRC32
+ * @ingroup lavu_crypto
+ * @{
+ */
+
+typedef uint32_t AVCRC;
+
+typedef enum {
+    AV_CRC_8_ATM,
+    AV_CRC_16_ANSI,
+    AV_CRC_16_CCITT,
+    AV_CRC_32_IEEE,
+    AV_CRC_32_IEEE_LE,  /*< reversed bitorder version of AV_CRC_32_IEEE */
+    AV_CRC_24_IEEE = 12,
+    AV_CRC_MAX,         /*< Not part of public API! Do not use outside libavutil. */
+}AVCRCId;
+
+/**
+ * Initialize a CRC table.
+ * @param ctx must be an array of size sizeof(AVCRC)*257 or sizeof(AVCRC)*1024
+ * @param le If 1, the lowest bit represents the coefficient for the highest
+ *           exponent of the corresponding polynomial (both for poly and
+ *           actual CRC).
+ *           If 0, you must swap the CRC parameter and the result of av_crc
+ *           if you need the standard representation (can be simplified in
+ *           most cases to e.g. bswap16):
+ *           av_bswap32(crc << (32-bits))
+ * @param bits number of bits for the CRC
+ * @param poly generator polynomial without the x**bits coefficient, in the
+ *             representation as specified by le
+ * @param ctx_size size of ctx in bytes
+ * @return <0 on failure
+ */
+int av_crc_init(AVCRC *ctx, int le, int bits, uint32_t poly, int ctx_size);
+
+/**
+ * Get an initialized standard CRC table.
+ * @param crc_id ID of a standard CRC
+ * @return a pointer to the CRC table or NULL on failure
+ */
+const AVCRC *av_crc_get_table(AVCRCId crc_id);
+
+/**
+ * Calculate the CRC of a block.
+ * @param crc CRC of previous blocks if any or initial value for CRC
+ * @return CRC updated with the data from the given block
+ *
+ * @see av_crc_init() "le" parameter
+ */
+uint32_t av_crc(const AVCRC *ctx, uint32_t crc,
+                const uint8_t *buffer, size_t length) av_pure;
+
+/**
+ * @}
+ */
+
+#endif /* AVUTIL_CRC_H */

+ 152 - 0
wave420l/code/ffmpeg/include/libavutil/dict.h

@@ -0,0 +1,152 @@
+/*
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * Public dictionary API.
+ * @deprecated
+ *  AVDictionary is provided for compatibility with libav. It is both in
+ *  implementation as well as API inefficient. It does not scale and is
+ *  extremely slow with large dictionaries.
+ *  It is recommended that new code uses our tree container from tree.c/h
+ *  where applicable, which uses AVL trees to achieve O(log n) performance.
+ */
+
+#ifndef AVUTIL_DICT_H
+#define AVUTIL_DICT_H
+
+/**
+ * @addtogroup lavu_dict AVDictionary
+ * @ingroup lavu_data
+ *
+ * @brief Simple key:value store
+ *
+ * @{
+ * Dictionaries are used for storing key:value pairs. To create
+ * an AVDictionary, simply pass an address of a NULL pointer to
+ * av_dict_set(). NULL can be used as an empty dictionary wherever
+ * a pointer to an AVDictionary is required.
+ * Use av_dict_get() to retrieve an entry or iterate over all
+ * entries and finally av_dict_free() to free the dictionary
+ * and all its contents.
+ *
+ * @code
+ * AVDictionary *d = NULL;                // "create" an empty dictionary
+ * av_dict_set(&d, "foo", "bar", 0);      // add an entry
+ *
+ * char *k = av_strdup("key");            // if your strings are already allocated,
+ * char *v = av_strdup("value");          // you can avoid copying them like this
+ * av_dict_set(&d, k, v, AV_DICT_DONT_STRDUP_KEY | AV_DICT_DONT_STRDUP_VAL);
+ *
+ * AVDictionaryEntry *t = NULL;
+ * while (t = av_dict_get(d, "", t, AV_DICT_IGNORE_SUFFIX)) {
+ *     <....>                             // iterate over all entries in d
+ * }
+ *
+ * av_dict_free(&d);
+ * @endcode
+ *
+ */
+
+#define AV_DICT_MATCH_CASE      1
+#define AV_DICT_IGNORE_SUFFIX   2
+#define AV_DICT_DONT_STRDUP_KEY 4   /**< Take ownership of a key that's been
+                                         allocated with av_malloc() and children. */
+#define AV_DICT_DONT_STRDUP_VAL 8   /**< Take ownership of a value that's been
+                                         allocated with av_malloc() and chilren. */
+#define AV_DICT_DONT_OVERWRITE 16   ///< Don't overwrite existing entries.
+#define AV_DICT_APPEND         32   /**< If the entry already exists, append to it.  Note that no
+                                      delimiter is added, the strings are simply concatenated. */
+
+typedef struct AVDictionaryEntry {
+    char *key;
+    char *value;
+} AVDictionaryEntry;
+
+typedef struct AVDictionary AVDictionary;
+
+/**
+ * Get a dictionary entry with matching key.
+ *
+ * @param prev Set to the previous matching element to find the next.
+ *             If set to NULL the first matching element is returned.
+ * @param flags Allows case as well as suffix-insensitive comparisons.
+ * @return Found entry or NULL, changing key or value leads to undefined behavior.
+ */
+AVDictionaryEntry *
+av_dict_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags);
+
+/**
+ * Get number of entries in dictionary.
+ *
+ * @param m dictionary
+ * @return  number of entries in dictionary
+ */
+int av_dict_count(const AVDictionary *m);
+
+/**
+ * Set the given entry in *pm, overwriting an existing entry.
+ *
+ * @param pm pointer to a pointer to a dictionary struct. If *pm is NULL
+ * a dictionary struct is allocated and put in *pm.
+ * @param key entry key to add to *pm (will be av_strduped depending on flags)
+ * @param value entry value to add to *pm (will be av_strduped depending on flags).
+ *        Passing a NULL value will cause an existing entry to be deleted.
+ * @return >= 0 on success otherwise an error code <0
+ */
+int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags);
+
+/**
+ * Parse the key/value pairs list and add to a dictionary.
+ *
+ * @param key_val_sep  a 0-terminated list of characters used to separate
+ *                     key from value
+ * @param pairs_sep    a 0-terminated list of characters used to separate
+ *                     two pairs from each other
+ * @param flags        flags to use when adding to dictionary.
+ *                     AV_DICT_DONT_STRDUP_KEY and AV_DICT_DONT_STRDUP_VAL
+ *                     are ignored since the key/value tokens will always
+ *                     be duplicated.
+ * @return             0 on success, negative AVERROR code on failure
+ */
+int av_dict_parse_string(AVDictionary **pm, const char *str,
+                         const char *key_val_sep, const char *pairs_sep,
+                         int flags);
+
+/**
+ * Copy entries from one AVDictionary struct into another.
+ * @param dst pointer to a pointer to a AVDictionary struct. If *dst is NULL,
+ *            this function will allocate a struct for you and put it in *dst
+ * @param src pointer to source AVDictionary struct
+ * @param flags flags to use when setting entries in *dst
+ * @note metadata is read using the AV_DICT_IGNORE_SUFFIX flag
+ */
+void av_dict_copy(AVDictionary **dst, AVDictionary *src, int flags);
+
+/**
+ * Free all the memory allocated for an AVDictionary struct
+ * and all keys and values.
+ */
+void av_dict_free(AVDictionary **m);
+
+/**
+ * @}
+ */
+
+#endif /* AVUTIL_DICT_H */

+ 117 - 0
wave420l/code/ffmpeg/include/libavutil/error.h

@@ -0,0 +1,117 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * error code definitions
+ */
+
+#ifndef AVUTIL_ERROR_H
+#define AVUTIL_ERROR_H
+
+#include <errno.h>
+#include <stddef.h>
+
+/**
+ * @addtogroup lavu_error
+ *
+ * @{
+ */
+
+
+/* error handling */
+#if EDOM > 0
+#define AVERROR(e) (-(e))   ///< Returns a negative error code from a POSIX error code, to return from library functions.
+#define AVUNERROR(e) (-(e)) ///< Returns a POSIX error code from a library function error return value.
+#else
+/* Some platforms have E* and errno already negated. */
+#define AVERROR(e) (e)
+#define AVUNERROR(e) (e)
+#endif
+
+#define FFERRTAG(a, b, c, d) (-(int)MKTAG(a, b, c, d))
+
+#define AVERROR_BSF_NOT_FOUND      FFERRTAG(0xF8,'B','S','F') ///< Bitstream filter not found
+#define AVERROR_BUG                FFERRTAG( 'B','U','G','!') ///< Internal bug, also see AVERROR_BUG2
+#define AVERROR_BUFFER_TOO_SMALL   FFERRTAG( 'B','U','F','S') ///< Buffer too small
+#define AVERROR_DECODER_NOT_FOUND  FFERRTAG(0xF8,'D','E','C') ///< Decoder not found
+#define AVERROR_DEMUXER_NOT_FOUND  FFERRTAG(0xF8,'D','E','M') ///< Demuxer not found
+#define AVERROR_ENCODER_NOT_FOUND  FFERRTAG(0xF8,'E','N','C') ///< Encoder not found
+#define AVERROR_EOF                FFERRTAG( 'E','O','F',' ') ///< End of file
+#define AVERROR_EXIT               FFERRTAG( 'E','X','I','T') ///< Immediate exit was requested; the called function should not be restarted
+#define AVERROR_EXTERNAL           FFERRTAG( 'E','X','T',' ') ///< Generic error in an external library
+#define AVERROR_FILTER_NOT_FOUND   FFERRTAG(0xF8,'F','I','L') ///< Filter not found
+#define AVERROR_INVALIDDATA        FFERRTAG( 'I','N','D','A') ///< Invalid data found when processing input
+#define AVERROR_MUXER_NOT_FOUND    FFERRTAG(0xF8,'M','U','X') ///< Muxer not found
+#define AVERROR_OPTION_NOT_FOUND   FFERRTAG(0xF8,'O','P','T') ///< Option not found
+#define AVERROR_PATCHWELCOME       FFERRTAG( 'P','A','W','E') ///< Not yet implemented in FFmpeg, patches welcome
+#define AVERROR_PROTOCOL_NOT_FOUND FFERRTAG(0xF8,'P','R','O') ///< Protocol not found
+
+#define AVERROR_STREAM_NOT_FOUND   FFERRTAG(0xF8,'S','T','R') ///< Stream not found
+/**
+ * This is semantically identical to AVERROR_BUG
+ * it has been introduced in Libav after our AVERROR_BUG and with a modified value.
+ */
+#define AVERROR_BUG2               FFERRTAG( 'B','U','G',' ')
+#define AVERROR_UNKNOWN            FFERRTAG( 'U','N','K','N') ///< Unknown error, typically from an external library
+#define AVERROR_EXPERIMENTAL       (-0x2bb2afa8) ///< Requested feature is flagged experimental. Set strict_std_compliance if you really want to use it.
+
+#define AV_ERROR_MAX_STRING_SIZE 64
+
+/**
+ * Put a description of the AVERROR code errnum in errbuf.
+ * In case of failure the global variable errno is set to indicate the
+ * error. Even in case of failure av_strerror() will print a generic
+ * error message indicating the errnum provided to errbuf.
+ *
+ * @param errnum      error code to describe
+ * @param errbuf      buffer to which description is written
+ * @param errbuf_size the size in bytes of errbuf
+ * @return 0 on success, a negative value if a description for errnum
+ * cannot be found
+ */
+int av_strerror(int errnum, char *errbuf, size_t errbuf_size);
+
+/**
+ * Fill the provided buffer with a string containing an error string
+ * corresponding to the AVERROR code errnum.
+ *
+ * @param errbuf         a buffer
+ * @param errbuf_size    size in bytes of errbuf
+ * @param errnum         error code to describe
+ * @return the buffer in input, filled with the error description
+ * @see av_strerror()
+ */
+static inline char *av_make_error_string(char *errbuf, size_t errbuf_size, int errnum)
+{
+    av_strerror(errnum, errbuf, errbuf_size);
+    return errbuf;
+}
+
+/**
+ * Convenience macro, the return value should be used only directly in
+ * function arguments but never stand-alone.
+ */
+#define av_err2str(errnum) \
+    av_make_error_string((char[AV_ERROR_MAX_STRING_SIZE]){0}, AV_ERROR_MAX_STRING_SIZE, errnum)
+
+/**
+ * @}
+ */
+
+#endif /* AVUTIL_ERROR_H */

+ 113 - 0
wave420l/code/ffmpeg/include/libavutil/eval.h

@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2002 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * simple arithmetic expression evaluator
+ */
+
+#ifndef AVUTIL_EVAL_H
+#define AVUTIL_EVAL_H
+
+#include "avutil.h"
+
+typedef struct AVExpr AVExpr;
+
+/**
+ * Parse and evaluate an expression.
+ * Note, this is significantly slower than av_expr_eval().
+ *
+ * @param res a pointer to a double where is put the result value of
+ * the expression, or NAN in case of error
+ * @param s expression as a zero terminated string, for example "1+2^3+5*5+sin(2/3)"
+ * @param const_names NULL terminated array of zero terminated strings of constant identifiers, for example {"PI", "E", 0}
+ * @param const_values a zero terminated array of values for the identifiers from const_names
+ * @param func1_names NULL terminated array of zero terminated strings of funcs1 identifiers
+ * @param funcs1 NULL terminated array of function pointers for functions which take 1 argument
+ * @param func2_names NULL terminated array of zero terminated strings of funcs2 identifiers
+ * @param funcs2 NULL terminated array of function pointers for functions which take 2 arguments
+ * @param opaque a pointer which will be passed to all functions from funcs1 and funcs2
+ * @param log_ctx parent logging context
+ * @return >= 0 in case of success, a negative value corresponding to an
+ * AVERROR code otherwise
+ */
+int av_expr_parse_and_eval(double *res, const char *s,
+                           const char * const *const_names, const double *const_values,
+                           const char * const *func1_names, double (* const *funcs1)(void *, double),
+                           const char * const *func2_names, double (* const *funcs2)(void *, double, double),
+                           void *opaque, int log_offset, void *log_ctx);
+
+/**
+ * Parse an expression.
+ *
+ * @param expr a pointer where is put an AVExpr containing the parsed
+ * value in case of successful parsing, or NULL otherwise.
+ * The pointed to AVExpr must be freed with av_expr_free() by the user
+ * when it is not needed anymore.
+ * @param s expression as a zero terminated string, for example "1+2^3+5*5+sin(2/3)"
+ * @param const_names NULL terminated array of zero terminated strings of constant identifiers, for example {"PI", "E", 0}
+ * @param func1_names NULL terminated array of zero terminated strings of funcs1 identifiers
+ * @param funcs1 NULL terminated array of function pointers for functions which take 1 argument
+ * @param func2_names NULL terminated array of zero terminated strings of funcs2 identifiers
+ * @param funcs2 NULL terminated array of function pointers for functions which take 2 arguments
+ * @param log_ctx parent logging context
+ * @return >= 0 in case of success, a negative value corresponding to an
+ * AVERROR code otherwise
+ */
+int av_expr_parse(AVExpr **expr, const char *s,
+                  const char * const *const_names,
+                  const char * const *func1_names, double (* const *funcs1)(void *, double),
+                  const char * const *func2_names, double (* const *funcs2)(void *, double, double),
+                  int log_offset, void *log_ctx);
+
+/**
+ * Evaluate a previously parsed expression.
+ *
+ * @param const_values a zero terminated array of values for the identifiers from av_expr_parse() const_names
+ * @param opaque a pointer which will be passed to all functions from funcs1 and funcs2
+ * @return the value of the expression
+ */
+double av_expr_eval(AVExpr *e, const double *const_values, void *opaque);
+
+/**
+ * Free a parsed expression previously created with av_expr_parse().
+ */
+void av_expr_free(AVExpr *e);
+
+/**
+ * Parse the string in numstr and return its value as a double. If
+ * the string is empty, contains only whitespaces, or does not contain
+ * an initial substring that has the expected syntax for a
+ * floating-point number, no conversion is performed. In this case,
+ * returns a value of zero and the value returned in tail is the value
+ * of numstr.
+ *
+ * @param numstr a string representing a number, may contain one of
+ * the International System number postfixes, for example 'K', 'M',
+ * 'G'. If 'i' is appended after the postfix, powers of 2 are used
+ * instead of powers of 10. The 'B' postfix multiplies the value for
+ * 8, and can be appended after another postfix or used alone. This
+ * allows using for example 'KB', 'MiB', 'G' and 'B' as postfix.
+ * @param tail if non-NULL puts here the pointer to the char next
+ * after the last parsed character
+ */
+double av_strtod(const char *numstr, char **tail);
+
+#endif /* AVUTIL_EVAL_H */

+ 144 - 0
wave420l/code/ffmpeg/include/libavutil/fifo.h

@@ -0,0 +1,144 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * a very simple circular buffer FIFO implementation
+ */
+
+#ifndef AVUTIL_FIFO_H
+#define AVUTIL_FIFO_H
+
+#include <stdint.h>
+#include "avutil.h"
+#include "attributes.h"
+
+typedef struct AVFifoBuffer {
+    uint8_t *buffer;
+    uint8_t *rptr, *wptr, *end;
+    uint32_t rndx, wndx;
+} AVFifoBuffer;
+
+/**
+ * Initialize an AVFifoBuffer.
+ * @param size of FIFO
+ * @return AVFifoBuffer or NULL in case of memory allocation failure
+ */
+AVFifoBuffer *av_fifo_alloc(unsigned int size);
+
+/**
+ * Free an AVFifoBuffer.
+ * @param f AVFifoBuffer to free
+ */
+void av_fifo_free(AVFifoBuffer *f);
+
+/**
+ * Reset the AVFifoBuffer to the state right after av_fifo_alloc, in particular it is emptied.
+ * @param f AVFifoBuffer to reset
+ */
+void av_fifo_reset(AVFifoBuffer *f);
+
+/**
+ * Return the amount of data in bytes in the AVFifoBuffer, that is the
+ * amount of data you can read from it.
+ * @param f AVFifoBuffer to read from
+ * @return size
+ */
+int av_fifo_size(AVFifoBuffer *f);
+
+/**
+ * Return the amount of space in bytes in the AVFifoBuffer, that is the
+ * amount of data you can write into it.
+ * @param f AVFifoBuffer to write into
+ * @return size
+ */
+int av_fifo_space(AVFifoBuffer *f);
+
+/**
+ * Feed data from an AVFifoBuffer to a user-supplied callback.
+ * @param f AVFifoBuffer to read from
+ * @param buf_size number of bytes to read
+ * @param func generic read function
+ * @param dest data destination
+ */
+int av_fifo_generic_read(AVFifoBuffer *f, void *dest, int buf_size, void (*func)(void*, void*, int));
+
+/**
+ * Feed data from a user-supplied callback to an AVFifoBuffer.
+ * @param f AVFifoBuffer to write to
+ * @param src data source; non-const since it may be used as a
+ * modifiable context by the function defined in func
+ * @param size number of bytes to write
+ * @param func generic write function; the first parameter is src,
+ * the second is dest_buf, the third is dest_buf_size.
+ * func must return the number of bytes written to dest_buf, or <= 0 to
+ * indicate no more data available to write.
+ * If func is NULL, src is interpreted as a simple byte array for source data.
+ * @return the number of bytes written to the FIFO
+ */
+int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int (*func)(void*, void*, int));
+
+/**
+ * Resize an AVFifoBuffer.
+ * In case of reallocation failure, the old FIFO is kept unchanged.
+ *
+ * @param f AVFifoBuffer to resize
+ * @param size new AVFifoBuffer size in bytes
+ * @return <0 for failure, >=0 otherwise
+ */
+int av_fifo_realloc2(AVFifoBuffer *f, unsigned int size);
+
+/**
+ * Enlarge an AVFifoBuffer.
+ * In case of reallocation failure, the old FIFO is kept unchanged.
+ * The new fifo size may be larger than the requested size.
+ *
+ * @param f AVFifoBuffer to resize
+ * @param additional_space the amount of space in bytes to allocate in addition to av_fifo_size()
+ * @return <0 for failure, >=0 otherwise
+ */
+int av_fifo_grow(AVFifoBuffer *f, unsigned int additional_space);
+
+/**
+ * Read and discard the specified amount of data from an AVFifoBuffer.
+ * @param f AVFifoBuffer to read from
+ * @param size amount of data to read in bytes
+ */
+void av_fifo_drain(AVFifoBuffer *f, int size);
+
+/**
+ * Return a pointer to the data stored in a FIFO buffer at a certain offset.
+ * The FIFO buffer is not modified.
+ *
+ * @param f    AVFifoBuffer to peek at, f must be non-NULL
+ * @param offs an offset in bytes, its absolute value must be less
+ *             than the used buffer size or the returned pointer will
+ *             point outside to the buffer data.
+ *             The used buffer size can be checked with av_fifo_size().
+ */
+static inline uint8_t *av_fifo_peek2(const AVFifoBuffer *f, int offs)
+{
+    uint8_t *ptr = f->rptr + offs;
+    if (ptr >= f->end)
+        ptr = f->buffer + (ptr - f->end);
+    else if (ptr < f->buffer)
+        ptr = f->end - (f->buffer - ptr);
+    return ptr;
+}
+
+#endif /* AVUTIL_FIFO_H */

+ 66 - 0
wave420l/code/ffmpeg/include/libavutil/file.h

@@ -0,0 +1,66 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_FILE_H
+#define AVUTIL_FILE_H
+
+#include <stdint.h>
+
+#include "avutil.h"
+
+/**
+ * @file
+ * Misc file utilities.
+ */
+
+/**
+ * Read the file with name filename, and put its content in a newly
+ * allocated buffer or map it with mmap() when available.
+ * In case of success set *bufptr to the read or mmapped buffer, and
+ * *size to the size in bytes of the buffer in *bufptr.
+ * The returned buffer must be released with av_file_unmap().
+ *
+ * @param log_offset loglevel offset used for logging
+ * @param log_ctx context used for logging
+ * @return a non negative number in case of success, a negative value
+ * corresponding to an AVERROR error code in case of failure
+ */
+int av_file_map(const char *filename, uint8_t **bufptr, size_t *size,
+                int log_offset, void *log_ctx);
+
+/**
+ * Unmap or free the buffer bufptr created by av_file_map().
+ *
+ * @param size size in bytes of bufptr, must be the same as returned
+ * by av_file_map()
+ */
+void av_file_unmap(uint8_t *bufptr, size_t size);
+
+/**
+ * Wrapper to work around the lack of mkstemp() on mingw.
+ * Also, tries to create file in /tmp first, if possible.
+ * *prefix can be a character constant; *filename will be allocated internally.
+ * @return file descriptor of opened file (or -1 on error)
+ * and opened file name in **filename.
+ * @note On very old libcs it is necessary to set a secure umask before
+ *       calling this, av_tempfile() can't call umask itself as it is used in
+ *       libraries and could interfere with the calling application.
+ */
+int av_tempfile(const char *prefix, char **filename, int log_offset, void *log_ctx);
+
+#endif /* AVUTIL_FILE_H */

+ 659 - 0
wave420l/code/ffmpeg/include/libavutil/frame.h

@@ -0,0 +1,659 @@
+/*
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_FRAME_H
+#define AVUTIL_FRAME_H
+
+#include <stdint.h>
+
+#include "libavcodec/version.h"
+
+#include "avutil.h"
+#include "buffer.h"
+#include "dict.h"
+#include "rational.h"
+#include "samplefmt.h"
+
+enum AVColorSpace{
+    AVCOL_SPC_RGB         = 0,
+    AVCOL_SPC_BT709       = 1, ///< also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / SMPTE RP177 Annex B
+    AVCOL_SPC_UNSPECIFIED = 2,
+    AVCOL_SPC_FCC         = 4,
+    AVCOL_SPC_BT470BG     = 5, ///< also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601
+    AVCOL_SPC_SMPTE170M   = 6, ///< also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC / functionally identical to above
+    AVCOL_SPC_SMPTE240M   = 7,
+    AVCOL_SPC_YCOCG       = 8, ///< Used by Dirac / VC-2 and H.264 FRext, see ITU-T SG16
+    AVCOL_SPC_NB             , ///< Not part of ABI
+};
+#define AVCOL_SPC_YCGCO AVCOL_SPC_YCOCG
+
+enum AVColorRange{
+    AVCOL_RANGE_UNSPECIFIED = 0,
+    AVCOL_RANGE_MPEG        = 1, ///< the normal 219*2^(n-8) "MPEG" YUV ranges
+    AVCOL_RANGE_JPEG        = 2, ///< the normal     2^n-1   "JPEG" YUV ranges
+    AVCOL_RANGE_NB             , ///< Not part of ABI
+};
+
+enum AVFrameSideDataType {
+    /**
+     * The data is the AVPanScan struct defined in libavcodec.
+     */
+    AV_FRAME_DATA_PANSCAN,
+};
+
+typedef struct AVFrameSideData {
+    enum AVFrameSideDataType type;
+    uint8_t *data;
+    int      size;
+    AVDictionary *metadata;
+} AVFrameSideData;
+
+/**
+ * This structure describes decoded (raw) audio or video data.
+ *
+ * AVFrame must be allocated using av_frame_alloc(). Note that this only
+ * allocates the AVFrame itself, the buffers for the data must be managed
+ * through other means (see below).
+ * AVFrame must be freed with av_frame_free().
+ *
+ * AVFrame is typically allocated once and then reused multiple times to hold
+ * different data (e.g. a single AVFrame to hold frames received from a
+ * decoder). In such a case, av_frame_unref() will free any references held by
+ * the frame and reset it to its original clean state before it
+ * is reused again.
+ *
+ * The data described by an AVFrame is usually reference counted through the
+ * AVBuffer API. The underlying buffer references are stored in AVFrame.buf /
+ * AVFrame.extended_buf. An AVFrame is considered to be reference counted if at
+ * least one reference is set, i.e. if AVFrame.buf[0] != NULL. In such a case,
+ * every single data plane must be contained in one of the buffers in
+ * AVFrame.buf or AVFrame.extended_buf.
+ * There may be a single buffer for all the data, or one separate buffer for
+ * each plane, or anything in between.
+ *
+ * sizeof(AVFrame) is not a part of the public ABI, so new fields may be added
+ * to the end with a minor bump.
+ * Similarly fields that are marked as to be only accessed by
+ * av_opt_ptr() can be reordered. This allows 2 forks to add fields
+ * without breaking compatibility with each other.
+ */
+typedef struct AVFrame {
+#define AV_NUM_DATA_POINTERS 8
+    /**
+     * pointer to the picture/channel planes.
+     * This might be different from the first allocated byte
+     *
+     * Some decoders access areas outside 0,0 - width,height, please
+     * see avcodec_align_dimensions2(). Some filters and swscale can read
+     * up to 16 bytes beyond the planes, if these filters are to be used,
+     * then 16 extra bytes must be allocated.
+     */
+    uint8_t *data[AV_NUM_DATA_POINTERS];
+
+    /**
+     * For video, size in bytes of each picture line.
+     * For audio, size in bytes of each plane.
+     *
+     * For audio, only linesize[0] may be set. For planar audio, each channel
+     * plane must be the same size.
+     *
+     * For video the linesizes should be multiplies of the CPUs alignment
+     * preference, this is 16 or 32 for modern desktop CPUs.
+     * Some code requires such alignment other code can be slower without
+     * correct alignment, for yet other it makes no difference.
+     *
+     * @note The linesize may be larger than the size of usable data -- there
+     * may be extra padding present for performance reasons.
+     */
+    int linesize[AV_NUM_DATA_POINTERS];
+
+    /**
+     * pointers to the data planes/channels.
+     *
+     * For video, this should simply point to data[].
+     *
+     * For planar audio, each channel has a separate data pointer, and
+     * linesize[0] contains the size of each channel buffer.
+     * For packed audio, there is just one data pointer, and linesize[0]
+     * contains the total size of the buffer for all channels.
+     *
+     * Note: Both data and extended_data should always be set in a valid frame,
+     * but for planar audio with more channels that can fit in data,
+     * extended_data must be used in order to access all channels.
+     */
+    uint8_t **extended_data;
+
+    /**
+     * width and height of the video frame
+     */
+    int width, height;
+
+    /**
+     * number of audio samples (per channel) described by this frame
+     */
+    int nb_samples;
+
+    /**
+     * format of the frame, -1 if unknown or unset
+     * Values correspond to enum AVPixelFormat for video frames,
+     * enum AVSampleFormat for audio)
+     */
+    int format;
+
+    /**
+     * 1 -> keyframe, 0-> not
+     */
+    int key_frame;
+
+    /**
+     * Picture type of the frame.
+     */
+    enum AVPictureType pict_type;
+
+#if FF_API_AVFRAME_LAVC
+    attribute_deprecated
+    uint8_t *base[AV_NUM_DATA_POINTERS];
+#endif
+
+    /**
+     * Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
+     */
+    AVRational sample_aspect_ratio;
+
+    /**
+     * Presentation timestamp in time_base units (time when frame should be shown to user).
+     */
+    int64_t pts;
+
+    /**
+     * PTS copied from the AVPacket that was decoded to produce this frame.
+     */
+    int64_t pkt_pts;
+
+    /**
+     * DTS copied from the AVPacket that triggered returning this frame. (if frame threading isnt used)
+     * This is also the Presentation time of this AVFrame calculated from
+     * only AVPacket.dts values without pts values.
+     */
+    int64_t pkt_dts;
+
+    /**
+     * picture number in bitstream order
+     */
+    int coded_picture_number;
+    /**
+     * picture number in display order
+     */
+    int display_picture_number;
+
+    /**
+     * quality (between 1 (good) and FF_LAMBDA_MAX (bad))
+     */
+    int quality;
+
+#if FF_API_AVFRAME_LAVC
+    attribute_deprecated
+    int reference;
+
+    /**
+     * QP table
+     */
+    attribute_deprecated
+    int8_t *qscale_table;
+    /**
+     * QP store stride
+     */
+    attribute_deprecated
+    int qstride;
+
+    attribute_deprecated
+    int qscale_type;
+
+    /**
+     * mbskip_table[mb]>=1 if MB didn't change
+     * stride= mb_width = (width+15)>>4
+     */
+    attribute_deprecated
+    uint8_t *mbskip_table;
+
+    /**
+     * motion vector table
+     * @code
+     * example:
+     * int mv_sample_log2= 4 - motion_subsample_log2;
+     * int mb_width= (width+15)>>4;
+     * int mv_stride= (mb_width << mv_sample_log2) + 1;
+     * motion_val[direction][x + y*mv_stride][0->mv_x, 1->mv_y];
+     * @endcode
+     */
+    attribute_deprecated
+    int16_t (*motion_val[2])[2];
+
+    /**
+     * macroblock type table
+     * mb_type_base + mb_width + 2
+     */
+    attribute_deprecated
+    uint32_t *mb_type;
+
+    /**
+     * DCT coefficients
+     */
+    attribute_deprecated
+    short *dct_coeff;
+
+    /**
+     * motion reference frame index
+     * the order in which these are stored can depend on the codec.
+     */
+    attribute_deprecated
+    int8_t *ref_index[2];
+#endif
+
+    /**
+     * for some private data of the user
+     */
+    void *opaque;
+
+    /**
+     * error
+     */
+    uint64_t error[AV_NUM_DATA_POINTERS];
+
+#if FF_API_AVFRAME_LAVC
+    attribute_deprecated
+    int type;
+#endif
+
+    /**
+     * When decoding, this signals how much the picture must be delayed.
+     * extra_delay = repeat_pict / (2*fps)
+     */
+    int repeat_pict;
+
+    /**
+     * The content of the picture is interlaced.
+     */
+    int interlaced_frame;
+
+    /**
+     * If the content is interlaced, is top field displayed first.
+     */
+    int top_field_first;
+
+    /**
+     * Tell user application that palette has changed from previous frame.
+     */
+    int palette_has_changed;
+
+#if FF_API_AVFRAME_LAVC
+    attribute_deprecated
+    int buffer_hints;
+
+    /**
+     * Pan scan.
+     */
+    attribute_deprecated
+    struct AVPanScan *pan_scan;
+#endif
+
+    /**
+     * reordered opaque 64bit (generally an integer or a double precision float
+     * PTS but can be anything).
+     * The user sets AVCodecContext.reordered_opaque to represent the input at
+     * that time,
+     * the decoder reorders values as needed and sets AVFrame.reordered_opaque
+     * to exactly one of the values provided by the user through AVCodecContext.reordered_opaque
+     * @deprecated in favor of pkt_pts
+     */
+    int64_t reordered_opaque;
+
+#if FF_API_AVFRAME_LAVC
+    /**
+     * @deprecated this field is unused
+     */
+    attribute_deprecated void *hwaccel_picture_private;
+
+    attribute_deprecated
+    struct AVCodecContext *owner;
+    attribute_deprecated
+    void *thread_opaque;
+
+    /**
+     * log2 of the size of the block which a single vector in motion_val represents:
+     * (4->16x16, 3->8x8, 2-> 4x4, 1-> 2x2)
+     */
+    attribute_deprecated
+    uint8_t motion_subsample_log2;
+#endif
+
+    /**
+     * Sample rate of the audio data.
+     */
+    int sample_rate;
+
+    /**
+     * Channel layout of the audio data.
+     */
+    uint64_t channel_layout;
+
+    /**
+     * AVBuffer references backing the data for this frame. If all elements of
+     * this array are NULL, then this frame is not reference counted.
+     *
+     * There may be at most one AVBuffer per data plane, so for video this array
+     * always contains all the references. For planar audio with more than
+     * AV_NUM_DATA_POINTERS channels, there may be more buffers than can fit in
+     * this array. Then the extra AVBufferRef pointers are stored in the
+     * extended_buf array.
+     */
+    AVBufferRef *buf[AV_NUM_DATA_POINTERS];
+
+    /**
+     * For planar audio which requires more than AV_NUM_DATA_POINTERS
+     * AVBufferRef pointers, this array will hold all the references which
+     * cannot fit into AVFrame.buf.
+     *
+     * Note that this is different from AVFrame.extended_data, which always
+     * contains all the pointers. This array only contains the extra pointers,
+     * which cannot fit into AVFrame.buf.
+     *
+     * This array is always allocated using av_malloc() by whoever constructs
+     * the frame. It is freed in av_frame_unref().
+     */
+    AVBufferRef **extended_buf;
+    /**
+     * Number of elements in extended_buf.
+     */
+    int        nb_extended_buf;
+
+    AVFrameSideData **side_data;
+    int            nb_side_data;
+
+    /**
+     * frame timestamp estimated using various heuristics, in stream time base
+     * Code outside libavcodec should access this field using:
+     * av_frame_get_best_effort_timestamp(frame)
+     * - encoding: unused
+     * - decoding: set by libavcodec, read by user.
+     */
+    int64_t best_effort_timestamp;
+
+    /**
+     * reordered pos from the last AVPacket that has been input into the decoder
+     * Code outside libavcodec should access this field using:
+     * av_frame_get_pkt_pos(frame)
+     * - encoding: unused
+     * - decoding: Read by user.
+     */
+    int64_t pkt_pos;
+
+    /**
+     * duration of the corresponding packet, expressed in
+     * AVStream->time_base units, 0 if unknown.
+     * Code outside libavcodec should access this field using:
+     * av_frame_get_pkt_duration(frame)
+     * - encoding: unused
+     * - decoding: Read by user.
+     */
+    int64_t pkt_duration;
+
+    /**
+     * metadata.
+     * Code outside libavcodec should access this field using:
+     * av_frame_get_metadata(frame)
+     * - encoding: Set by user.
+     * - decoding: Set by libavcodec.
+     */
+    AVDictionary *metadata;
+
+    /**
+     * decode error flags of the frame, set to a combination of
+     * FF_DECODE_ERROR_xxx flags if the decoder produced a frame, but there
+     * were errors during the decoding.
+     * Code outside libavcodec should access this field using:
+     * av_frame_get_decode_error_flags(frame)
+     * - encoding: unused
+     * - decoding: set by libavcodec, read by user.
+     */
+    int decode_error_flags;
+#define FF_DECODE_ERROR_INVALID_BITSTREAM   1
+#define FF_DECODE_ERROR_MISSING_REFERENCE   2
+
+    /**
+     * number of audio channels, only used for audio.
+     * Code outside libavcodec should access this field using:
+     * av_frame_get_channels(frame)
+     * - encoding: unused
+     * - decoding: Read by user.
+     */
+    int channels;
+
+    /**
+     * size of the corresponding packet containing the compressed
+     * frame. It must be accessed using av_frame_get_pkt_size() and
+     * av_frame_set_pkt_size().
+     * It is set to a negative value if unknown.
+     * - encoding: unused
+     * - decoding: set by libavcodec, read by user.
+     */
+    int pkt_size;
+
+    /**
+     * YUV colorspace type.
+     * It must be accessed using av_frame_get_colorspace() and
+     * av_frame_set_colorspace().
+     * - encoding: Set by user
+     * - decoding: Set by libavcodec
+     */
+    enum AVColorSpace colorspace;
+
+    /**
+     * MPEG vs JPEG YUV range.
+     * It must be accessed using av_frame_get_color_range() and
+     * av_frame_set_color_range().
+     * - encoding: Set by user
+     * - decoding: Set by libavcodec
+     */
+    enum AVColorRange color_range;
+
+
+    /**
+     * Not to be accessed directly from outside libavutil
+     */
+    AVBufferRef *qp_table_buf;
+} AVFrame;
+
+/**
+ * Accessors for some AVFrame fields.
+ * The position of these field in the structure is not part of the ABI,
+ * they should not be accessed directly outside libavcodec.
+ */
+int64_t av_frame_get_best_effort_timestamp(const AVFrame *frame);
+void    av_frame_set_best_effort_timestamp(AVFrame *frame, int64_t val);
+int64_t av_frame_get_pkt_duration         (const AVFrame *frame);
+void    av_frame_set_pkt_duration         (AVFrame *frame, int64_t val);
+int64_t av_frame_get_pkt_pos              (const AVFrame *frame);
+void    av_frame_set_pkt_pos              (AVFrame *frame, int64_t val);
+int64_t av_frame_get_channel_layout       (const AVFrame *frame);
+void    av_frame_set_channel_layout       (AVFrame *frame, int64_t val);
+int     av_frame_get_channels             (const AVFrame *frame);
+void    av_frame_set_channels             (AVFrame *frame, int     val);
+int     av_frame_get_sample_rate          (const AVFrame *frame);
+void    av_frame_set_sample_rate          (AVFrame *frame, int     val);
+AVDictionary *av_frame_get_metadata       (const AVFrame *frame);
+void          av_frame_set_metadata       (AVFrame *frame, AVDictionary *val);
+int     av_frame_get_decode_error_flags   (const AVFrame *frame);
+void    av_frame_set_decode_error_flags   (AVFrame *frame, int     val);
+int     av_frame_get_pkt_size(const AVFrame *frame);
+void    av_frame_set_pkt_size(AVFrame *frame, int val);
+AVDictionary **avpriv_frame_get_metadatap(AVFrame *frame);
+int8_t *av_frame_get_qp_table(AVFrame *f, int *stride, int *type);
+int av_frame_set_qp_table(AVFrame *f, AVBufferRef *buf, int stride, int type);
+enum AVColorSpace av_frame_get_colorspace(const AVFrame *frame);
+void    av_frame_set_colorspace(AVFrame *frame, enum AVColorSpace val);
+enum AVColorRange av_frame_get_color_range(const AVFrame *frame);
+void    av_frame_set_color_range(AVFrame *frame, enum AVColorRange val);
+
+/**
+ * Get the name of a colorspace.
+ * @return a static string identifying the colorspace; can be NULL.
+ */
+const char *av_get_colorspace_name(enum AVColorSpace val);
+
+/**
+ * Allocate an AVFrame and set its fields to default values.  The resulting
+ * struct must be freed using av_frame_free().
+ *
+ * @return An AVFrame filled with default values or NULL on failure.
+ *
+ * @note this only allocates the AVFrame itself, not the data buffers. Those
+ * must be allocated through other means, e.g. with av_frame_get_buffer() or
+ * manually.
+ */
+AVFrame *av_frame_alloc(void);
+
+/**
+ * Free the frame and any dynamically allocated objects in it,
+ * e.g. extended_data. If the frame is reference counted, it will be
+ * unreferenced first.
+ *
+ * @param frame frame to be freed. The pointer will be set to NULL.
+ */
+void av_frame_free(AVFrame **frame);
+
+/**
+ * Setup a new reference to the data described by a given frame.
+ *
+ * Copy frame properties from src to dst and create a new reference for each
+ * AVBufferRef from src.
+ *
+ * If src is not reference counted, new buffers are allocated and the data is
+ * copied.
+ *
+ * @return 0 on success, a negative AVERROR on error
+ */
+int av_frame_ref(AVFrame *dst, AVFrame *src);
+
+/**
+ * Create a new frame that references the same data as src.
+ *
+ * This is a shortcut for av_frame_alloc()+av_frame_ref().
+ *
+ * @return newly created AVFrame on success, NULL on error.
+ */
+AVFrame *av_frame_clone(AVFrame *src);
+
+/**
+ * Unreference all the buffers referenced by frame and reset the frame fields.
+ */
+void av_frame_unref(AVFrame *frame);
+
+/**
+ * Move everythnig contained in src to dst and reset src.
+ */
+void av_frame_move_ref(AVFrame *dst, AVFrame *src);
+
+/**
+ * Allocate new buffer(s) for audio or video data.
+ *
+ * The following fields must be set on frame before calling this function:
+ * - format (pixel format for video, sample format for audio)
+ * - width and height for video
+ * - nb_samples and channel_layout for audio
+ *
+ * This function will fill AVFrame.data and AVFrame.buf arrays and, if
+ * necessary, allocate and fill AVFrame.extended_data and AVFrame.extended_buf.
+ * For planar formats, one buffer will be allocated for each plane.
+ *
+ * @param frame frame in which to store the new buffers.
+ * @param align required buffer size alignment
+ *
+ * @return 0 on success, a negative AVERROR on error.
+ */
+int av_frame_get_buffer(AVFrame *frame, int align);
+
+/**
+ * Check if the frame data is writable.
+ *
+ * @return A positive value if the frame data is writable (which is true if and
+ * only if each of the underlying buffers has only one reference, namely the one
+ * stored in this frame). Return 0 otherwise.
+ *
+ * If 1 is returned the answer is valid until av_buffer_ref() is called on any
+ * of the underlying AVBufferRefs (e.g. through av_frame_ref() or directly).
+ *
+ * @see av_frame_make_writable(), av_buffer_is_writable()
+ */
+int av_frame_is_writable(AVFrame *frame);
+
+/**
+ * Ensure that the frame data is writable, avoiding data copy if possible.
+ *
+ * Do nothing if the frame is writable, allocate new buffers and copy the data
+ * if it is not.
+ *
+ * @return 0 on success, a negative AVERROR on error.
+ *
+ * @see av_frame_is_writable(), av_buffer_is_writable(),
+ * av_buffer_make_writable()
+ */
+int av_frame_make_writable(AVFrame *frame);
+
+/**
+ * Copy only "metadata" fields from src to dst.
+ *
+ * Metadata for the purpose of this function are those fields that do not affect
+ * the data layout in the buffers.  E.g. pts, sample rate (for audio) or sample
+ * aspect ratio (for video), but not width/height or channel layout.
+ * Side data is also copied.
+ */
+int av_frame_copy_props(AVFrame *dst, const AVFrame *src);
+
+/**
+ * Get the buffer reference a given data plane is stored in.
+ *
+ * @param plane index of the data plane of interest in frame->extended_data.
+ *
+ * @return the buffer reference that contains the plane or NULL if the input
+ * frame is not valid.
+ */
+AVBufferRef *av_frame_get_plane_buffer(AVFrame *frame, int plane);
+
+/**
+ * Add a new side data to a frame.
+ *
+ * @param frame a frame to which the side data should be added
+ * @param type type of the added side data
+ * @param size size of the side data
+ *
+ * @return newly added side data on success, NULL on error
+ */
+AVFrameSideData *av_frame_new_side_data(AVFrame *frame,
+                                        enum AVFrameSideDataType type,
+                                        int size);
+
+/**
+ * @return a pointer to the side data of a given type on success, NULL if there
+ * is no side data with such type in this frame.
+ */
+AVFrameSideData *av_frame_get_side_data(const AVFrame *frame,
+                                        enum AVFrameSideDataType type);
+
+#endif /* AVUTIL_FRAME_H */

+ 99 - 0
wave420l/code/ffmpeg/include/libavutil/hmac.h

@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2012 Martin Storsjo
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_HMAC_H
+#define AVUTIL_HMAC_H
+
+#include <stdint.h>
+
+/**
+ * @defgroup lavu_hmac HMAC
+ * @ingroup lavu_crypto
+ * @{
+ */
+
+enum AVHMACType {
+    AV_HMAC_MD5,
+    AV_HMAC_SHA1,
+    AV_HMAC_SHA224 = 10,
+    AV_HMAC_SHA256,
+    AV_HMAC_SHA384,
+    AV_HMAC_SHA512,
+};
+
+typedef struct AVHMAC AVHMAC;
+
+/**
+ * Allocate an AVHMAC context.
+ * @param type The hash function used for the HMAC.
+ */
+AVHMAC *av_hmac_alloc(enum AVHMACType type);
+
+/**
+ * Free an AVHMAC context.
+ * @param ctx The context to free, may be NULL
+ */
+void av_hmac_free(AVHMAC *ctx);
+
+/**
+ * Initialize an AVHMAC context with an authentication key.
+ * @param ctx    The HMAC context
+ * @param key    The authentication key
+ * @param keylen The length of the key, in bytes
+ */
+void av_hmac_init(AVHMAC *ctx, const uint8_t *key, unsigned int keylen);
+
+/**
+ * Hash data with the HMAC.
+ * @param ctx  The HMAC context
+ * @param data The data to hash
+ * @param len  The length of the data, in bytes
+ */
+void av_hmac_update(AVHMAC *ctx, const uint8_t *data, unsigned int len);
+
+/**
+ * Finish hashing and output the HMAC digest.
+ * @param ctx    The HMAC context
+ * @param out    The output buffer to write the digest into
+ * @param outlen The length of the out buffer, in bytes
+ * @return       The number of bytes written to out, or a negative error code.
+ */
+int av_hmac_final(AVHMAC *ctx, uint8_t *out, unsigned int outlen);
+
+/**
+ * Hash an array of data with a key.
+ * @param ctx    The HMAC context
+ * @param data   The data to hash
+ * @param len    The length of the data, in bytes
+ * @param key    The authentication key
+ * @param keylen The length of the key, in bytes
+ * @param out    The output buffer to write the digest into
+ * @param outlen The length of the out buffer, in bytes
+ * @return       The number of bytes written to out, or a negative error code.
+ */
+int av_hmac_calc(AVHMAC *ctx, const uint8_t *data, unsigned int len,
+                 const uint8_t *key, unsigned int keylen,
+                 uint8_t *out, unsigned int outlen);
+
+/**
+ * @}
+ */
+
+#endif /* AVUTIL_HMAC_H */

+ 200 - 0
wave420l/code/ffmpeg/include/libavutil/imgutils.h

@@ -0,0 +1,200 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_IMGUTILS_H
+#define AVUTIL_IMGUTILS_H
+
+/**
+ * @file
+ * misc image utilities
+ *
+ * @addtogroup lavu_picture
+ * @{
+ */
+
+#include "avutil.h"
+#include "pixdesc.h"
+
+/**
+ * Compute the max pixel step for each plane of an image with a
+ * format described by pixdesc.
+ *
+ * The pixel step is the distance in bytes between the first byte of
+ * the group of bytes which describe a pixel component and the first
+ * byte of the successive group in the same plane for the same
+ * component.
+ *
+ * @param max_pixsteps an array which is filled with the max pixel step
+ * for each plane. Since a plane may contain different pixel
+ * components, the computed max_pixsteps[plane] is relative to the
+ * component in the plane with the max pixel step.
+ * @param max_pixstep_comps an array which is filled with the component
+ * for each plane which has the max pixel step. May be NULL.
+ */
+void av_image_fill_max_pixsteps(int max_pixsteps[4], int max_pixstep_comps[4],
+                                const AVPixFmtDescriptor *pixdesc);
+
+/**
+ * Compute the size of an image line with format pix_fmt and width
+ * width for the plane plane.
+ *
+ * @return the computed size in bytes
+ */
+int av_image_get_linesize(enum AVPixelFormat pix_fmt, int width, int plane);
+
+/**
+ * Fill plane linesizes for an image with pixel format pix_fmt and
+ * width width.
+ *
+ * @param linesizes array to be filled with the linesize for each plane
+ * @return >= 0 in case of success, a negative error code otherwise
+ */
+int av_image_fill_linesizes(int linesizes[4], enum AVPixelFormat pix_fmt, int width);
+
+/**
+ * Fill plane data pointers for an image with pixel format pix_fmt and
+ * height height.
+ *
+ * @param data pointers array to be filled with the pointer for each image plane
+ * @param ptr the pointer to a buffer which will contain the image
+ * @param linesizes the array containing the linesize for each
+ * plane, should be filled by av_image_fill_linesizes()
+ * @return the size in bytes required for the image buffer, a negative
+ * error code in case of failure
+ */
+int av_image_fill_pointers(uint8_t *data[4], enum AVPixelFormat pix_fmt, int height,
+                           uint8_t *ptr, const int linesizes[4]);
+
+/**
+ * Allocate an image with size w and h and pixel format pix_fmt, and
+ * fill pointers and linesizes accordingly.
+ * The allocated image buffer has to be freed by using
+ * av_freep(&pointers[0]).
+ *
+ * @param align the value to use for buffer size alignment
+ * @return the size in bytes required for the image buffer, a negative
+ * error code in case of failure
+ */
+int av_image_alloc(uint8_t *pointers[4], int linesizes[4],
+                   int w, int h, enum AVPixelFormat pix_fmt, int align);
+
+/**
+ * Copy image plane from src to dst.
+ * That is, copy "height" number of lines of "bytewidth" bytes each.
+ * The first byte of each successive line is separated by *_linesize
+ * bytes.
+ *
+ * bytewidth must be contained by both absolute values of dst_linesize
+ * and src_linesize, otherwise the function behavior is undefined.
+ *
+ * @param dst_linesize linesize for the image plane in dst
+ * @param src_linesize linesize for the image plane in src
+ */
+void av_image_copy_plane(uint8_t       *dst, int dst_linesize,
+                         const uint8_t *src, int src_linesize,
+                         int bytewidth, int height);
+
+/**
+ * Copy image in src_data to dst_data.
+ *
+ * @param dst_linesizes linesizes for the image in dst_data
+ * @param src_linesizes linesizes for the image in src_data
+ */
+void av_image_copy(uint8_t *dst_data[4], int dst_linesizes[4],
+                   const uint8_t *src_data[4], const int src_linesizes[4],
+                   enum AVPixelFormat pix_fmt, int width, int height);
+
+/**
+ * Setup the data pointers and linesizes based on the specified image
+ * parameters and the provided array.
+ *
+ * The fields of the given image are filled in by using the src
+ * address which points to the image data buffer. Depending on the
+ * specified pixel format, one or multiple image data pointers and
+ * line sizes will be set.  If a planar format is specified, several
+ * pointers will be set pointing to the different picture planes and
+ * the line sizes of the different planes will be stored in the
+ * lines_sizes array. Call with src == NULL to get the required
+ * size for the src buffer.
+ *
+ * To allocate the buffer and fill in the dst_data and dst_linesize in
+ * one call, use av_image_alloc().
+ *
+ * @param dst_data      data pointers to be filled in
+ * @param dst_linesizes linesizes for the image in dst_data to be filled in
+ * @param src           buffer which will contain or contains the actual image data, can be NULL
+ * @param pix_fmt       the pixel format of the image
+ * @param width         the width of the image in pixels
+ * @param height        the height of the image in pixels
+ * @param align         the value used in src for linesize alignment
+ * @return the size in bytes required for src, a negative error code
+ * in case of failure
+ */
+int av_image_fill_arrays(uint8_t *dst_data[4], int dst_linesize[4],
+                         const uint8_t *src,
+                         enum AVPixelFormat pix_fmt, int width, int height, int align);
+
+/**
+ * Return the size in bytes of the amount of data required to store an
+ * image with the given parameters.
+ *
+ * @param[in] align the assumed linesize alignment
+ */
+int av_image_get_buffer_size(enum AVPixelFormat pix_fmt, int width, int height, int align);
+
+/**
+ * Copy image data from an image into a buffer.
+ *
+ * av_image_get_buffer_size() can be used to compute the required size
+ * for the buffer to fill.
+ *
+ * @param dst           a buffer into which picture data will be copied
+ * @param dst_size      the size in bytes of dst
+ * @param src_data      pointers containing the source image data
+ * @param src_linesizes linesizes for the image in src_data
+ * @param pix_fmt       the pixel format of the source image
+ * @param width         the width of the source image in pixels
+ * @param height        the height of the source image in pixels
+ * @param align         the assumed linesize alignment for dst
+ * @return the number of bytes written to dst, or a negative value
+ * (error code) on error
+ */
+int av_image_copy_to_buffer(uint8_t *dst, int dst_size,
+                            const uint8_t * const src_data[4], const int src_linesize[4],
+                            enum AVPixelFormat pix_fmt, int width, int height, int align);
+
+/**
+ * Check if the given dimension of an image is valid, meaning that all
+ * bytes of the image can be addressed with a signed int.
+ *
+ * @param w the width of the picture
+ * @param h the height of the picture
+ * @param log_offset the offset to sum to the log level for logging with log_ctx
+ * @param log_ctx the parent logging context, it may be NULL
+ * @return >= 0 if valid, a negative error code otherwise
+ */
+int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx);
+
+int avpriv_set_systematic_pal2(uint32_t pal[256], enum AVPixelFormat pix_fmt);
+
+/**
+ * @}
+ */
+
+
+#endif /* AVUTIL_IMGUTILS_H */

+ 77 - 0
wave420l/code/ffmpeg/include/libavutil/intfloat.h

@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2011 Mans Rullgard
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_INTFLOAT_H
+#define AVUTIL_INTFLOAT_H
+
+#include <stdint.h>
+#include "attributes.h"
+
+union av_intfloat32 {
+    uint32_t i;
+    float    f;
+};
+
+union av_intfloat64 {
+    uint64_t i;
+    double   f;
+};
+
+/**
+ * Reinterpret a 32-bit integer as a float.
+ */
+static av_always_inline float av_int2float(uint32_t i)
+{
+    union av_intfloat32 v;
+    v.i = i;
+    return v.f;
+}
+
+/**
+ * Reinterpret a float as a 32-bit integer.
+ */
+static av_always_inline uint32_t av_float2int(float f)
+{
+    union av_intfloat32 v;
+    v.f = f;
+    return v.i;
+}
+
+/**
+ * Reinterpret a 64-bit integer as a double.
+ */
+static av_always_inline double av_int2double(uint64_t i)
+{
+    union av_intfloat64 v;
+    v.i = i;
+    return v.f;
+}
+
+/**
+ * Reinterpret a double as a 64-bit integer.
+ */
+static av_always_inline uint64_t av_double2int(double f)
+{
+    union av_intfloat64 v;
+    v.f = f;
+    return v.i;
+}
+
+#endif /* AVUTIL_INTFLOAT_H */

+ 40 - 0
wave420l/code/ffmpeg/include/libavutil/intfloat_readwrite.h

@@ -0,0 +1,40 @@
+/*
+ * copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_INTFLOAT_READWRITE_H
+#define AVUTIL_INTFLOAT_READWRITE_H
+
+#include <stdint.h>
+#include "attributes.h"
+
+/* IEEE 80 bits extended float */
+typedef struct AVExtFloat  {
+    uint8_t exponent[2];
+    uint8_t mantissa[8];
+} AVExtFloat;
+
+attribute_deprecated double av_int2dbl(int64_t v) av_const;
+attribute_deprecated float av_int2flt(int32_t v) av_const;
+attribute_deprecated double av_ext2dbl(const AVExtFloat ext) av_const;
+attribute_deprecated int64_t av_dbl2int(double d) av_const;
+attribute_deprecated int32_t av_flt2int(float d) av_const;
+attribute_deprecated AVExtFloat av_dbl2ext(double d) av_const;
+
+#endif /* AVUTIL_INTFLOAT_READWRITE_H */

+ 621 - 0
wave420l/code/ffmpeg/include/libavutil/intreadwrite.h

@@ -0,0 +1,621 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_INTREADWRITE_H
+#define AVUTIL_INTREADWRITE_H
+
+#include <stdint.h>
+#include "libavutil/avconfig.h"
+#include "attributes.h"
+#include "bswap.h"
+
+typedef union {
+    uint64_t u64;
+    uint32_t u32[2];
+    uint16_t u16[4];
+    uint8_t  u8 [8];
+    double   f64;
+    float    f32[2];
+} av_alias av_alias64;
+
+typedef union {
+    uint32_t u32;
+    uint16_t u16[2];
+    uint8_t  u8 [4];
+    float    f32;
+} av_alias av_alias32;
+
+typedef union {
+    uint16_t u16;
+    uint8_t  u8 [2];
+} av_alias av_alias16;
+
+/*
+ * Arch-specific headers can provide any combination of
+ * AV_[RW][BLN](16|24|32|48|64) and AV_(COPY|SWAP|ZERO)(64|128) macros.
+ * Preprocessor symbols must be defined, even if these are implemented
+ * as inline functions.
+ */
+
+#ifdef HAVE_AV_CONFIG_H
+
+#include "config.h"
+
+#if   ARCH_ARM
+#   include "arm/intreadwrite.h"
+#elif ARCH_AVR32
+#   include "avr32/intreadwrite.h"
+#elif ARCH_MIPS
+#   include "mips/intreadwrite.h"
+#elif ARCH_PPC
+#   include "ppc/intreadwrite.h"
+#elif ARCH_TOMI
+#   include "tomi/intreadwrite.h"
+#elif ARCH_X86
+#   include "x86/intreadwrite.h"
+#endif
+
+#endif /* HAVE_AV_CONFIG_H */
+
+/*
+ * Map AV_RNXX <-> AV_R[BL]XX for all variants provided by per-arch headers.
+ */
+
+#if AV_HAVE_BIGENDIAN
+
+#   if    defined(AV_RN16) && !defined(AV_RB16)
+#       define AV_RB16(p) AV_RN16(p)
+#   elif !defined(AV_RN16) &&  defined(AV_RB16)
+#       define AV_RN16(p) AV_RB16(p)
+#   endif
+
+#   if    defined(AV_WN16) && !defined(AV_WB16)
+#       define AV_WB16(p, v) AV_WN16(p, v)
+#   elif !defined(AV_WN16) &&  defined(AV_WB16)
+#       define AV_WN16(p, v) AV_WB16(p, v)
+#   endif
+
+#   if    defined(AV_RN24) && !defined(AV_RB24)
+#       define AV_RB24(p) AV_RN24(p)
+#   elif !defined(AV_RN24) &&  defined(AV_RB24)
+#       define AV_RN24(p) AV_RB24(p)
+#   endif
+
+#   if    defined(AV_WN24) && !defined(AV_WB24)
+#       define AV_WB24(p, v) AV_WN24(p, v)
+#   elif !defined(AV_WN24) &&  defined(AV_WB24)
+#       define AV_WN24(p, v) AV_WB24(p, v)
+#   endif
+
+#   if    defined(AV_RN32) && !defined(AV_RB32)
+#       define AV_RB32(p) AV_RN32(p)
+#   elif !defined(AV_RN32) &&  defined(AV_RB32)
+#       define AV_RN32(p) AV_RB32(p)
+#   endif
+
+#   if    defined(AV_WN32) && !defined(AV_WB32)
+#       define AV_WB32(p, v) AV_WN32(p, v)
+#   elif !defined(AV_WN32) &&  defined(AV_WB32)
+#       define AV_WN32(p, v) AV_WB32(p, v)
+#   endif
+
+#   if    defined(AV_RN48) && !defined(AV_RB48)
+#       define AV_RB48(p) AV_RN48(p)
+#   elif !defined(AV_RN48) &&  defined(AV_RB48)
+#       define AV_RN48(p) AV_RB48(p)
+#   endif
+
+#   if    defined(AV_WN48) && !defined(AV_WB48)
+#       define AV_WB48(p, v) AV_WN48(p, v)
+#   elif !defined(AV_WN48) &&  defined(AV_WB48)
+#       define AV_WN48(p, v) AV_WB48(p, v)
+#   endif
+
+#   if    defined(AV_RN64) && !defined(AV_RB64)
+#       define AV_RB64(p) AV_RN64(p)
+#   elif !defined(AV_RN64) &&  defined(AV_RB64)
+#       define AV_RN64(p) AV_RB64(p)
+#   endif
+
+#   if    defined(AV_WN64) && !defined(AV_WB64)
+#       define AV_WB64(p, v) AV_WN64(p, v)
+#   elif !defined(AV_WN64) &&  defined(AV_WB64)
+#       define AV_WN64(p, v) AV_WB64(p, v)
+#   endif
+
+#else /* AV_HAVE_BIGENDIAN */
+
+#   if    defined(AV_RN16) && !defined(AV_RL16)
+#       define AV_RL16(p) AV_RN16(p)
+#   elif !defined(AV_RN16) &&  defined(AV_RL16)
+#       define AV_RN16(p) AV_RL16(p)
+#   endif
+
+#   if    defined(AV_WN16) && !defined(AV_WL16)
+#       define AV_WL16(p, v) AV_WN16(p, v)
+#   elif !defined(AV_WN16) &&  defined(AV_WL16)
+#       define AV_WN16(p, v) AV_WL16(p, v)
+#   endif
+
+#   if    defined(AV_RN24) && !defined(AV_RL24)
+#       define AV_RL24(p) AV_RN24(p)
+#   elif !defined(AV_RN24) &&  defined(AV_RL24)
+#       define AV_RN24(p) AV_RL24(p)
+#   endif
+
+#   if    defined(AV_WN24) && !defined(AV_WL24)
+#       define AV_WL24(p, v) AV_WN24(p, v)
+#   elif !defined(AV_WN24) &&  defined(AV_WL24)
+#       define AV_WN24(p, v) AV_WL24(p, v)
+#   endif
+
+#   if    defined(AV_RN32) && !defined(AV_RL32)
+#       define AV_RL32(p) AV_RN32(p)
+#   elif !defined(AV_RN32) &&  defined(AV_RL32)
+#       define AV_RN32(p) AV_RL32(p)
+#   endif
+
+#   if    defined(AV_WN32) && !defined(AV_WL32)
+#       define AV_WL32(p, v) AV_WN32(p, v)
+#   elif !defined(AV_WN32) &&  defined(AV_WL32)
+#       define AV_WN32(p, v) AV_WL32(p, v)
+#   endif
+
+#   if    defined(AV_RN48) && !defined(AV_RL48)
+#       define AV_RL48(p) AV_RN48(p)
+#   elif !defined(AV_RN48) &&  defined(AV_RL48)
+#       define AV_RN48(p) AV_RL48(p)
+#   endif
+
+#   if    defined(AV_WN48) && !defined(AV_WL48)
+#       define AV_WL48(p, v) AV_WN48(p, v)
+#   elif !defined(AV_WN48) &&  defined(AV_WL48)
+#       define AV_WN48(p, v) AV_WL48(p, v)
+#   endif
+
+#   if    defined(AV_RN64) && !defined(AV_RL64)
+#       define AV_RL64(p) AV_RN64(p)
+#   elif !defined(AV_RN64) &&  defined(AV_RL64)
+#       define AV_RN64(p) AV_RL64(p)
+#   endif
+
+#   if    defined(AV_WN64) && !defined(AV_WL64)
+#       define AV_WL64(p, v) AV_WN64(p, v)
+#   elif !defined(AV_WN64) &&  defined(AV_WL64)
+#       define AV_WN64(p, v) AV_WL64(p, v)
+#   endif
+
+#endif /* !AV_HAVE_BIGENDIAN */
+
+/*
+ * Define AV_[RW]N helper macros to simplify definitions not provided
+ * by per-arch headers.
+ */
+
+#if defined(__GNUC__) && !defined(__TI_COMPILER_VERSION__)
+
+union unaligned_64 { uint64_t l; } __attribute__((packed)) av_alias;
+union unaligned_32 { uint32_t l; } __attribute__((packed)) av_alias;
+union unaligned_16 { uint16_t l; } __attribute__((packed)) av_alias;
+
+#   define AV_RN(s, p) (((const union unaligned_##s *) (p))->l)
+#   define AV_WN(s, p, v) ((((union unaligned_##s *) (p))->l) = (v))
+
+#elif defined(__DECC)
+
+#   define AV_RN(s, p) (*((const __unaligned uint##s##_t*)(p)))
+#   define AV_WN(s, p, v) (*((__unaligned uint##s##_t*)(p)) = (v))
+
+#elif AV_HAVE_FAST_UNALIGNED
+
+#   define AV_RN(s, p) (((const av_alias##s*)(p))->u##s)
+#   define AV_WN(s, p, v) (((av_alias##s*)(p))->u##s = (v))
+
+#else
+
+#ifndef AV_RB16
+#   define AV_RB16(x)                           \
+    ((((const uint8_t*)(x))[0] << 8) |          \
+      ((const uint8_t*)(x))[1])
+#endif
+#ifndef AV_WB16
+#   define AV_WB16(p, darg) do {                \
+        unsigned d = (darg);                    \
+        ((uint8_t*)(p))[1] = (d);               \
+        ((uint8_t*)(p))[0] = (d)>>8;            \
+    } while(0)
+#endif
+
+#ifndef AV_RL16
+#   define AV_RL16(x)                           \
+    ((((const uint8_t*)(x))[1] << 8) |          \
+      ((const uint8_t*)(x))[0])
+#endif
+#ifndef AV_WL16
+#   define AV_WL16(p, darg) do {                \
+        unsigned d = (darg);                    \
+        ((uint8_t*)(p))[0] = (d);               \
+        ((uint8_t*)(p))[1] = (d)>>8;            \
+    } while(0)
+#endif
+
+#ifndef AV_RB32
+#   define AV_RB32(x)                                \
+    (((uint32_t)((const uint8_t*)(x))[0] << 24) |    \
+               (((const uint8_t*)(x))[1] << 16) |    \
+               (((const uint8_t*)(x))[2] <<  8) |    \
+                ((const uint8_t*)(x))[3])
+#endif
+#ifndef AV_WB32
+#   define AV_WB32(p, darg) do {                \
+        unsigned d = (darg);                    \
+        ((uint8_t*)(p))[3] = (d);               \
+        ((uint8_t*)(p))[2] = (d)>>8;            \
+        ((uint8_t*)(p))[1] = (d)>>16;           \
+        ((uint8_t*)(p))[0] = (d)>>24;           \
+    } while(0)
+#endif
+
+#ifndef AV_RL32
+#   define AV_RL32(x)                                \
+    (((uint32_t)((const uint8_t*)(x))[3] << 24) |    \
+               (((const uint8_t*)(x))[2] << 16) |    \
+               (((const uint8_t*)(x))[1] <<  8) |    \
+                ((const uint8_t*)(x))[0])
+#endif
+#ifndef AV_WL32
+#   define AV_WL32(p, darg) do {                \
+        unsigned d = (darg);                    \
+        ((uint8_t*)(p))[0] = (d);               \
+        ((uint8_t*)(p))[1] = (d)>>8;            \
+        ((uint8_t*)(p))[2] = (d)>>16;           \
+        ((uint8_t*)(p))[3] = (d)>>24;           \
+    } while(0)
+#endif
+
+#ifndef AV_RB64
+#   define AV_RB64(x)                                   \
+    (((uint64_t)((const uint8_t*)(x))[0] << 56) |       \
+     ((uint64_t)((const uint8_t*)(x))[1] << 48) |       \
+     ((uint64_t)((const uint8_t*)(x))[2] << 40) |       \
+     ((uint64_t)((const uint8_t*)(x))[3] << 32) |       \
+     ((uint64_t)((const uint8_t*)(x))[4] << 24) |       \
+     ((uint64_t)((const uint8_t*)(x))[5] << 16) |       \
+     ((uint64_t)((const uint8_t*)(x))[6] <<  8) |       \
+      (uint64_t)((const uint8_t*)(x))[7])
+#endif
+#ifndef AV_WB64
+#   define AV_WB64(p, darg) do {                \
+        uint64_t d = (darg);                    \
+        ((uint8_t*)(p))[7] = (d);               \
+        ((uint8_t*)(p))[6] = (d)>>8;            \
+        ((uint8_t*)(p))[5] = (d)>>16;           \
+        ((uint8_t*)(p))[4] = (d)>>24;           \
+        ((uint8_t*)(p))[3] = (d)>>32;           \
+        ((uint8_t*)(p))[2] = (d)>>40;           \
+        ((uint8_t*)(p))[1] = (d)>>48;           \
+        ((uint8_t*)(p))[0] = (d)>>56;           \
+    } while(0)
+#endif
+
+#ifndef AV_RL64
+#   define AV_RL64(x)                                   \
+    (((uint64_t)((const uint8_t*)(x))[7] << 56) |       \
+     ((uint64_t)((const uint8_t*)(x))[6] << 48) |       \
+     ((uint64_t)((const uint8_t*)(x))[5] << 40) |       \
+     ((uint64_t)((const uint8_t*)(x))[4] << 32) |       \
+     ((uint64_t)((const uint8_t*)(x))[3] << 24) |       \
+     ((uint64_t)((const uint8_t*)(x))[2] << 16) |       \
+     ((uint64_t)((const uint8_t*)(x))[1] <<  8) |       \
+      (uint64_t)((const uint8_t*)(x))[0])
+#endif
+#ifndef AV_WL64
+#   define AV_WL64(p, darg) do {                \
+        uint64_t d = (darg);                    \
+        ((uint8_t*)(p))[0] = (d);               \
+        ((uint8_t*)(p))[1] = (d)>>8;            \
+        ((uint8_t*)(p))[2] = (d)>>16;           \
+        ((uint8_t*)(p))[3] = (d)>>24;           \
+        ((uint8_t*)(p))[4] = (d)>>32;           \
+        ((uint8_t*)(p))[5] = (d)>>40;           \
+        ((uint8_t*)(p))[6] = (d)>>48;           \
+        ((uint8_t*)(p))[7] = (d)>>56;           \
+    } while(0)
+#endif
+
+#if AV_HAVE_BIGENDIAN
+#   define AV_RN(s, p)    AV_RB##s(p)
+#   define AV_WN(s, p, v) AV_WB##s(p, v)
+#else
+#   define AV_RN(s, p)    AV_RL##s(p)
+#   define AV_WN(s, p, v) AV_WL##s(p, v)
+#endif
+
+#endif /* HAVE_FAST_UNALIGNED */
+
+#ifndef AV_RN16
+#   define AV_RN16(p) AV_RN(16, p)
+#endif
+
+#ifndef AV_RN32
+#   define AV_RN32(p) AV_RN(32, p)
+#endif
+
+#ifndef AV_RN64
+#   define AV_RN64(p) AV_RN(64, p)
+#endif
+
+#ifndef AV_WN16
+#   define AV_WN16(p, v) AV_WN(16, p, v)
+#endif
+
+#ifndef AV_WN32
+#   define AV_WN32(p, v) AV_WN(32, p, v)
+#endif
+
+#ifndef AV_WN64
+#   define AV_WN64(p, v) AV_WN(64, p, v)
+#endif
+
+#if AV_HAVE_BIGENDIAN
+#   define AV_RB(s, p)    AV_RN##s(p)
+#   define AV_WB(s, p, v) AV_WN##s(p, v)
+#   define AV_RL(s, p)    av_bswap##s(AV_RN##s(p))
+#   define AV_WL(s, p, v) AV_WN##s(p, av_bswap##s(v))
+#else
+#   define AV_RB(s, p)    av_bswap##s(AV_RN##s(p))
+#   define AV_WB(s, p, v) AV_WN##s(p, av_bswap##s(v))
+#   define AV_RL(s, p)    AV_RN##s(p)
+#   define AV_WL(s, p, v) AV_WN##s(p, v)
+#endif
+
+#define AV_RB8(x)     (((const uint8_t*)(x))[0])
+#define AV_WB8(p, d)  do { ((uint8_t*)(p))[0] = (d); } while(0)
+
+#define AV_RL8(x)     AV_RB8(x)
+#define AV_WL8(p, d)  AV_WB8(p, d)
+
+#ifndef AV_RB16
+#   define AV_RB16(p)    AV_RB(16, p)
+#endif
+#ifndef AV_WB16
+#   define AV_WB16(p, v) AV_WB(16, p, v)
+#endif
+
+#ifndef AV_RL16
+#   define AV_RL16(p)    AV_RL(16, p)
+#endif
+#ifndef AV_WL16
+#   define AV_WL16(p, v) AV_WL(16, p, v)
+#endif
+
+#ifndef AV_RB32
+#   define AV_RB32(p)    AV_RB(32, p)
+#endif
+#ifndef AV_WB32
+#   define AV_WB32(p, v) AV_WB(32, p, v)
+#endif
+
+#ifndef AV_RL32
+#   define AV_RL32(p)    AV_RL(32, p)
+#endif
+#ifndef AV_WL32
+#   define AV_WL32(p, v) AV_WL(32, p, v)
+#endif
+
+#ifndef AV_RB64
+#   define AV_RB64(p)    AV_RB(64, p)
+#endif
+#ifndef AV_WB64
+#   define AV_WB64(p, v) AV_WB(64, p, v)
+#endif
+
+#ifndef AV_RL64
+#   define AV_RL64(p)    AV_RL(64, p)
+#endif
+#ifndef AV_WL64
+#   define AV_WL64(p, v) AV_WL(64, p, v)
+#endif
+
+#ifndef AV_RB24
+#   define AV_RB24(x)                           \
+    ((((const uint8_t*)(x))[0] << 16) |         \
+     (((const uint8_t*)(x))[1] <<  8) |         \
+      ((const uint8_t*)(x))[2])
+#endif
+#ifndef AV_WB24
+#   define AV_WB24(p, d) do {                   \
+        ((uint8_t*)(p))[2] = (d);               \
+        ((uint8_t*)(p))[1] = (d)>>8;            \
+        ((uint8_t*)(p))[0] = (d)>>16;           \
+    } while(0)
+#endif
+
+#ifndef AV_RL24
+#   define AV_RL24(x)                           \
+    ((((const uint8_t*)(x))[2] << 16) |         \
+     (((const uint8_t*)(x))[1] <<  8) |         \
+      ((const uint8_t*)(x))[0])
+#endif
+#ifndef AV_WL24
+#   define AV_WL24(p, d) do {                   \
+        ((uint8_t*)(p))[0] = (d);               \
+        ((uint8_t*)(p))[1] = (d)>>8;            \
+        ((uint8_t*)(p))[2] = (d)>>16;           \
+    } while(0)
+#endif
+
+#ifndef AV_RB48
+#   define AV_RB48(x)                                     \
+    (((uint64_t)((const uint8_t*)(x))[0] << 40) |         \
+     ((uint64_t)((const uint8_t*)(x))[1] << 32) |         \
+     ((uint64_t)((const uint8_t*)(x))[2] << 24) |         \
+     ((uint64_t)((const uint8_t*)(x))[3] << 16) |         \
+     ((uint64_t)((const uint8_t*)(x))[4] <<  8) |         \
+      (uint64_t)((const uint8_t*)(x))[5])
+#endif
+#ifndef AV_WB48
+#   define AV_WB48(p, darg) do {                \
+        uint64_t d = (darg);                    \
+        ((uint8_t*)(p))[5] = (d);               \
+        ((uint8_t*)(p))[4] = (d)>>8;            \
+        ((uint8_t*)(p))[3] = (d)>>16;           \
+        ((uint8_t*)(p))[2] = (d)>>24;           \
+        ((uint8_t*)(p))[1] = (d)>>32;           \
+        ((uint8_t*)(p))[0] = (d)>>40;           \
+    } while(0)
+#endif
+
+#ifndef AV_RL48
+#   define AV_RL48(x)                                     \
+    (((uint64_t)((const uint8_t*)(x))[5] << 40) |         \
+     ((uint64_t)((const uint8_t*)(x))[4] << 32) |         \
+     ((uint64_t)((const uint8_t*)(x))[3] << 24) |         \
+     ((uint64_t)((const uint8_t*)(x))[2] << 16) |         \
+     ((uint64_t)((const uint8_t*)(x))[1] <<  8) |         \
+      (uint64_t)((const uint8_t*)(x))[0])
+#endif
+#ifndef AV_WL48
+#   define AV_WL48(p, darg) do {                \
+        uint64_t d = (darg);                    \
+        ((uint8_t*)(p))[0] = (d);               \
+        ((uint8_t*)(p))[1] = (d)>>8;            \
+        ((uint8_t*)(p))[2] = (d)>>16;           \
+        ((uint8_t*)(p))[3] = (d)>>24;           \
+        ((uint8_t*)(p))[4] = (d)>>32;           \
+        ((uint8_t*)(p))[5] = (d)>>40;           \
+    } while(0)
+#endif
+
+/*
+ * The AV_[RW]NA macros access naturally aligned data
+ * in a type-safe way.
+ */
+
+#define AV_RNA(s, p)    (((const av_alias##s*)(p))->u##s)
+#define AV_WNA(s, p, v) (((av_alias##s*)(p))->u##s = (v))
+
+#ifndef AV_RN16A
+#   define AV_RN16A(p) AV_RNA(16, p)
+#endif
+
+#ifndef AV_RN32A
+#   define AV_RN32A(p) AV_RNA(32, p)
+#endif
+
+#ifndef AV_RN64A
+#   define AV_RN64A(p) AV_RNA(64, p)
+#endif
+
+#ifndef AV_WN16A
+#   define AV_WN16A(p, v) AV_WNA(16, p, v)
+#endif
+
+#ifndef AV_WN32A
+#   define AV_WN32A(p, v) AV_WNA(32, p, v)
+#endif
+
+#ifndef AV_WN64A
+#   define AV_WN64A(p, v) AV_WNA(64, p, v)
+#endif
+
+/*
+ * The AV_COPYxxU macros are suitable for copying data to/from unaligned
+ * memory locations.
+ */
+
+#define AV_COPYU(n, d, s) AV_WN##n(d, AV_RN##n(s));
+
+#ifndef AV_COPY16U
+#   define AV_COPY16U(d, s) AV_COPYU(16, d, s)
+#endif
+
+#ifndef AV_COPY32U
+#   define AV_COPY32U(d, s) AV_COPYU(32, d, s)
+#endif
+
+#ifndef AV_COPY64U
+#   define AV_COPY64U(d, s) AV_COPYU(64, d, s)
+#endif
+
+#ifndef AV_COPY128U
+#   define AV_COPY128U(d, s)                                    \
+    do {                                                        \
+        AV_COPY64U(d, s);                                       \
+        AV_COPY64U((char *)(d) + 8, (const char *)(s) + 8);     \
+    } while(0)
+#endif
+
+/* Parameters for AV_COPY*, AV_SWAP*, AV_ZERO* must be
+ * naturally aligned. They may be implemented using MMX,
+ * so emms_c() must be called before using any float code
+ * afterwards.
+ */
+
+#define AV_COPY(n, d, s) \
+    (((av_alias##n*)(d))->u##n = ((const av_alias##n*)(s))->u##n)
+
+#ifndef AV_COPY16
+#   define AV_COPY16(d, s) AV_COPY(16, d, s)
+#endif
+
+#ifndef AV_COPY32
+#   define AV_COPY32(d, s) AV_COPY(32, d, s)
+#endif
+
+#ifndef AV_COPY64
+#   define AV_COPY64(d, s) AV_COPY(64, d, s)
+#endif
+
+#ifndef AV_COPY128
+#   define AV_COPY128(d, s)                    \
+    do {                                       \
+        AV_COPY64(d, s);                       \
+        AV_COPY64((char*)(d)+8, (char*)(s)+8); \
+    } while(0)
+#endif
+
+#define AV_SWAP(n, a, b) FFSWAP(av_alias##n, *(av_alias##n*)(a), *(av_alias##n*)(b))
+
+#ifndef AV_SWAP64
+#   define AV_SWAP64(a, b) AV_SWAP(64, a, b)
+#endif
+
+#define AV_ZERO(n, d) (((av_alias##n*)(d))->u##n = 0)
+
+#ifndef AV_ZERO16
+#   define AV_ZERO16(d) AV_ZERO(16, d)
+#endif
+
+#ifndef AV_ZERO32
+#   define AV_ZERO32(d) AV_ZERO(32, d)
+#endif
+
+#ifndef AV_ZERO64
+#   define AV_ZERO64(d) AV_ZERO(64, d)
+#endif
+
+#ifndef AV_ZERO128
+#   define AV_ZERO128(d)         \
+    do {                         \
+        AV_ZERO64(d);            \
+        AV_ZERO64((char*)(d)+8); \
+    } while(0)
+#endif
+
+#endif /* AVUTIL_INTREADWRITE_H */

+ 62 - 0
wave420l/code/ffmpeg/include/libavutil/lfg.h

@@ -0,0 +1,62 @@
+/*
+ * Lagged Fibonacci PRNG
+ * Copyright (c) 2008 Michael Niedermayer
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_LFG_H
+#define AVUTIL_LFG_H
+
+typedef struct AVLFG {
+    unsigned int state[64];
+    int index;
+} AVLFG;
+
+void av_lfg_init(AVLFG *c, unsigned int seed);
+
+/**
+ * Get the next random unsigned 32-bit number using an ALFG.
+ *
+ * Please also consider a simple LCG like state= state*1664525+1013904223,
+ * it may be good enough and faster for your specific use case.
+ */
+static inline unsigned int av_lfg_get(AVLFG *c){
+    c->state[c->index & 63] = c->state[(c->index-24) & 63] + c->state[(c->index-55) & 63];
+    return c->state[c->index++ & 63];
+}
+
+/**
+ * Get the next random unsigned 32-bit number using a MLFG.
+ *
+ * Please also consider av_lfg_get() above, it is faster.
+ */
+static inline unsigned int av_mlfg_get(AVLFG *c){
+    unsigned int a= c->state[(c->index-55) & 63];
+    unsigned int b= c->state[(c->index-24) & 63];
+    return c->state[c->index++ & 63] = 2*a*b+a+b;
+}
+
+/**
+ * Get the next two numbers generated by a Box-Muller Gaussian
+ * generator using the random numbers issued by lfg.
+ *
+ * @param out array where the two generated numbers are placed
+ */
+void av_bmg_get(AVLFG *lfg, double out[2]);
+
+#endif /* AVUTIL_LFG_H */

+ 313 - 0
wave420l/code/ffmpeg/include/libavutil/log.h

@@ -0,0 +1,313 @@
+/*
+ * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_LOG_H
+#define AVUTIL_LOG_H
+
+#include <stdarg.h>
+#include "avutil.h"
+#include "attributes.h"
+
+typedef enum {
+    AV_CLASS_CATEGORY_NA = 0,
+    AV_CLASS_CATEGORY_INPUT,
+    AV_CLASS_CATEGORY_OUTPUT,
+    AV_CLASS_CATEGORY_MUXER,
+    AV_CLASS_CATEGORY_DEMUXER,
+    AV_CLASS_CATEGORY_ENCODER,
+    AV_CLASS_CATEGORY_DECODER,
+    AV_CLASS_CATEGORY_FILTER,
+    AV_CLASS_CATEGORY_BITSTREAM_FILTER,
+    AV_CLASS_CATEGORY_SWSCALER,
+    AV_CLASS_CATEGORY_SWRESAMPLER,
+    AV_CLASS_CATEGORY_NB, ///< not part of ABI/API
+}AVClassCategory;
+
+struct AVOptionRanges;
+
+/**
+ * Describe the class of an AVClass context structure. That is an
+ * arbitrary struct of which the first field is a pointer to an
+ * AVClass struct (e.g. AVCodecContext, AVFormatContext etc.).
+ */
+typedef struct AVClass {
+    /**
+     * The name of the class; usually it is the same name as the
+     * context structure type to which the AVClass is associated.
+     */
+    const char* class_name;
+
+    /**
+     * A pointer to a function which returns the name of a context
+     * instance ctx associated with the class.
+     */
+    const char* (*item_name)(void* ctx);
+
+    /**
+     * a pointer to the first option specified in the class if any or NULL
+     *
+     * @see av_set_default_options()
+     */
+    const struct AVOption *option;
+
+    /**
+     * LIBAVUTIL_VERSION with which this structure was created.
+     * This is used to allow fields to be added without requiring major
+     * version bumps everywhere.
+     */
+
+    int version;
+
+    /**
+     * Offset in the structure where log_level_offset is stored.
+     * 0 means there is no such variable
+     */
+    int log_level_offset_offset;
+
+    /**
+     * Offset in the structure where a pointer to the parent context for
+     * logging is stored. For example a decoder could pass its AVCodecContext
+     * to eval as such a parent context, which an av_log() implementation
+     * could then leverage to display the parent context.
+     * The offset can be NULL.
+     */
+    int parent_log_context_offset;
+
+    /**
+     * Return next AVOptions-enabled child or NULL
+     */
+    void* (*child_next)(void *obj, void *prev);
+
+    /**
+     * Return an AVClass corresponding to the next potential
+     * AVOptions-enabled child.
+     *
+     * The difference between child_next and this is that
+     * child_next iterates over _already existing_ objects, while
+     * child_class_next iterates over _all possible_ children.
+     */
+    const struct AVClass* (*child_class_next)(const struct AVClass *prev);
+
+    /**
+     * Category used for visualization (like color)
+     * This is only set if the category is equal for all objects using this class.
+     * available since version (51 << 16 | 56 << 8 | 100)
+     */
+    AVClassCategory category;
+
+    /**
+     * Callback to return the category.
+     * available since version (51 << 16 | 59 << 8 | 100)
+     */
+    AVClassCategory (*get_category)(void* ctx);
+
+    /**
+     * Callback to return the supported/allowed ranges.
+     * available since version (52.12)
+     */
+    int (*query_ranges)(struct AVOptionRanges **, void *obj, const char *key, int flags);
+} AVClass;
+
+/**
+ * @addtogroup lavu_log
+ *
+ * @{
+ *
+ * @defgroup lavu_log_constants Logging Constants
+ *
+ * @{
+ */
+
+/**
+ * Print no output.
+ */
+#define AV_LOG_QUIET    -8
+
+/**
+ * Something went really wrong and we will crash now.
+ */
+#define AV_LOG_PANIC     0
+
+/**
+ * Something went wrong and recovery is not possible.
+ * For example, no header was found for a format which depends
+ * on headers or an illegal combination of parameters is used.
+ */
+#define AV_LOG_FATAL     8
+
+/**
+ * Something went wrong and cannot losslessly be recovered.
+ * However, not all future data is affected.
+ */
+#define AV_LOG_ERROR    16
+
+/**
+ * Something somehow does not look correct. This may or may not
+ * lead to problems. An example would be the use of '-vstrict -2'.
+ */
+#define AV_LOG_WARNING  24
+
+/**
+ * Standard information.
+ */
+#define AV_LOG_INFO     32
+
+/**
+ * Detailed information.
+ */
+#define AV_LOG_VERBOSE  40
+
+/**
+ * Stuff which is only useful for libav* developers.
+ */
+#define AV_LOG_DEBUG    48
+
+#define AV_LOG_MAX_OFFSET (AV_LOG_DEBUG - AV_LOG_QUIET)
+
+/**
+ * @}
+ */
+
+/**
+ * Send the specified message to the log if the level is less than or equal
+ * to the current av_log_level. By default, all logging messages are sent to
+ * stderr. This behavior can be altered by setting a different logging callback
+ * function.
+ * @see av_log_set_callback
+ *
+ * @param avcl A pointer to an arbitrary struct of which the first field is a
+ *        pointer to an AVClass struct.
+ * @param level The importance level of the message expressed using a @ref
+ *        lavu_log_constants "Logging Constant".
+ * @param fmt The format string (printf-compatible) that specifies how
+ *        subsequent arguments are converted to output.
+ */
+void av_log(void *avcl, int level, const char *fmt, ...) av_printf_format(3, 4);
+
+
+/**
+ * Send the specified message to the log if the level is less than or equal
+ * to the current av_log_level. By default, all logging messages are sent to
+ * stderr. This behavior can be altered by setting a different logging callback
+ * function.
+ * @see av_log_set_callback
+ *
+ * @param avcl A pointer to an arbitrary struct of which the first field is a
+ *        pointer to an AVClass struct.
+ * @param level The importance level of the message expressed using a @ref
+ *        lavu_log_constants "Logging Constant".
+ * @param fmt The format string (printf-compatible) that specifies how
+ *        subsequent arguments are converted to output.
+ * @param vl The arguments referenced by the format string.
+ */
+void av_vlog(void *avcl, int level, const char *fmt, va_list vl);
+
+/**
+ * Get the current log level
+ *
+ * @see lavu_log_constants
+ *
+ * @return Current log level
+ */
+int av_log_get_level(void);
+
+/**
+ * Set the log level
+ *
+ * @see lavu_log_constants
+ *
+ * @param level Logging level
+ */
+void av_log_set_level(int level);
+
+/**
+ * Set the logging callback
+ *
+ * @note The callback must be thread safe, even if the application does not use
+ *       threads itself as some codecs are multithreaded.
+ *
+ * @see av_log_default_callback
+ *
+ * @param callback A logging function with a compatible signature.
+ */
+void av_log_set_callback(void (*callback)(void*, int, const char*, va_list));
+
+/**
+ * Default logging callback
+ *
+ * It prints the message to stderr, optionally colorizing it.
+ *
+ * @param avcl A pointer to an arbitrary struct of which the first field is a
+ *        pointer to an AVClass struct.
+ * @param level The importance level of the message expressed using a @ref
+ *        lavu_log_constants "Logging Constant".
+ * @param fmt The format string (printf-compatible) that specifies how
+ *        subsequent arguments are converted to output.
+ * @param ap The arguments referenced by the format string.
+ */
+void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl);
+
+/**
+ * Return the context name
+ *
+ * @param  ctx The AVClass context
+ *
+ * @return The AVClass class_name
+ */
+const char* av_default_item_name(void* ctx);
+AVClassCategory av_default_get_category(void *ptr);
+
+/**
+ * Format a line of log the same way as the default callback.
+ * @param line          buffer to receive the formated line
+ * @param line_size     size of the buffer
+ * @param print_prefix  used to store whether the prefix must be printed;
+ *                      must point to a persistent integer initially set to 1
+ */
+void av_log_format_line(void *ptr, int level, const char *fmt, va_list vl,
+                        char *line, int line_size, int *print_prefix);
+
+/**
+ * av_dlog macros
+ * Useful to print debug messages that shouldn't get compiled in normally.
+ */
+
+#ifdef DEBUG
+#    define av_dlog(pctx, ...) av_log(pctx, AV_LOG_DEBUG, __VA_ARGS__)
+#else
+#    define av_dlog(pctx, ...) do { if (0) av_log(pctx, AV_LOG_DEBUG, __VA_ARGS__); } while (0)
+#endif
+
+/**
+ * Skip repeated messages, this requires the user app to use av_log() instead of
+ * (f)printf as the 2 would otherwise interfere and lead to
+ * "Last message repeated x times" messages below (f)printf messages with some
+ * bad luck.
+ * Also to receive the last, "last repeated" line if any, the user app must
+ * call av_log(NULL, AV_LOG_QUIET, "%s", ""); at the end
+ */
+#define AV_LOG_SKIP_REPEATED 1
+void av_log_set_flags(int arg);
+
+/**
+ * @}
+ */
+
+#endif /* AVUTIL_LOG_H */

+ 66 - 0
wave420l/code/ffmpeg/include/libavutil/lzo.h

@@ -0,0 +1,66 @@
+/*
+ * LZO 1x decompression
+ * copyright (c) 2006 Reimar Doeffinger
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_LZO_H
+#define AVUTIL_LZO_H
+
+/**
+ * @defgroup lavu_lzo LZO
+ * @ingroup lavu_crypto
+ *
+ * @{
+ */
+
+#include <stdint.h>
+
+/** @name Error flags returned by av_lzo1x_decode
+ * @{ */
+/// end of the input buffer reached before decoding finished
+#define AV_LZO_INPUT_DEPLETED  1
+/// decoded data did not fit into output buffer
+#define AV_LZO_OUTPUT_FULL     2
+/// a reference to previously decoded data was wrong
+#define AV_LZO_INVALID_BACKPTR 4
+/// a non-specific error in the compressed bitstream
+#define AV_LZO_ERROR           8
+/** @} */
+
+#define AV_LZO_INPUT_PADDING   8
+#define AV_LZO_OUTPUT_PADDING 12
+
+/**
+ * @brief Decodes LZO 1x compressed data.
+ * @param out output buffer
+ * @param outlen size of output buffer, number of bytes left are returned here
+ * @param in input buffer
+ * @param inlen size of input buffer, number of bytes left are returned here
+ * @return 0 on success, otherwise a combination of the error flags above
+ *
+ * Make sure all buffers are appropriately padded, in must provide
+ * AV_LZO_INPUT_PADDING, out must provide AV_LZO_OUTPUT_PADDING additional bytes.
+ */
+int av_lzo1x_decode(void *out, int *outlen, const void *in, int *inlen);
+
+/**
+ * @}
+ */
+
+#endif /* AVUTIL_LZO_H */

+ 147 - 0
wave420l/code/ffmpeg/include/libavutil/mathematics.h

@@ -0,0 +1,147 @@
+/*
+ * copyright (c) 2005-2012 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_MATHEMATICS_H
+#define AVUTIL_MATHEMATICS_H
+
+#include <stdint.h>
+#include <math.h>
+#include "attributes.h"
+#include "rational.h"
+#include "intfloat.h"
+
+#ifndef M_E
+#define M_E            2.7182818284590452354   /* e */
+#endif
+#ifndef M_LN2
+#define M_LN2          0.69314718055994530942  /* log_e 2 */
+#endif
+#ifndef M_LN10
+#define M_LN10         2.30258509299404568402  /* log_e 10 */
+#endif
+#ifndef M_LOG2_10
+#define M_LOG2_10      3.32192809488736234787  /* log_2 10 */
+#endif
+#ifndef M_PHI
+#define M_PHI          1.61803398874989484820   /* phi / golden ratio */
+#endif
+#ifndef M_PI
+#define M_PI           3.14159265358979323846  /* pi */
+#endif
+#ifndef M_SQRT1_2
+#define M_SQRT1_2      0.70710678118654752440  /* 1/sqrt(2) */
+#endif
+#ifndef M_SQRT2
+#define M_SQRT2        1.41421356237309504880  /* sqrt(2) */
+#endif
+#ifndef NAN
+#define NAN            av_int2float(0x7fc00000)
+#endif
+#ifndef INFINITY
+#define INFINITY       av_int2float(0x7f800000)
+#endif
+
+/**
+ * @addtogroup lavu_math
+ * @{
+ */
+
+
+enum AVRounding {
+    AV_ROUND_ZERO     = 0, ///< Round toward zero.
+    AV_ROUND_INF      = 1, ///< Round away from zero.
+    AV_ROUND_DOWN     = 2, ///< Round toward -infinity.
+    AV_ROUND_UP       = 3, ///< Round toward +infinity.
+    AV_ROUND_NEAR_INF = 5, ///< Round to nearest and halfway cases away from zero.
+    AV_ROUND_PASS_MINMAX = 8192, ///< Flag to pass INT64_MIN/MAX through instead of rescaling, this avoids special cases for AV_NOPTS_VALUE
+};
+
+/**
+ * Return the greatest common divisor of a and b.
+ * If both a and b are 0 or either or both are <0 then behavior is
+ * undefined.
+ */
+int64_t av_const av_gcd(int64_t a, int64_t b);
+
+/**
+ * Rescale a 64-bit integer with rounding to nearest.
+ * A simple a*b/c isn't possible as it can overflow.
+ */
+int64_t av_rescale(int64_t a, int64_t b, int64_t c) av_const;
+
+/**
+ * Rescale a 64-bit integer with specified rounding.
+ * A simple a*b/c isn't possible as it can overflow.
+ *
+ * @return rescaled value a, or if AV_ROUND_PASS_MINMAX is set and a is
+ *         INT64_MIN or INT64_MAX then a is passed through unchanged.
+ */
+int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding) av_const;
+
+/**
+ * Rescale a 64-bit integer by 2 rational numbers.
+ */
+int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq) av_const;
+
+/**
+ * Rescale a 64-bit integer by 2 rational numbers with specified rounding.
+ *
+ * @return rescaled value a, or if AV_ROUND_PASS_MINMAX is set and a is
+ *         INT64_MIN or INT64_MAX then a is passed through unchanged.
+ */
+int64_t av_rescale_q_rnd(int64_t a, AVRational bq, AVRational cq,
+                         enum AVRounding) av_const;
+
+/**
+ * Compare 2 timestamps each in its own timebases.
+ * The result of the function is undefined if one of the timestamps
+ * is outside the int64_t range when represented in the others timebase.
+ * @return -1 if ts_a is before ts_b, 1 if ts_a is after ts_b or 0 if they represent the same position
+ */
+int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b);
+
+/**
+ * Compare 2 integers modulo mod.
+ * That is we compare integers a and b for which only the least
+ * significant log2(mod) bits are known.
+ *
+ * @param mod must be a power of 2
+ * @return a negative value if a is smaller than b
+ *         a positive value if a is greater than b
+ *         0                if a equals          b
+ */
+int64_t av_compare_mod(uint64_t a, uint64_t b, uint64_t mod);
+
+/**
+ * Rescale a timestamp while preserving known durations.
+ *
+ * @param in_ts Input timestamp
+ * @param in_tb Input timesbase
+ * @param fs_tb Duration and *last timebase
+ * @param duration duration till the next call
+ * @param out_tb Output timesbase
+ */
+int64_t av_rescale_delta(AVRational in_tb, int64_t in_ts,  AVRational fs_tb, int duration, int64_t *last, AVRational out_tb);
+
+/**
+ * @}
+ */
+
+#endif /* AVUTIL_MATHEMATICS_H */

+ 81 - 0
wave420l/code/ffmpeg/include/libavutil/md5.h

@@ -0,0 +1,81 @@
+/*
+ * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_MD5_H
+#define AVUTIL_MD5_H
+
+#include <stdint.h>
+
+#include "attributes.h"
+#include "version.h"
+
+/**
+ * @defgroup lavu_md5 MD5
+ * @ingroup lavu_crypto
+ * @{
+ */
+
+extern const int av_md5_size;
+
+struct AVMD5;
+
+/**
+ * Allocate an AVMD5 context.
+ */
+struct AVMD5 *av_md5_alloc(void);
+
+/**
+ * Initialize MD5 hashing.
+ *
+ * @param ctx pointer to the function context (of size av_md5_size)
+ */
+void av_md5_init(struct AVMD5 *ctx);
+
+/**
+ * Update hash value.
+ *
+ * @param ctx hash function context
+ * @param src input data to update hash with
+ * @param len input data length
+ */
+void av_md5_update(struct AVMD5 *ctx, const uint8_t *src, int len);
+
+/**
+ * Finish hashing and output digest value.
+ *
+ * @param ctx hash function context
+ * @param dst buffer where output digest value is stored
+ */
+void av_md5_final(struct AVMD5 *ctx, uint8_t *dst);
+
+/**
+ * Hash an array of data.
+ *
+ * @param dst The output buffer to write the digest into
+ * @param src The data to hash
+ * @param len The length of the data, in bytes
+ */
+void av_md5_sum(uint8_t *dst, const uint8_t *src, const int len);
+
+/**
+ * @}
+ */
+
+#endif /* AVUTIL_MD5_H */

+ 342 - 0
wave420l/code/ffmpeg/include/libavutil/mem.h

@@ -0,0 +1,342 @@
+/*
+ * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * memory handling functions
+ */
+
+#ifndef AVUTIL_MEM_H
+#define AVUTIL_MEM_H
+
+#include <limits.h>
+#include <stdint.h>
+
+#include "attributes.h"
+#include "error.h"
+#include "avutil.h"
+
+/**
+ * @addtogroup lavu_mem
+ * @{
+ */
+
+
+#if defined(__INTEL_COMPILER) && __INTEL_COMPILER < 1110 || defined(__SUNPRO_C)
+    #define DECLARE_ALIGNED(n,t,v)      t __attribute__ ((aligned (n))) v
+    #define DECLARE_ASM_CONST(n,t,v)    const t __attribute__ ((aligned (n))) v
+#elif defined(__TI_COMPILER_VERSION__)
+    #define DECLARE_ALIGNED(n,t,v)                      \
+        AV_PRAGMA(DATA_ALIGN(v,n))                      \
+        t __attribute__((aligned(n))) v
+    #define DECLARE_ASM_CONST(n,t,v)                    \
+        AV_PRAGMA(DATA_ALIGN(v,n))                      \
+        static const t __attribute__((aligned(n))) v
+#elif defined(__GNUC__)
+    #define DECLARE_ALIGNED(n,t,v)      t __attribute__ ((aligned (n))) v
+    #define DECLARE_ASM_CONST(n,t,v)    static const t av_used __attribute__ ((aligned (n))) v
+#elif defined(_MSC_VER)
+    #define DECLARE_ALIGNED(n,t,v)      __declspec(align(n)) t v
+    #define DECLARE_ASM_CONST(n,t,v)    __declspec(align(n)) static const t v
+#else
+    #define DECLARE_ALIGNED(n,t,v)      t v
+    #define DECLARE_ASM_CONST(n,t,v)    static const t v
+#endif
+
+#if AV_GCC_VERSION_AT_LEAST(3,1)
+    #define av_malloc_attrib __attribute__((__malloc__))
+#else
+    #define av_malloc_attrib
+#endif
+
+#if AV_GCC_VERSION_AT_LEAST(4,3)
+    #define av_alloc_size(...) __attribute__((alloc_size(__VA_ARGS__)))
+#else
+    #define av_alloc_size(...)
+#endif
+
+/**
+ * Allocate a block of size bytes with alignment suitable for all
+ * memory accesses (including vectors if available on the CPU).
+ * @param size Size in bytes for the memory block to be allocated.
+ * @return Pointer to the allocated block, NULL if the block cannot
+ * be allocated.
+ * @see av_mallocz()
+ */
+void *av_malloc(size_t size) av_malloc_attrib av_alloc_size(1);
+
+/**
+ * Allocate a block of size * nmemb bytes with av_malloc().
+ * @param nmemb Number of elements
+ * @param size Size of the single element
+ * @return Pointer to the allocated block, NULL if the block cannot
+ * be allocated.
+ * @see av_malloc()
+ */
+av_alloc_size(1, 2) static inline void *av_malloc_array(size_t nmemb, size_t size)
+{
+    if (!size || nmemb >= INT_MAX / size)
+        return NULL;
+    return av_malloc(nmemb * size);
+}
+
+/**
+ * Allocate or reallocate a block of memory.
+ * If ptr is NULL and size > 0, allocate a new block. If
+ * size is zero, free the memory block pointed to by ptr.
+ * @param ptr Pointer to a memory block already allocated with
+ * av_realloc() or NULL.
+ * @param size Size in bytes of the memory block to be allocated or
+ * reallocated.
+ * @return Pointer to a newly-reallocated block or NULL if the block
+ * cannot be reallocated or the function is used to free the memory block.
+ * @warning Pointers originating from the av_malloc() family of functions must
+ *          not be passed to av_realloc(). The former can be implemented using
+ *          memalign() (or other functions), and there is no guarantee that
+ *          pointers from such functions can be passed to realloc() at all.
+ *          The situation is undefined according to POSIX and may crash with
+ *          some libc implementations.
+ * @see av_fast_realloc()
+ */
+void *av_realloc(void *ptr, size_t size) av_alloc_size(2);
+
+/**
+ * Allocate or reallocate a block of memory.
+ * This function does the same thing as av_realloc, except:
+ * - It takes two arguments and checks the result of the multiplication for
+ *   integer overflow.
+ * - It frees the input block in case of failure, thus avoiding the memory
+ *   leak with the classic "buf = realloc(buf); if (!buf) return -1;".
+ */
+void *av_realloc_f(void *ptr, size_t nelem, size_t elsize);
+
+/**
+ * Allocate or reallocate a block of memory.
+ * If *ptr is NULL and size > 0, allocate a new block. If
+ * size is zero, free the memory block pointed to by ptr.
+ * @param   ptr Pointer to a pointer to a memory block already allocated
+ *          with av_realloc(), or pointer to a pointer to NULL.
+ *          The pointer is updated on success, or freed on failure.
+ * @param   size Size in bytes for the memory block to be allocated or
+ *          reallocated
+ * @return  Zero on success, an AVERROR error code on failure.
+ * @warning Pointers originating from the av_malloc() family of functions must
+ *          not be passed to av_reallocp(). The former can be implemented using
+ *          memalign() (or other functions), and there is no guarantee that
+ *          pointers from such functions can be passed to realloc() at all.
+ *          The situation is undefined according to POSIX and may crash with
+ *          some libc implementations.
+ */
+int av_reallocp(void *ptr, size_t size);
+
+/**
+ * Allocate or reallocate an array.
+ * If ptr is NULL and nmemb > 0, allocate a new block. If
+ * nmemb is zero, free the memory block pointed to by ptr.
+ * @param ptr Pointer to a memory block already allocated with
+ * av_realloc() or NULL.
+ * @param nmemb Number of elements
+ * @param size Size of the single element
+ * @return Pointer to a newly-reallocated block or NULL if the block
+ * cannot be reallocated or the function is used to free the memory block.
+ * @warning Pointers originating from the av_malloc() family of functions must
+ *          not be passed to av_realloc(). The former can be implemented using
+ *          memalign() (or other functions), and there is no guarantee that
+ *          pointers from such functions can be passed to realloc() at all.
+ *          The situation is undefined according to POSIX and may crash with
+ *          some libc implementations.
+ */
+av_alloc_size(2, 3) void *av_realloc_array(void *ptr, size_t nmemb, size_t size);
+
+/**
+ * Allocate or reallocate an array through a pointer to a pointer.
+ * If *ptr is NULL and nmemb > 0, allocate a new block. If
+ * nmemb is zero, free the memory block pointed to by ptr.
+ * @param ptr Pointer to a pointer to a memory block already allocated
+ * with av_realloc(), or pointer to a pointer to NULL.
+ * The pointer is updated on success, or freed on failure.
+ * @param nmemb Number of elements
+ * @param size Size of the single element
+ * @return Zero on success, an AVERROR error code on failure.
+ * @warning Pointers originating from the av_malloc() family of functions must
+ *          not be passed to av_realloc(). The former can be implemented using
+ *          memalign() (or other functions), and there is no guarantee that
+ *          pointers from such functions can be passed to realloc() at all.
+ *          The situation is undefined according to POSIX and may crash with
+ *          some libc implementations.
+ */
+av_alloc_size(2, 3) int av_reallocp_array(void *ptr, size_t nmemb, size_t size);
+
+/**
+ * Free a memory block which has been allocated with av_malloc(z)() or
+ * av_realloc().
+ * @param ptr Pointer to the memory block which should be freed.
+ * @note ptr = NULL is explicitly allowed.
+ * @note It is recommended that you use av_freep() instead.
+ * @see av_freep()
+ */
+void av_free(void *ptr);
+
+/**
+ * Allocate a block of size bytes with alignment suitable for all
+ * memory accesses (including vectors if available on the CPU) and
+ * zero all the bytes of the block.
+ * @param size Size in bytes for the memory block to be allocated.
+ * @return Pointer to the allocated block, NULL if it cannot be allocated.
+ * @see av_malloc()
+ */
+void *av_mallocz(size_t size) av_malloc_attrib av_alloc_size(1);
+
+/**
+ * Allocate a block of nmemb * size bytes with alignment suitable for all
+ * memory accesses (including vectors if available on the CPU) and
+ * zero all the bytes of the block.
+ * The allocation will fail if nmemb * size is greater than or equal
+ * to INT_MAX.
+ * @param nmemb
+ * @param size
+ * @return Pointer to the allocated block, NULL if it cannot be allocated.
+ */
+void *av_calloc(size_t nmemb, size_t size) av_malloc_attrib;
+
+/**
+ * Allocate a block of size * nmemb bytes with av_mallocz().
+ * @param nmemb Number of elements
+ * @param size Size of the single element
+ * @return Pointer to the allocated block, NULL if the block cannot
+ * be allocated.
+ * @see av_mallocz()
+ * @see av_malloc_array()
+ */
+av_alloc_size(1, 2) static inline void *av_mallocz_array(size_t nmemb, size_t size)
+{
+    if (!size || nmemb >= INT_MAX / size)
+        return NULL;
+    return av_mallocz(nmemb * size);
+}
+
+/**
+ * Duplicate the string s.
+ * @param s string to be duplicated
+ * @return Pointer to a newly-allocated string containing a
+ * copy of s or NULL if the string cannot be allocated.
+ */
+char *av_strdup(const char *s) av_malloc_attrib;
+
+/**
+ * Duplicate the buffer p.
+ * @param p buffer to be duplicated
+ * @return Pointer to a newly allocated buffer containing a
+ * copy of p or NULL if the buffer cannot be allocated.
+ */
+void *av_memdup(const void *p, size_t size);
+
+/**
+ * Free a memory block which has been allocated with av_malloc(z)() or
+ * av_realloc() and set the pointer pointing to it to NULL.
+ * @param ptr Pointer to the pointer to the memory block which should
+ * be freed.
+ * @see av_free()
+ */
+void av_freep(void *ptr);
+
+/**
+ * Add an element to a dynamic array.
+ *
+ * The array to grow is supposed to be an array of pointers to
+ * structures, and the element to add must be a pointer to an already
+ * allocated structure.
+ *
+ * The array is reallocated when its size reaches powers of 2.
+ * Therefore, the amortized cost of adding an element is constant.
+ *
+ * In case of success, the pointer to the array is updated in order to
+ * point to the new grown array, and the number pointed to by nb_ptr
+ * is incremented.
+ * In case of failure, the array is freed, *tab_ptr is set to NULL and
+ * *nb_ptr is set to 0.
+ *
+ * @param tab_ptr pointer to the array to grow
+ * @param nb_ptr  pointer to the number of elements in the array
+ * @param elem    element to add
+ * @see av_dynarray2_add()
+ */
+void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem);
+
+/**
+ * Add an element of size elem_size to a dynamic array.
+ *
+ * The array is reallocated when its number of elements reaches powers of 2.
+ * Therefore, the amortized cost of adding an element is constant.
+ *
+ * In case of success, the pointer to the array is updated in order to
+ * point to the new grown array, and the number pointed to by nb_ptr
+ * is incremented.
+ * In case of failure, the array is freed, *tab_ptr is set to NULL and
+ * *nb_ptr is set to 0.
+ *
+ * @param tab_ptr   pointer to the array to grow
+ * @param nb_ptr    pointer to the number of elements in the array
+ * @param elem_size size in bytes of the elements in the array
+ * @param elem_data pointer to the data of the element to add. If NULL, the space of
+ *                  the new added element is not filled.
+ * @return          pointer to the data of the element to copy in the new allocated space.
+ *                  If NULL, the new allocated space is left uninitialized."
+ * @see av_dynarray_add()
+ */
+void *av_dynarray2_add(void **tab_ptr, int *nb_ptr, size_t elem_size,
+                       const uint8_t *elem_data);
+
+/**
+ * Multiply two size_t values checking for overflow.
+ * @return  0 if success, AVERROR(EINVAL) if overflow.
+ */
+static inline int av_size_mult(size_t a, size_t b, size_t *r)
+{
+    size_t t = a * b;
+    /* Hack inspired from glibc: only try the division if nelem and elsize
+     * are both greater than sqrt(SIZE_MAX). */
+    if ((a | b) >= ((size_t)1 << (sizeof(size_t) * 4)) && a && t / a != b)
+        return AVERROR(EINVAL);
+    *r = t;
+    return 0;
+}
+
+/**
+ * Set the maximum size that may me allocated in one block.
+ */
+void av_max_alloc(size_t max);
+
+/**
+ * deliberately overlapping memcpy implementation
+ * @param dst destination buffer
+ * @param back how many bytes back we start (the initial size of the overlapping window), must be > 0
+ * @param cnt number of bytes to copy, must be >= 0
+ *
+ * cnt > back is valid, this will copy the bytes we just copied,
+ * thus creating a repeating pattern with a period length of back.
+ */
+void av_memcpy_backptr(uint8_t *dst, int back, int cnt);
+
+/**
+ * @}
+ */
+
+#endif /* AVUTIL_MEM_H */

+ 32 - 0
wave420l/code/ffmpeg/include/libavutil/murmur3.h

@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2013 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_MURMUR3_H
+#define AVUTIL_MURMUR3_H
+
+#include <stdint.h>
+
+struct AVMurMur3 *av_murmur3_alloc(void);
+void av_murmur3_init_seeded(struct AVMurMur3 *c, uint64_t seed);
+void av_murmur3_init(struct AVMurMur3 *c);
+void av_murmur3_update(struct AVMurMur3 *c, const uint8_t *src, int len);
+void av_murmur3_final(struct AVMurMur3 *c, uint8_t dst[16]);
+
+#endif /* AVUTIL_MURMUR3_H */

+ 175 - 0
wave420l/code/ffmpeg/include/libavutil/old_pix_fmts.h

@@ -0,0 +1,175 @@
+/*
+ * copyright (c) 2006-2012 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_OLD_PIX_FMTS_H
+#define AVUTIL_OLD_PIX_FMTS_H
+
+/*
+ * This header exists to prevent new pixel formats from being accidentally added
+ * to the deprecated list.
+ * Do not include it directly. It will be removed on next major bump
+ *
+ * Do not add new items to this list. Use the AVPixelFormat enum instead.
+ */
+    PIX_FMT_NONE = AV_PIX_FMT_NONE,
+    PIX_FMT_YUV420P,   ///< planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
+    PIX_FMT_YUYV422,   ///< packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
+    PIX_FMT_RGB24,     ///< packed RGB 8:8:8, 24bpp, RGBRGB...
+    PIX_FMT_BGR24,     ///< packed RGB 8:8:8, 24bpp, BGRBGR...
+    PIX_FMT_YUV422P,   ///< planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
+    PIX_FMT_YUV444P,   ///< planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
+    PIX_FMT_YUV410P,   ///< planar YUV 4:1:0,  9bpp, (1 Cr & Cb sample per 4x4 Y samples)
+    PIX_FMT_YUV411P,   ///< planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
+    PIX_FMT_GRAY8,     ///<        Y        ,  8bpp
+    PIX_FMT_MONOWHITE, ///<        Y        ,  1bpp, 0 is white, 1 is black, in each byte pixels are ordered from the msb to the lsb
+    PIX_FMT_MONOBLACK, ///<        Y        ,  1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb
+    PIX_FMT_PAL8,      ///< 8 bit with PIX_FMT_RGB32 palette
+    PIX_FMT_YUVJ420P,  ///< planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV420P and setting color_range
+    PIX_FMT_YUVJ422P,  ///< planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV422P and setting color_range
+    PIX_FMT_YUVJ444P,  ///< planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV444P and setting color_range
+    PIX_FMT_XVMC_MPEG2_MC,///< XVideo Motion Acceleration via common packet passing
+    PIX_FMT_XVMC_MPEG2_IDCT,
+    PIX_FMT_UYVY422,   ///< packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
+    PIX_FMT_UYYVYY411, ///< packed YUV 4:1:1, 12bpp, Cb Y0 Y1 Cr Y2 Y3
+    PIX_FMT_BGR8,      ///< packed RGB 3:3:2,  8bpp, (msb)2B 3G 3R(lsb)
+    PIX_FMT_BGR4,      ///< packed RGB 1:2:1 bitstream,  4bpp, (msb)1B 2G 1R(lsb), a byte contains two pixels, the first pixel in the byte is the one composed by the 4 msb bits
+    PIX_FMT_BGR4_BYTE, ///< packed RGB 1:2:1,  8bpp, (msb)1B 2G 1R(lsb)
+    PIX_FMT_RGB8,      ///< packed RGB 3:3:2,  8bpp, (msb)2R 3G 3B(lsb)
+    PIX_FMT_RGB4,      ///< packed RGB 1:2:1 bitstream,  4bpp, (msb)1R 2G 1B(lsb), a byte contains two pixels, the first pixel in the byte is the one composed by the 4 msb bits
+    PIX_FMT_RGB4_BYTE, ///< packed RGB 1:2:1,  8bpp, (msb)1R 2G 1B(lsb)
+    PIX_FMT_NV12,      ///< planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (first byte U and the following byte V)
+    PIX_FMT_NV21,      ///< as above, but U and V bytes are swapped
+
+    PIX_FMT_ARGB,      ///< packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
+    PIX_FMT_RGBA,      ///< packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
+    PIX_FMT_ABGR,      ///< packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
+    PIX_FMT_BGRA,      ///< packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
+
+    PIX_FMT_GRAY16BE,  ///<        Y        , 16bpp, big-endian
+    PIX_FMT_GRAY16LE,  ///<        Y        , 16bpp, little-endian
+    PIX_FMT_YUV440P,   ///< planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
+    PIX_FMT_YUVJ440P,  ///< planar YUV 4:4:0 full scale (JPEG), deprecated in favor of PIX_FMT_YUV440P and setting color_range
+    PIX_FMT_YUVA420P,  ///< planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
+#if FF_API_VDPAU
+    PIX_FMT_VDPAU_H264,///< H.264 HW decoding with VDPAU, data[0] contains a vdpau_render_state struct which contains the bitstream of the slices as well as various fields extracted from headers
+    PIX_FMT_VDPAU_MPEG1,///< MPEG-1 HW decoding with VDPAU, data[0] contains a vdpau_render_state struct which contains the bitstream of the slices as well as various fields extracted from headers
+    PIX_FMT_VDPAU_MPEG2,///< MPEG-2 HW decoding with VDPAU, data[0] contains a vdpau_render_state struct which contains the bitstream of the slices as well as various fields extracted from headers
+    PIX_FMT_VDPAU_WMV3,///< WMV3 HW decoding with VDPAU, data[0] contains a vdpau_render_state struct which contains the bitstream of the slices as well as various fields extracted from headers
+    PIX_FMT_VDPAU_VC1, ///< VC-1 HW decoding with VDPAU, data[0] contains a vdpau_render_state struct which contains the bitstream of the slices as well as various fields extracted from headers
+#endif
+    PIX_FMT_RGB48BE,   ///< packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as big-endian
+    PIX_FMT_RGB48LE,   ///< packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as little-endian
+
+    PIX_FMT_RGB565BE,  ///< packed RGB 5:6:5, 16bpp, (msb)   5R 6G 5B(lsb), big-endian
+    PIX_FMT_RGB565LE,  ///< packed RGB 5:6:5, 16bpp, (msb)   5R 6G 5B(lsb), little-endian
+    PIX_FMT_RGB555BE,  ///< packed RGB 5:5:5, 16bpp, (msb)1A 5R 5G 5B(lsb), big-endian, most significant bit to 0
+    PIX_FMT_RGB555LE,  ///< packed RGB 5:5:5, 16bpp, (msb)1A 5R 5G 5B(lsb), little-endian, most significant bit to 0
+
+    PIX_FMT_BGR565BE,  ///< packed BGR 5:6:5, 16bpp, (msb)   5B 6G 5R(lsb), big-endian
+    PIX_FMT_BGR565LE,  ///< packed BGR 5:6:5, 16bpp, (msb)   5B 6G 5R(lsb), little-endian
+    PIX_FMT_BGR555BE,  ///< packed BGR 5:5:5, 16bpp, (msb)1A 5B 5G 5R(lsb), big-endian, most significant bit to 1
+    PIX_FMT_BGR555LE,  ///< packed BGR 5:5:5, 16bpp, (msb)1A 5B 5G 5R(lsb), little-endian, most significant bit to 1
+
+    PIX_FMT_VAAPI_MOCO, ///< HW acceleration through VA API at motion compensation entry-point, Picture.data[3] contains a vaapi_render_state struct which contains macroblocks as well as various fields extracted from headers
+    PIX_FMT_VAAPI_IDCT, ///< HW acceleration through VA API at IDCT entry-point, Picture.data[3] contains a vaapi_render_state struct which contains fields extracted from headers
+    PIX_FMT_VAAPI_VLD,  ///< HW decoding through VA API, Picture.data[3] contains a vaapi_render_state struct which contains the bitstream of the slices as well as various fields extracted from headers
+
+    PIX_FMT_YUV420P16LE,  ///< planar YUV 4:2:0, 24bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
+    PIX_FMT_YUV420P16BE,  ///< planar YUV 4:2:0, 24bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
+    PIX_FMT_YUV422P16LE,  ///< planar YUV 4:2:2, 32bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
+    PIX_FMT_YUV422P16BE,  ///< planar YUV 4:2:2, 32bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
+    PIX_FMT_YUV444P16LE,  ///< planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
+    PIX_FMT_YUV444P16BE,  ///< planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
+#if FF_API_VDPAU
+    PIX_FMT_VDPAU_MPEG4,  ///< MPEG4 HW decoding with VDPAU, data[0] contains a vdpau_render_state struct which contains the bitstream of the slices as well as various fields extracted from headers
+#endif
+    PIX_FMT_DXVA2_VLD,    ///< HW decoding through DXVA2, Picture.data[3] contains a LPDIRECT3DSURFACE9 pointer
+
+    PIX_FMT_RGB444LE,  ///< packed RGB 4:4:4, 16bpp, (msb)4A 4R 4G 4B(lsb), little-endian, most significant bits to 0
+    PIX_FMT_RGB444BE,  ///< packed RGB 4:4:4, 16bpp, (msb)4A 4R 4G 4B(lsb), big-endian, most significant bits to 0
+    PIX_FMT_BGR444LE,  ///< packed BGR 4:4:4, 16bpp, (msb)4A 4B 4G 4R(lsb), little-endian, most significant bits to 1
+    PIX_FMT_BGR444BE,  ///< packed BGR 4:4:4, 16bpp, (msb)4A 4B 4G 4R(lsb), big-endian, most significant bits to 1
+    PIX_FMT_GRAY8A,    ///< 8bit gray, 8bit alpha
+    PIX_FMT_BGR48BE,   ///< packed RGB 16:16:16, 48bpp, 16B, 16G, 16R, the 2-byte value for each R/G/B component is stored as big-endian
+    PIX_FMT_BGR48LE,   ///< packed RGB 16:16:16, 48bpp, 16B, 16G, 16R, the 2-byte value for each R/G/B component is stored as little-endian
+
+    //the following 10 formats have the disadvantage of needing 1 format for each bit depth, thus
+    //If you want to support multiple bit depths, then using PIX_FMT_YUV420P16* with the bpp stored separately
+    //is better
+    PIX_FMT_YUV420P9BE, ///< planar YUV 4:2:0, 13.5bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
+    PIX_FMT_YUV420P9LE, ///< planar YUV 4:2:0, 13.5bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
+    PIX_FMT_YUV420P10BE,///< planar YUV 4:2:0, 15bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
+    PIX_FMT_YUV420P10LE,///< planar YUV 4:2:0, 15bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
+    PIX_FMT_YUV422P10BE,///< planar YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
+    PIX_FMT_YUV422P10LE,///< planar YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
+    PIX_FMT_YUV444P9BE, ///< planar YUV 4:4:4, 27bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
+    PIX_FMT_YUV444P9LE, ///< planar YUV 4:4:4, 27bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
+    PIX_FMT_YUV444P10BE,///< planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
+    PIX_FMT_YUV444P10LE,///< planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
+    PIX_FMT_YUV422P9BE, ///< planar YUV 4:2:2, 18bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
+    PIX_FMT_YUV422P9LE, ///< planar YUV 4:2:2, 18bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
+    PIX_FMT_VDA_VLD,    ///< hardware decoding through VDA
+
+#ifdef AV_PIX_FMT_ABI_GIT_MASTER
+    PIX_FMT_RGBA64BE,  ///< packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is stored as big-endian
+    PIX_FMT_RGBA64LE,  ///< packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is stored as little-endian
+    PIX_FMT_BGRA64BE,  ///< packed RGBA 16:16:16:16, 64bpp, 16B, 16G, 16R, 16A, the 2-byte value for each R/G/B/A component is stored as big-endian
+    PIX_FMT_BGRA64LE,  ///< packed RGBA 16:16:16:16, 64bpp, 16B, 16G, 16R, 16A, the 2-byte value for each R/G/B/A component is stored as little-endian
+#endif
+    PIX_FMT_GBRP,      ///< planar GBR 4:4:4 24bpp
+    PIX_FMT_GBRP9BE,   ///< planar GBR 4:4:4 27bpp, big endian
+    PIX_FMT_GBRP9LE,   ///< planar GBR 4:4:4 27bpp, little endian
+    PIX_FMT_GBRP10BE,  ///< planar GBR 4:4:4 30bpp, big endian
+    PIX_FMT_GBRP10LE,  ///< planar GBR 4:4:4 30bpp, little endian
+    PIX_FMT_GBRP16BE,  ///< planar GBR 4:4:4 48bpp, big endian
+    PIX_FMT_GBRP16LE,  ///< planar GBR 4:4:4 48bpp, little endian
+
+#ifndef AV_PIX_FMT_ABI_GIT_MASTER
+    PIX_FMT_RGBA64BE=0x123,  ///< packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is stored as big-endian
+    PIX_FMT_RGBA64LE,  ///< packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is stored as little-endian
+    PIX_FMT_BGRA64BE,  ///< packed RGBA 16:16:16:16, 64bpp, 16B, 16G, 16R, 16A, the 2-byte value for each R/G/B/A component is stored as big-endian
+    PIX_FMT_BGRA64LE,  ///< packed RGBA 16:16:16:16, 64bpp, 16B, 16G, 16R, 16A, the 2-byte value for each R/G/B/A component is stored as little-endian
+#endif
+    PIX_FMT_0RGB=0x123+4,      ///< packed RGB 8:8:8, 32bpp, 0RGB0RGB...
+    PIX_FMT_RGB0,      ///< packed RGB 8:8:8, 32bpp, RGB0RGB0...
+    PIX_FMT_0BGR,      ///< packed BGR 8:8:8, 32bpp, 0BGR0BGR...
+    PIX_FMT_BGR0,      ///< packed BGR 8:8:8, 32bpp, BGR0BGR0...
+    PIX_FMT_YUVA444P,  ///< planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
+    PIX_FMT_YUVA422P,  ///< planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
+
+    PIX_FMT_YUV420P12BE, ///< planar YUV 4:2:0,18bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
+    PIX_FMT_YUV420P12LE, ///< planar YUV 4:2:0,18bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
+    PIX_FMT_YUV420P14BE, ///< planar YUV 4:2:0,21bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
+    PIX_FMT_YUV420P14LE, ///< planar YUV 4:2:0,21bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
+    PIX_FMT_YUV422P12BE, ///< planar YUV 4:2:2,24bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
+    PIX_FMT_YUV422P12LE, ///< planar YUV 4:2:2,24bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
+    PIX_FMT_YUV422P14BE, ///< planar YUV 4:2:2,28bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
+    PIX_FMT_YUV422P14LE, ///< planar YUV 4:2:2,28bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
+    PIX_FMT_YUV444P12BE, ///< planar YUV 4:4:4,36bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
+    PIX_FMT_YUV444P12LE, ///< planar YUV 4:4:4,36bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
+    PIX_FMT_YUV444P14BE, ///< planar YUV 4:4:4,42bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
+    PIX_FMT_YUV444P14LE, ///< planar YUV 4:4:4,42bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
+    PIX_FMT_GBRP12BE,    ///< planar GBR 4:4:4 36bpp, big endian
+    PIX_FMT_GBRP12LE,    ///< planar GBR 4:4:4 36bpp, little endian
+    PIX_FMT_GBRP14BE,    ///< planar GBR 4:4:4 42bpp, big endian
+    PIX_FMT_GBRP14LE,    ///< planar GBR 4:4:4 42bpp, little endian
+
+    PIX_FMT_NB,        ///< number of pixel formats, DO NOT USE THIS if you want to link with shared libav* because the number of formats might differ between versions
+#endif /* AVUTIL_OLD_PIX_FMTS_H */

+ 757 - 0
wave420l/code/ffmpeg/include/libavutil/opt.h

@@ -0,0 +1,757 @@
+/*
+ * AVOptions
+ * copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_OPT_H
+#define AVUTIL_OPT_H
+
+/**
+ * @file
+ * AVOptions
+ */
+
+#include "rational.h"
+#include "avutil.h"
+#include "dict.h"
+#include "log.h"
+#include "pixfmt.h"
+#include "samplefmt.h"
+
+/**
+ * @defgroup avoptions AVOptions
+ * @ingroup lavu_data
+ * @{
+ * AVOptions provide a generic system to declare options on arbitrary structs
+ * ("objects"). An option can have a help text, a type and a range of possible
+ * values. Options may then be enumerated, read and written to.
+ *
+ * @section avoptions_implement Implementing AVOptions
+ * This section describes how to add AVOptions capabilities to a struct.
+ *
+ * All AVOptions-related information is stored in an AVClass. Therefore
+ * the first member of the struct should be a pointer to an AVClass describing it.
+ * The option field of the AVClass must be set to a NULL-terminated static array
+ * of AVOptions. Each AVOption must have a non-empty name, a type, a default
+ * value and for number-type AVOptions also a range of allowed values. It must
+ * also declare an offset in bytes from the start of the struct, where the field
+ * associated with this AVOption is located. Other fields in the AVOption struct
+ * should also be set when applicable, but are not required.
+ *
+ * The following example illustrates an AVOptions-enabled struct:
+ * @code
+ * typedef struct test_struct {
+ *     AVClass *class;
+ *     int      int_opt;
+ *     char    *str_opt;
+ *     uint8_t *bin_opt;
+ *     int      bin_len;
+ * } test_struct;
+ *
+ * static const AVOption test_options[] = {
+ *   { "test_int", "This is a test option of int type.", offsetof(test_struct, int_opt),
+ *     AV_OPT_TYPE_INT, { .i64 = -1 }, INT_MIN, INT_MAX },
+ *   { "test_str", "This is a test option of string type.", offsetof(test_struct, str_opt),
+ *     AV_OPT_TYPE_STRING },
+ *   { "test_bin", "This is a test option of binary type.", offsetof(test_struct, bin_opt),
+ *     AV_OPT_TYPE_BINARY },
+ *   { NULL },
+ * };
+ *
+ * static const AVClass test_class = {
+ *     .class_name = "test class",
+ *     .item_name  = av_default_item_name,
+ *     .option     = test_options,
+ *     .version    = LIBAVUTIL_VERSION_INT,
+ * };
+ * @endcode
+ *
+ * Next, when allocating your struct, you must ensure that the AVClass pointer
+ * is set to the correct value. Then, av_opt_set_defaults() can be called to
+ * initialize defaults. After that the struct is ready to be used with the
+ * AVOptions API.
+ *
+ * When cleaning up, you may use the av_opt_free() function to automatically
+ * free all the allocated string and binary options.
+ *
+ * Continuing with the above example:
+ *
+ * @code
+ * test_struct *alloc_test_struct(void)
+ * {
+ *     test_struct *ret = av_malloc(sizeof(*ret));
+ *     ret->class = &test_class;
+ *     av_opt_set_defaults(ret);
+ *     return ret;
+ * }
+ * void free_test_struct(test_struct **foo)
+ * {
+ *     av_opt_free(*foo);
+ *     av_freep(foo);
+ * }
+ * @endcode
+ *
+ * @subsection avoptions_implement_nesting Nesting
+ *      It may happen that an AVOptions-enabled struct contains another
+ *      AVOptions-enabled struct as a member (e.g. AVCodecContext in
+ *      libavcodec exports generic options, while its priv_data field exports
+ *      codec-specific options). In such a case, it is possible to set up the
+ *      parent struct to export a child's options. To do that, simply
+ *      implement AVClass.child_next() and AVClass.child_class_next() in the
+ *      parent struct's AVClass.
+ *      Assuming that the test_struct from above now also contains a
+ *      child_struct field:
+ *
+ *      @code
+ *      typedef struct child_struct {
+ *          AVClass *class;
+ *          int flags_opt;
+ *      } child_struct;
+ *      static const AVOption child_opts[] = {
+ *          { "test_flags", "This is a test option of flags type.",
+ *            offsetof(child_struct, flags_opt), AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT_MIN, INT_MAX },
+ *          { NULL },
+ *      };
+ *      static const AVClass child_class = {
+ *          .class_name = "child class",
+ *          .item_name  = av_default_item_name,
+ *          .option     = child_opts,
+ *          .version    = LIBAVUTIL_VERSION_INT,
+ *      };
+ *
+ *      void *child_next(void *obj, void *prev)
+ *      {
+ *          test_struct *t = obj;
+ *          if (!prev && t->child_struct)
+ *              return t->child_struct;
+ *          return NULL
+ *      }
+ *      const AVClass child_class_next(const AVClass *prev)
+ *      {
+ *          return prev ? NULL : &child_class;
+ *      }
+ *      @endcode
+ *      Putting child_next() and child_class_next() as defined above into
+ *      test_class will now make child_struct's options accessible through
+ *      test_struct (again, proper setup as described above needs to be done on
+ *      child_struct right after it is created).
+ *
+ *      From the above example it might not be clear why both child_next()
+ *      and child_class_next() are needed. The distinction is that child_next()
+ *      iterates over actually existing objects, while child_class_next()
+ *      iterates over all possible child classes. E.g. if an AVCodecContext
+ *      was initialized to use a codec which has private options, then its
+ *      child_next() will return AVCodecContext.priv_data and finish
+ *      iterating. OTOH child_class_next() on AVCodecContext.av_class will
+ *      iterate over all available codecs with private options.
+ *
+ * @subsection avoptions_implement_named_constants Named constants
+ *      It is possible to create named constants for options. Simply set the unit
+ *      field of the option the constants should apply to a string and
+ *      create the constants themselves as options of type AV_OPT_TYPE_CONST
+ *      with their unit field set to the same string.
+ *      Their default_val field should contain the value of the named
+ *      constant.
+ *      For example, to add some named constants for the test_flags option
+ *      above, put the following into the child_opts array:
+ *      @code
+ *      { "test_flags", "This is a test option of flags type.",
+ *        offsetof(child_struct, flags_opt), AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT_MIN, INT_MAX, "test_unit" },
+ *      { "flag1", "This is a flag with value 16", 0, AV_OPT_TYPE_CONST, { .i64 = 16 }, 0, 0, "test_unit" },
+ *      @endcode
+ *
+ * @section avoptions_use Using AVOptions
+ * This section deals with accessing options in an AVOptions-enabled struct.
+ * Such structs in FFmpeg are e.g. AVCodecContext in libavcodec or
+ * AVFormatContext in libavformat.
+ *
+ * @subsection avoptions_use_examine Examining AVOptions
+ * The basic functions for examining options are av_opt_next(), which iterates
+ * over all options defined for one object, and av_opt_find(), which searches
+ * for an option with the given name.
+ *
+ * The situation is more complicated with nesting. An AVOptions-enabled struct
+ * may have AVOptions-enabled children. Passing the AV_OPT_SEARCH_CHILDREN flag
+ * to av_opt_find() will make the function search children recursively.
+ *
+ * For enumerating there are basically two cases. The first is when you want to
+ * get all options that may potentially exist on the struct and its children
+ * (e.g.  when constructing documentation). In that case you should call
+ * av_opt_child_class_next() recursively on the parent struct's AVClass.  The
+ * second case is when you have an already initialized struct with all its
+ * children and you want to get all options that can be actually written or read
+ * from it. In that case you should call av_opt_child_next() recursively (and
+ * av_opt_next() on each result).
+ *
+ * @subsection avoptions_use_get_set Reading and writing AVOptions
+ * When setting options, you often have a string read directly from the
+ * user. In such a case, simply passing it to av_opt_set() is enough. For
+ * non-string type options, av_opt_set() will parse the string according to the
+ * option type.
+ *
+ * Similarly av_opt_get() will read any option type and convert it to a string
+ * which will be returned. Do not forget that the string is allocated, so you
+ * have to free it with av_free().
+ *
+ * In some cases it may be more convenient to put all options into an
+ * AVDictionary and call av_opt_set_dict() on it. A specific case of this
+ * are the format/codec open functions in lavf/lavc which take a dictionary
+ * filled with option as a parameter. This allows to set some options
+ * that cannot be set otherwise, since e.g. the input file format is not known
+ * before the file is actually opened.
+ */
+
+enum AVOptionType{
+    AV_OPT_TYPE_FLAGS,
+    AV_OPT_TYPE_INT,
+    AV_OPT_TYPE_INT64,
+    AV_OPT_TYPE_DOUBLE,
+    AV_OPT_TYPE_FLOAT,
+    AV_OPT_TYPE_STRING,
+    AV_OPT_TYPE_RATIONAL,
+    AV_OPT_TYPE_BINARY,  ///< offset must point to a pointer immediately followed by an int for the length
+    AV_OPT_TYPE_CONST = 128,
+    AV_OPT_TYPE_IMAGE_SIZE = MKBETAG('S','I','Z','E'), ///< offset must point to two consecutive integers
+    AV_OPT_TYPE_PIXEL_FMT  = MKBETAG('P','F','M','T'),
+    AV_OPT_TYPE_SAMPLE_FMT = MKBETAG('S','F','M','T'),
+    AV_OPT_TYPE_VIDEO_RATE = MKBETAG('V','R','A','T'), ///< offset must point to AVRational
+    AV_OPT_TYPE_DURATION   = MKBETAG('D','U','R',' '),
+    AV_OPT_TYPE_COLOR      = MKBETAG('C','O','L','R'),
+    AV_OPT_TYPE_CHANNEL_LAYOUT = MKBETAG('C','H','L','A'),
+#if FF_API_OLD_AVOPTIONS
+    FF_OPT_TYPE_FLAGS = 0,
+    FF_OPT_TYPE_INT,
+    FF_OPT_TYPE_INT64,
+    FF_OPT_TYPE_DOUBLE,
+    FF_OPT_TYPE_FLOAT,
+    FF_OPT_TYPE_STRING,
+    FF_OPT_TYPE_RATIONAL,
+    FF_OPT_TYPE_BINARY,  ///< offset must point to a pointer immediately followed by an int for the length
+    FF_OPT_TYPE_CONST=128,
+#endif
+};
+
+/**
+ * AVOption
+ */
+typedef struct AVOption {
+    const char *name;
+
+    /**
+     * short English help text
+     * @todo What about other languages?
+     */
+    const char *help;
+
+    /**
+     * The offset relative to the context structure where the option
+     * value is stored. It should be 0 for named constants.
+     */
+    int offset;
+    enum AVOptionType type;
+
+    /**
+     * the default value for scalar options
+     */
+    union {
+        int64_t i64;
+        double dbl;
+        const char *str;
+        /* TODO those are unused now */
+        AVRational q;
+    } default_val;
+    double min;                 ///< minimum valid value for the option
+    double max;                 ///< maximum valid value for the option
+
+    int flags;
+#define AV_OPT_FLAG_ENCODING_PARAM  1   ///< a generic parameter which can be set by the user for muxing or encoding
+#define AV_OPT_FLAG_DECODING_PARAM  2   ///< a generic parameter which can be set by the user for demuxing or decoding
+#define AV_OPT_FLAG_METADATA        4   ///< some data extracted or inserted into the file like title, comment, ...
+#define AV_OPT_FLAG_AUDIO_PARAM     8
+#define AV_OPT_FLAG_VIDEO_PARAM     16
+#define AV_OPT_FLAG_SUBTITLE_PARAM  32
+#define AV_OPT_FLAG_FILTERING_PARAM (1<<16) ///< a generic parameter which can be set by the user for filtering
+//FIXME think about enc-audio, ... style flags
+
+    /**
+     * The logical unit to which the option belongs. Non-constant
+     * options and corresponding named constants share the same
+     * unit. May be NULL.
+     */
+    const char *unit;
+} AVOption;
+
+/**
+ * A single allowed range of values, or a single allowed value.
+ */
+typedef struct AVOptionRange {
+    const char *str;
+    double value_min, value_max;             ///< For string ranges this represents the min/max length, for dimensions this represents the min/max pixel count
+    double component_min, component_max;     ///< For string this represents the unicode range for chars, 0-127 limits to ASCII
+    int is_range;                            ///< if set to 1 the struct encodes a range, if set to 0 a single value
+} AVOptionRange;
+
+/**
+ * List of AVOptionRange structs
+ */
+typedef struct AVOptionRanges {
+    AVOptionRange **range;
+    int nb_ranges;
+} AVOptionRanges;
+
+
+#if FF_API_FIND_OPT
+/**
+ * Look for an option in obj. Look only for the options which
+ * have the flags set as specified in mask and flags (that is,
+ * for which it is the case that (opt->flags & mask) == flags).
+ *
+ * @param[in] obj a pointer to a struct whose first element is a
+ * pointer to an AVClass
+ * @param[in] name the name of the option to look for
+ * @param[in] unit the unit of the option to look for, or any if NULL
+ * @return a pointer to the option found, or NULL if no option
+ * has been found
+ *
+ * @deprecated use av_opt_find.
+ */
+attribute_deprecated
+const AVOption *av_find_opt(void *obj, const char *name, const char *unit, int mask, int flags);
+#endif
+
+#if FF_API_OLD_AVOPTIONS
+/**
+ * Set the field of obj with the given name to value.
+ *
+ * @param[in] obj A struct whose first element is a pointer to an
+ * AVClass.
+ * @param[in] name the name of the field to set
+ * @param[in] val The value to set. If the field is not of a string
+ * type, then the given string is parsed.
+ * SI postfixes and some named scalars are supported.
+ * If the field is of a numeric type, it has to be a numeric or named
+ * scalar. Behavior with more than one scalar and +- infix operators
+ * is undefined.
+ * If the field is of a flags type, it has to be a sequence of numeric
+ * scalars or named flags separated by '+' or '-'. Prefixing a flag
+ * with '+' causes it to be set without affecting the other flags;
+ * similarly, '-' unsets a flag.
+ * @param[out] o_out if non-NULL put here a pointer to the AVOption
+ * found
+ * @param alloc this parameter is currently ignored
+ * @return 0 if the value has been set, or an AVERROR code in case of
+ * error:
+ * AVERROR_OPTION_NOT_FOUND if no matching option exists
+ * AVERROR(ERANGE) if the value is out of range
+ * AVERROR(EINVAL) if the value is not valid
+ * @deprecated use av_opt_set()
+ */
+attribute_deprecated
+int av_set_string3(void *obj, const char *name, const char *val, int alloc, const AVOption **o_out);
+
+attribute_deprecated const AVOption *av_set_double(void *obj, const char *name, double n);
+attribute_deprecated const AVOption *av_set_q(void *obj, const char *name, AVRational n);
+attribute_deprecated const AVOption *av_set_int(void *obj, const char *name, int64_t n);
+
+double av_get_double(void *obj, const char *name, const AVOption **o_out);
+AVRational av_get_q(void *obj, const char *name, const AVOption **o_out);
+int64_t av_get_int(void *obj, const char *name, const AVOption **o_out);
+attribute_deprecated const char *av_get_string(void *obj, const char *name, const AVOption **o_out, char *buf, int buf_len);
+attribute_deprecated const AVOption *av_next_option(void *obj, const AVOption *last);
+#endif
+
+/**
+ * Show the obj options.
+ *
+ * @param req_flags requested flags for the options to show. Show only the
+ * options for which it is opt->flags & req_flags.
+ * @param rej_flags rejected flags for the options to show. Show only the
+ * options for which it is !(opt->flags & req_flags).
+ * @param av_log_obj log context to use for showing the options
+ */
+int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags);
+
+/**
+ * Set the values of all AVOption fields to their default values.
+ *
+ * @param s an AVOption-enabled struct (its first member must be a pointer to AVClass)
+ */
+void av_opt_set_defaults(void *s);
+
+#if FF_API_OLD_AVOPTIONS
+attribute_deprecated
+void av_opt_set_defaults2(void *s, int mask, int flags);
+#endif
+
+/**
+ * Parse the key/value pairs list in opts. For each key/value pair
+ * found, stores the value in the field in ctx that is named like the
+ * key. ctx must be an AVClass context, storing is done using
+ * AVOptions.
+ *
+ * @param opts options string to parse, may be NULL
+ * @param key_val_sep a 0-terminated list of characters used to
+ * separate key from value
+ * @param pairs_sep a 0-terminated list of characters used to separate
+ * two pairs from each other
+ * @return the number of successfully set key/value pairs, or a negative
+ * value corresponding to an AVERROR code in case of error:
+ * AVERROR(EINVAL) if opts cannot be parsed,
+ * the error code issued by av_set_string3() if a key/value pair
+ * cannot be set
+ */
+int av_set_options_string(void *ctx, const char *opts,
+                          const char *key_val_sep, const char *pairs_sep);
+
+/**
+ * Parse the key-value pairs list in opts. For each key=value pair found,
+ * set the value of the corresponding option in ctx.
+ *
+ * @param ctx          the AVClass object to set options on
+ * @param opts         the options string, key-value pairs separated by a
+ *                     delimiter
+ * @param shorthand    a NULL-terminated array of options names for shorthand
+ *                     notation: if the first field in opts has no key part,
+ *                     the key is taken from the first element of shorthand;
+ *                     then again for the second, etc., until either opts is
+ *                     finished, shorthand is finished or a named option is
+ *                     found; after that, all options must be named
+ * @param key_val_sep  a 0-terminated list of characters used to separate
+ *                     key from value, for example '='
+ * @param pairs_sep    a 0-terminated list of characters used to separate
+ *                     two pairs from each other, for example ':' or ','
+ * @return  the number of successfully set key=value pairs, or a negative
+ *          value corresponding to an AVERROR code in case of error:
+ *          AVERROR(EINVAL) if opts cannot be parsed,
+ *          the error code issued by av_set_string3() if a key/value pair
+ *          cannot be set
+ *
+ * Options names must use only the following characters: a-z A-Z 0-9 - . / _
+ * Separators must use characters distinct from option names and from each
+ * other.
+ */
+int av_opt_set_from_string(void *ctx, const char *opts,
+                           const char *const *shorthand,
+                           const char *key_val_sep, const char *pairs_sep);
+/**
+ * Free all string and binary options in obj.
+ */
+void av_opt_free(void *obj);
+
+/**
+ * Check whether a particular flag is set in a flags field.
+ *
+ * @param field_name the name of the flag field option
+ * @param flag_name the name of the flag to check
+ * @return non-zero if the flag is set, zero if the flag isn't set,
+ *         isn't of the right type, or the flags field doesn't exist.
+ */
+int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name);
+
+/**
+ * Set all the options from a given dictionary on an object.
+ *
+ * @param obj a struct whose first element is a pointer to AVClass
+ * @param options options to process. This dictionary will be freed and replaced
+ *                by a new one containing all options not found in obj.
+ *                Of course this new dictionary needs to be freed by caller
+ *                with av_dict_free().
+ *
+ * @return 0 on success, a negative AVERROR if some option was found in obj,
+ *         but could not be set.
+ *
+ * @see av_dict_copy()
+ */
+int av_opt_set_dict(void *obj, struct AVDictionary **options);
+
+/**
+ * Extract a key-value pair from the beginning of a string.
+ *
+ * @param ropts        pointer to the options string, will be updated to
+ *                     point to the rest of the string (one of the pairs_sep
+ *                     or the final NUL)
+ * @param key_val_sep  a 0-terminated list of characters used to separate
+ *                     key from value, for example '='
+ * @param pairs_sep    a 0-terminated list of characters used to separate
+ *                     two pairs from each other, for example ':' or ','
+ * @param flags        flags; see the AV_OPT_FLAG_* values below
+ * @param rkey         parsed key; must be freed using av_free()
+ * @param rval         parsed value; must be freed using av_free()
+ *
+ * @return  >=0 for success, or a negative value corresponding to an
+ *          AVERROR code in case of error; in particular:
+ *          AVERROR(EINVAL) if no key is present
+ *
+ */
+int av_opt_get_key_value(const char **ropts,
+                         const char *key_val_sep, const char *pairs_sep,
+                         unsigned flags,
+                         char **rkey, char **rval);
+
+enum {
+
+    /**
+     * Accept to parse a value without a key; the key will then be returned
+     * as NULL.
+     */
+    AV_OPT_FLAG_IMPLICIT_KEY = 1,
+};
+
+/**
+ * @defgroup opt_eval_funcs Evaluating option strings
+ * @{
+ * This group of functions can be used to evaluate option strings
+ * and get numbers out of them. They do the same thing as av_opt_set(),
+ * except the result is written into the caller-supplied pointer.
+ *
+ * @param obj a struct whose first element is a pointer to AVClass.
+ * @param o an option for which the string is to be evaluated.
+ * @param val string to be evaluated.
+ * @param *_out value of the string will be written here.
+ *
+ * @return 0 on success, a negative number on failure.
+ */
+int av_opt_eval_flags (void *obj, const AVOption *o, const char *val, int        *flags_out);
+int av_opt_eval_int   (void *obj, const AVOption *o, const char *val, int        *int_out);
+int av_opt_eval_int64 (void *obj, const AVOption *o, const char *val, int64_t    *int64_out);
+int av_opt_eval_float (void *obj, const AVOption *o, const char *val, float      *float_out);
+int av_opt_eval_double(void *obj, const AVOption *o, const char *val, double     *double_out);
+int av_opt_eval_q     (void *obj, const AVOption *o, const char *val, AVRational *q_out);
+/**
+ * @}
+ */
+
+#define AV_OPT_SEARCH_CHILDREN   0x0001 /**< Search in possible children of the
+                                             given object first. */
+/**
+ *  The obj passed to av_opt_find() is fake -- only a double pointer to AVClass
+ *  instead of a required pointer to a struct containing AVClass. This is
+ *  useful for searching for options without needing to allocate the corresponding
+ *  object.
+ */
+#define AV_OPT_SEARCH_FAKE_OBJ   0x0002
+
+/**
+ * Look for an option in an object. Consider only options which
+ * have all the specified flags set.
+ *
+ * @param[in] obj A pointer to a struct whose first element is a
+ *                pointer to an AVClass.
+ *                Alternatively a double pointer to an AVClass, if
+ *                AV_OPT_SEARCH_FAKE_OBJ search flag is set.
+ * @param[in] name The name of the option to look for.
+ * @param[in] unit When searching for named constants, name of the unit
+ *                 it belongs to.
+ * @param opt_flags Find only options with all the specified flags set (AV_OPT_FLAG).
+ * @param search_flags A combination of AV_OPT_SEARCH_*.
+ *
+ * @return A pointer to the option found, or NULL if no option
+ *         was found.
+ *
+ * @note Options found with AV_OPT_SEARCH_CHILDREN flag may not be settable
+ * directly with av_set_string3(). Use special calls which take an options
+ * AVDictionary (e.g. avformat_open_input()) to set options found with this
+ * flag.
+ */
+const AVOption *av_opt_find(void *obj, const char *name, const char *unit,
+                            int opt_flags, int search_flags);
+
+/**
+ * Look for an option in an object. Consider only options which
+ * have all the specified flags set.
+ *
+ * @param[in] obj A pointer to a struct whose first element is a
+ *                pointer to an AVClass.
+ *                Alternatively a double pointer to an AVClass, if
+ *                AV_OPT_SEARCH_FAKE_OBJ search flag is set.
+ * @param[in] name The name of the option to look for.
+ * @param[in] unit When searching for named constants, name of the unit
+ *                 it belongs to.
+ * @param opt_flags Find only options with all the specified flags set (AV_OPT_FLAG).
+ * @param search_flags A combination of AV_OPT_SEARCH_*.
+ * @param[out] target_obj if non-NULL, an object to which the option belongs will be
+ * written here. It may be different from obj if AV_OPT_SEARCH_CHILDREN is present
+ * in search_flags. This parameter is ignored if search_flags contain
+ * AV_OPT_SEARCH_FAKE_OBJ.
+ *
+ * @return A pointer to the option found, or NULL if no option
+ *         was found.
+ */
+const AVOption *av_opt_find2(void *obj, const char *name, const char *unit,
+                             int opt_flags, int search_flags, void **target_obj);
+
+/**
+ * Iterate over all AVOptions belonging to obj.
+ *
+ * @param obj an AVOptions-enabled struct or a double pointer to an
+ *            AVClass describing it.
+ * @param prev result of the previous call to av_opt_next() on this object
+ *             or NULL
+ * @return next AVOption or NULL
+ */
+const AVOption *av_opt_next(void *obj, const AVOption *prev);
+
+/**
+ * Iterate over AVOptions-enabled children of obj.
+ *
+ * @param prev result of a previous call to this function or NULL
+ * @return next AVOptions-enabled child or NULL
+ */
+void *av_opt_child_next(void *obj, void *prev);
+
+/**
+ * Iterate over potential AVOptions-enabled children of parent.
+ *
+ * @param prev result of a previous call to this function or NULL
+ * @return AVClass corresponding to next potential child or NULL
+ */
+const AVClass *av_opt_child_class_next(const AVClass *parent, const AVClass *prev);
+
+/**
+ * @defgroup opt_set_funcs Option setting functions
+ * @{
+ * Those functions set the field of obj with the given name to value.
+ *
+ * @param[in] obj A struct whose first element is a pointer to an AVClass.
+ * @param[in] name the name of the field to set
+ * @param[in] val The value to set. In case of av_opt_set() if the field is not
+ * of a string type, then the given string is parsed.
+ * SI postfixes and some named scalars are supported.
+ * If the field is of a numeric type, it has to be a numeric or named
+ * scalar. Behavior with more than one scalar and +- infix operators
+ * is undefined.
+ * If the field is of a flags type, it has to be a sequence of numeric
+ * scalars or named flags separated by '+' or '-'. Prefixing a flag
+ * with '+' causes it to be set without affecting the other flags;
+ * similarly, '-' unsets a flag.
+ * @param search_flags flags passed to av_opt_find2. I.e. if AV_OPT_SEARCH_CHILDREN
+ * is passed here, then the option may be set on a child of obj.
+ *
+ * @return 0 if the value has been set, or an AVERROR code in case of
+ * error:
+ * AVERROR_OPTION_NOT_FOUND if no matching option exists
+ * AVERROR(ERANGE) if the value is out of range
+ * AVERROR(EINVAL) if the value is not valid
+ */
+int av_opt_set       (void *obj, const char *name, const char *val, int search_flags);
+int av_opt_set_int   (void *obj, const char *name, int64_t     val, int search_flags);
+int av_opt_set_double(void *obj, const char *name, double      val, int search_flags);
+int av_opt_set_q     (void *obj, const char *name, AVRational  val, int search_flags);
+int av_opt_set_bin   (void *obj, const char *name, const uint8_t *val, int size, int search_flags);
+int av_opt_set_image_size(void *obj, const char *name, int w, int h, int search_flags);
+int av_opt_set_pixel_fmt (void *obj, const char *name, enum AVPixelFormat fmt, int search_flags);
+int av_opt_set_sample_fmt(void *obj, const char *name, enum AVSampleFormat fmt, int search_flags);
+int av_opt_set_video_rate(void *obj, const char *name, AVRational val, int search_flags);
+int av_opt_set_channel_layout(void *obj, const char *name, int64_t ch_layout, int search_flags);
+
+/**
+ * Set a binary option to an integer list.
+ *
+ * @param obj    AVClass object to set options on
+ * @param name   name of the binary option
+ * @param val    pointer to an integer list (must have the correct type with
+ *               regard to the contents of the list)
+ * @param term   list terminator (usually 0 or -1)
+ * @param flags  search flags
+ */
+#define av_opt_set_int_list(obj, name, val, term, flags) \
+    (av_int_list_length(val, term) > INT_MAX / sizeof(*(val)) ? \
+     AVERROR(EINVAL) : \
+     av_opt_set_bin(obj, name, (const uint8_t *)(val), \
+                    av_int_list_length(val, term) * sizeof(*(val)), flags))
+/**
+ * @}
+ */
+
+/**
+ * @defgroup opt_get_funcs Option getting functions
+ * @{
+ * Those functions get a value of the option with the given name from an object.
+ *
+ * @param[in] obj a struct whose first element is a pointer to an AVClass.
+ * @param[in] name name of the option to get.
+ * @param[in] search_flags flags passed to av_opt_find2. I.e. if AV_OPT_SEARCH_CHILDREN
+ * is passed here, then the option may be found in a child of obj.
+ * @param[out] out_val value of the option will be written here
+ * @return >=0 on success, a negative error code otherwise
+ */
+/**
+ * @note the returned string will be av_malloc()ed and must be av_free()ed by the caller
+ */
+int av_opt_get       (void *obj, const char *name, int search_flags, uint8_t   **out_val);
+int av_opt_get_int   (void *obj, const char *name, int search_flags, int64_t    *out_val);
+int av_opt_get_double(void *obj, const char *name, int search_flags, double     *out_val);
+int av_opt_get_q     (void *obj, const char *name, int search_flags, AVRational *out_val);
+int av_opt_get_image_size(void *obj, const char *name, int search_flags, int *w_out, int *h_out);
+int av_opt_get_pixel_fmt (void *obj, const char *name, int search_flags, enum AVPixelFormat *out_fmt);
+int av_opt_get_sample_fmt(void *obj, const char *name, int search_flags, enum AVSampleFormat *out_fmt);
+int av_opt_get_video_rate(void *obj, const char *name, int search_flags, AVRational *out_val);
+int av_opt_get_channel_layout(void *obj, const char *name, int search_flags, int64_t *ch_layout);
+/**
+ * @}
+ */
+/**
+ * Gets a pointer to the requested field in a struct.
+ * This function allows accessing a struct even when its fields are moved or
+ * renamed since the application making the access has been compiled,
+ *
+ * @returns a pointer to the field, it can be cast to the correct type and read
+ *          or written to.
+ */
+void *av_opt_ptr(const AVClass *avclass, void *obj, const char *name);
+
+/**
+ * Free an AVOptionRanges struct and set it to NULL.
+ */
+void av_opt_freep_ranges(AVOptionRanges **ranges);
+
+/**
+ * Get a list of allowed ranges for the given option.
+ *
+ * The returned list may depend on other fields in obj like for example profile.
+ *
+ * @param flags is a bitmask of flags, undefined flags should not be set and should be ignored
+ *              AV_OPT_SEARCH_FAKE_OBJ indicates that the obj is a double pointer to a AVClass instead of a full instance
+ *
+ * The result must be freed with av_opt_freep_ranges.
+ *
+ * @return >= 0 on success, a negative errro code otherwise
+ */
+int av_opt_query_ranges(AVOptionRanges **, void *obj, const char *key, int flags);
+
+/**
+ * Get a default list of allowed ranges for the given option.
+ *
+ * This list is constructed without using the AVClass.query_ranges() callback
+ * and can be used as fallback from within the callback.
+ *
+ * @param flags is a bitmask of flags, undefined flags should not be set and should be ignored
+ *              AV_OPT_SEARCH_FAKE_OBJ indicates that the obj is a double pointer to a AVClass instead of a full instance
+ *
+ * The result must be freed with av_opt_free_ranges.
+ *
+ * @return >= 0 on success, a negative errro code otherwise
+ */
+int av_opt_query_ranges_default(AVOptionRanges **, void *obj, const char *key, int flags);
+
+/**
+ * @}
+ */
+
+#endif /* AVUTIL_OPT_H */

+ 187 - 0
wave420l/code/ffmpeg/include/libavutil/parseutils.h

@@ -0,0 +1,187 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_PARSEUTILS_H
+#define AVUTIL_PARSEUTILS_H
+
+#include <time.h>
+
+#include "rational.h"
+
+/**
+ * @file
+ * misc parsing utilities
+ */
+
+/**
+ * Parse str and store the parsed ratio in q.
+ *
+ * Note that a ratio with infinite (1/0) or negative value is
+ * considered valid, so you should check on the returned value if you
+ * want to exclude those values.
+ *
+ * The undefined value can be expressed using the "0:0" string.
+ *
+ * @param[in,out] q pointer to the AVRational which will contain the ratio
+ * @param[in] str the string to parse: it has to be a string in the format
+ * num:den, a float number or an expression
+ * @param[in] max the maximum allowed numerator and denominator
+ * @param[in] log_offset log level offset which is applied to the log
+ * level of log_ctx
+ * @param[in] log_ctx parent logging context
+ * @return >= 0 on success, a negative error code otherwise
+ */
+int av_parse_ratio(AVRational *q, const char *str, int max,
+                   int log_offset, void *log_ctx);
+
+#define av_parse_ratio_quiet(rate, str, max) \
+    av_parse_ratio(rate, str, max, AV_LOG_MAX_OFFSET, NULL)
+
+/**
+ * Parse str and put in width_ptr and height_ptr the detected values.
+ *
+ * @param[in,out] width_ptr pointer to the variable which will contain the detected
+ * width value
+ * @param[in,out] height_ptr pointer to the variable which will contain the detected
+ * height value
+ * @param[in] str the string to parse: it has to be a string in the format
+ * width x height or a valid video size abbreviation.
+ * @return >= 0 on success, a negative error code otherwise
+ */
+int av_parse_video_size(int *width_ptr, int *height_ptr, const char *str);
+
+/**
+ * Parse str and store the detected values in *rate.
+ *
+ * @param[in,out] rate pointer to the AVRational which will contain the detected
+ * frame rate
+ * @param[in] str the string to parse: it has to be a string in the format
+ * rate_num / rate_den, a float number or a valid video rate abbreviation
+ * @return >= 0 on success, a negative error code otherwise
+ */
+int av_parse_video_rate(AVRational *rate, const char *str);
+
+/**
+ * Put the RGBA values that correspond to color_string in rgba_color.
+ *
+ * @param color_string a string specifying a color. It can be the name of
+ * a color (case insensitive match) or a [0x|#]RRGGBB[AA] sequence,
+ * possibly followed by "@" and a string representing the alpha
+ * component.
+ * The alpha component may be a string composed by "0x" followed by an
+ * hexadecimal number or a decimal number between 0.0 and 1.0, which
+ * represents the opacity value (0x00/0.0 means completely transparent,
+ * 0xff/1.0 completely opaque).
+ * If the alpha component is not specified then 0xff is assumed.
+ * The string "random" will result in a random color.
+ * @param slen length of the initial part of color_string containing the
+ * color. It can be set to -1 if color_string is a null terminated string
+ * containing nothing else than the color.
+ * @return >= 0 in case of success, a negative value in case of
+ * failure (for example if color_string cannot be parsed).
+ */
+int av_parse_color(uint8_t *rgba_color, const char *color_string, int slen,
+                   void *log_ctx);
+
+/**
+ * Get the name of a color from the internal table of hard-coded named
+ * colors.
+ *
+ * This function is meant to enumerate the color names recognized by
+ * av_parse_color().
+ *
+ * @param color_idx index of the requested color, starting from 0
+ * @param rgbp      if not NULL, will point to a 3-elements array with the color value in RGB
+ * @return the color name string or NULL if color_idx is not in the array
+ */
+const char *av_get_known_color_name(int color_idx, const uint8_t **rgb);
+
+/**
+ * Parse timestr and return in *time a corresponding number of
+ * microseconds.
+ *
+ * @param timeval puts here the number of microseconds corresponding
+ * to the string in timestr. If the string represents a duration, it
+ * is the number of microseconds contained in the time interval.  If
+ * the string is a date, is the number of microseconds since 1st of
+ * January, 1970 up to the time of the parsed date.  If timestr cannot
+ * be successfully parsed, set *time to INT64_MIN.
+
+ * @param timestr a string representing a date or a duration.
+ * - If a date the syntax is:
+ * @code
+ * [{YYYY-MM-DD|YYYYMMDD}[T|t| ]]{{HH:MM:SS[.m...]]]}|{HHMMSS[.m...]]]}}[Z]
+ * now
+ * @endcode
+ * If the value is "now" it takes the current time.
+ * Time is local time unless Z is appended, in which case it is
+ * interpreted as UTC.
+ * If the year-month-day part is not specified it takes the current
+ * year-month-day.
+ * - If a duration the syntax is:
+ * @code
+ * [-][HH:]MM:SS[.m...]
+ * [-]S+[.m...]
+ * @endcode
+ * @param duration flag which tells how to interpret timestr, if not
+ * zero timestr is interpreted as a duration, otherwise as a date
+ * @return >= 0 in case of success, a negative value corresponding to an
+ * AVERROR code otherwise
+ */
+int av_parse_time(int64_t *timeval, const char *timestr, int duration);
+
+/**
+ * Parse the input string p according to the format string fmt and
+ * store its results in the structure dt.
+ * This implementation supports only a subset of the formats supported
+ * by the standard strptime().
+ *
+ * In particular it actually supports the parameters:
+ * - %H: the hour as a decimal number, using a 24-hour clock, in the
+ * range '00' through '23'
+ * - %J: hours as a decimal number, in the range '0' through INT_MAX
+ * - %M: the minute as a decimal number, using a 24-hour clock, in the
+ * range '00' through '59'
+ * - %S: the second as a decimal number, using a 24-hour clock, in the
+ * range '00' through '59'
+ * - %Y: the year as a decimal number, using the Gregorian calendar
+ * - %m: the month as a decimal number, in the range '1' through '12'
+ * - %d: the day of the month as a decimal number, in the range '1'
+ * through '31'
+ * - %%: a literal '%'
+ *
+ * @return a pointer to the first character not processed in this
+ * function call, or NULL in case the function fails to match all of
+ * the fmt string and therefore an error occurred
+ */
+char *av_small_strptime(const char *p, const char *fmt, struct tm *dt);
+
+/**
+ * Attempt to find a specific tag in a URL.
+ *
+ * syntax: '?tag1=val1&tag2=val2...'. Little URL decoding is done.
+ * Return 1 if found.
+ */
+int av_find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
+
+/**
+ * Convert the decomposed UTC time in tm to a time_t value.
+ */
+time_t av_timegm(struct tm *tm);
+
+#endif /* AVUTIL_PARSEUTILS_H */

+ 291 - 0
wave420l/code/ffmpeg/include/libavutil/pixdesc.h

@@ -0,0 +1,291 @@
+/*
+ * pixel format descriptor
+ * Copyright (c) 2009 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_PIXDESC_H
+#define AVUTIL_PIXDESC_H
+
+#include <inttypes.h>
+
+#include "attributes.h"
+#include "pixfmt.h"
+
+typedef struct AVComponentDescriptor{
+    uint16_t plane        :2;            ///< which of the 4 planes contains the component
+
+    /**
+     * Number of elements between 2 horizontally consecutive pixels minus 1.
+     * Elements are bits for bitstream formats, bytes otherwise.
+     */
+    uint16_t step_minus1  :3;
+
+    /**
+     * Number of elements before the component of the first pixel plus 1.
+     * Elements are bits for bitstream formats, bytes otherwise.
+     */
+    uint16_t offset_plus1 :3;
+    uint16_t shift        :3;            ///< number of least significant bits that must be shifted away to get the value
+    uint16_t depth_minus1 :4;            ///< number of bits in the component minus 1
+}AVComponentDescriptor;
+
+/**
+ * Descriptor that unambiguously describes how the bits of a pixel are
+ * stored in the up to 4 data planes of an image. It also stores the
+ * subsampling factors and number of components.
+ *
+ * @note This is separate of the colorspace (RGB, YCbCr, YPbPr, JPEG-style YUV
+ *       and all the YUV variants) AVPixFmtDescriptor just stores how values
+ *       are stored not what these values represent.
+ */
+typedef struct AVPixFmtDescriptor{
+    const char *name;
+    uint8_t nb_components;      ///< The number of components each pixel has, (1-4)
+
+    /**
+     * Amount to shift the luma width right to find the chroma width.
+     * For YV12 this is 1 for example.
+     * chroma_width = -((-luma_width) >> log2_chroma_w)
+     * The note above is needed to ensure rounding up.
+     * This value only refers to the chroma components.
+     */
+    uint8_t log2_chroma_w;      ///< chroma_width = -((-luma_width )>>log2_chroma_w)
+
+    /**
+     * Amount to shift the luma height right to find the chroma height.
+     * For YV12 this is 1 for example.
+     * chroma_height= -((-luma_height) >> log2_chroma_h)
+     * The note above is needed to ensure rounding up.
+     * This value only refers to the chroma components.
+     */
+    uint8_t log2_chroma_h;
+    uint8_t flags;
+
+    /**
+     * Parameters that describe how pixels are packed.
+     * If the format has 2 or 4 components, then alpha is last.
+     * If the format has 1 or 2 components, then luma is 0.
+     * If the format has 3 or 4 components,
+     * if the RGB flag is set then 0 is red, 1 is green and 2 is blue;
+     * otherwise 0 is luma, 1 is chroma-U and 2 is chroma-V.
+     */
+    AVComponentDescriptor comp[4];
+}AVPixFmtDescriptor;
+
+/**
+ * Pixel format is big-endian.
+ */
+#define AV_PIX_FMT_FLAG_BE           (1 << 0)
+/**
+ * Pixel format has a palette in data[1], values are indexes in this palette.
+ */
+#define AV_PIX_FMT_FLAG_PAL          (1 << 1)
+/**
+ * All values of a component are bit-wise packed end to end.
+ */
+#define AV_PIX_FMT_FLAG_BITSTREAM    (1 << 2)
+/**
+ * Pixel format is an HW accelerated format.
+ */
+#define AV_PIX_FMT_FLAG_HWACCEL      (1 << 3)
+/**
+ * At least one pixel component is not in the first data plane.
+ */
+#define AV_PIX_FMT_FLAG_PLANAR       (1 << 4)
+/**
+ * The pixel format contains RGB-like data (as opposed to YUV/grayscale).
+ */
+#define AV_PIX_FMT_FLAG_RGB          (1 << 5)
+/**
+ * The pixel format is "pseudo-paletted". This means that FFmpeg treats it as
+ * paletted internally, but the palette is generated by the decoder and is not
+ * stored in the file.
+ */
+#define AV_PIX_FMT_FLAG_PSEUDOPAL    (1 << 6)
+/**
+ * The pixel format has an alpha channel.
+ */
+#define AV_PIX_FMT_FLAG_ALPHA        (1 << 7)
+
+#if FF_API_PIX_FMT
+/**
+ * @deprecated use the AV_PIX_FMT_FLAG_* flags
+ */
+#define PIX_FMT_BE        AV_PIX_FMT_FLAG_BE
+#define PIX_FMT_PAL       AV_PIX_FMT_FLAG_PAL
+#define PIX_FMT_BITSTREAM AV_PIX_FMT_FLAG_BITSTREAM
+#define PIX_FMT_HWACCEL   AV_PIX_FMT_FLAG_HWACCEL
+#define PIX_FMT_PLANAR    AV_PIX_FMT_FLAG_PLANAR
+#define PIX_FMT_RGB       AV_PIX_FMT_FLAG_RGB
+#define PIX_FMT_PSEUDOPAL AV_PIX_FMT_FLAG_PSEUDOPAL
+#define PIX_FMT_ALPHA     AV_PIX_FMT_FLAG_ALPHA
+#endif
+
+#if FF_API_PIX_FMT_DESC
+/**
+ * The array of all the pixel format descriptors.
+ */
+extern attribute_deprecated const AVPixFmtDescriptor av_pix_fmt_descriptors[];
+#endif
+
+/**
+ * Read a line from an image, and write the values of the
+ * pixel format component c to dst.
+ *
+ * @param data the array containing the pointers to the planes of the image
+ * @param linesize the array containing the linesizes of the image
+ * @param desc the pixel format descriptor for the image
+ * @param x the horizontal coordinate of the first pixel to read
+ * @param y the vertical coordinate of the first pixel to read
+ * @param w the width of the line to read, that is the number of
+ * values to write to dst
+ * @param read_pal_component if not zero and the format is a paletted
+ * format writes the values corresponding to the palette
+ * component c in data[1] to dst, rather than the palette indexes in
+ * data[0]. The behavior is undefined if the format is not paletted.
+ */
+void av_read_image_line(uint16_t *dst, const uint8_t *data[4], const int linesize[4],
+                        const AVPixFmtDescriptor *desc, int x, int y, int c, int w, int read_pal_component);
+
+/**
+ * Write the values from src to the pixel format component c of an
+ * image line.
+ *
+ * @param src array containing the values to write
+ * @param data the array containing the pointers to the planes of the
+ * image to write into. It is supposed to be zeroed.
+ * @param linesize the array containing the linesizes of the image
+ * @param desc the pixel format descriptor for the image
+ * @param x the horizontal coordinate of the first pixel to write
+ * @param y the vertical coordinate of the first pixel to write
+ * @param w the width of the line to write, that is the number of
+ * values to write to the image line
+ */
+void av_write_image_line(const uint16_t *src, uint8_t *data[4], const int linesize[4],
+                         const AVPixFmtDescriptor *desc, int x, int y, int c, int w);
+
+/**
+ * Return the pixel format corresponding to name.
+ *
+ * If there is no pixel format with name name, then looks for a
+ * pixel format with the name corresponding to the native endian
+ * format of name.
+ * For example in a little-endian system, first looks for "gray16",
+ * then for "gray16le".
+ *
+ * Finally if no pixel format has been found, returns AV_PIX_FMT_NONE.
+ */
+enum AVPixelFormat av_get_pix_fmt(const char *name);
+
+/**
+ * Return the short name for a pixel format, NULL in case pix_fmt is
+ * unknown.
+ *
+ * @see av_get_pix_fmt(), av_get_pix_fmt_string()
+ */
+const char *av_get_pix_fmt_name(enum AVPixelFormat pix_fmt);
+
+/**
+ * Print in buf the string corresponding to the pixel format with
+ * number pix_fmt, or a header if pix_fmt is negative.
+ *
+ * @param buf the buffer where to write the string
+ * @param buf_size the size of buf
+ * @param pix_fmt the number of the pixel format to print the
+ * corresponding info string, or a negative value to print the
+ * corresponding header.
+ */
+char *av_get_pix_fmt_string (char *buf, int buf_size, enum AVPixelFormat pix_fmt);
+
+/**
+ * Return the number of bits per pixel used by the pixel format
+ * described by pixdesc. Note that this is not the same as the number
+ * of bits per sample.
+ *
+ * The returned number of bits refers to the number of bits actually
+ * used for storing the pixel information, that is padding bits are
+ * not counted.
+ */
+int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc);
+
+/**
+ * Return the number of bits per pixel for the pixel format
+ * described by pixdesc, including any padding or unused bits.
+ */
+int av_get_padded_bits_per_pixel(const AVPixFmtDescriptor *pixdesc);
+
+/**
+ * @return a pixel format descriptor for provided pixel format or NULL if
+ * this pixel format is unknown.
+ */
+const AVPixFmtDescriptor *av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt);
+
+/**
+ * Iterate over all pixel format descriptors known to libavutil.
+ *
+ * @param prev previous descriptor. NULL to get the first descriptor.
+ *
+ * @return next descriptor or NULL after the last descriptor
+ */
+const AVPixFmtDescriptor *av_pix_fmt_desc_next(const AVPixFmtDescriptor *prev);
+
+/**
+ * @return an AVPixelFormat id described by desc, or AV_PIX_FMT_NONE if desc
+ * is not a valid pointer to a pixel format descriptor.
+ */
+enum AVPixelFormat av_pix_fmt_desc_get_id(const AVPixFmtDescriptor *desc);
+
+/**
+ * Utility function to access log2_chroma_w log2_chroma_h from
+ * the pixel format AVPixFmtDescriptor.
+ *
+ * See avcodec_get_chroma_sub_sample() for a function that asserts a
+ * valid pixel format instead of returning an error code.
+ * Its recommanded that you use avcodec_get_chroma_sub_sample unless
+ * you do check the return code!
+ *
+ * @param[in]  pix_fmt the pixel format
+ * @param[out] h_shift store log2_chroma_w
+ * @param[out] v_shift store log2_chroma_h
+ *
+ * @return 0 on success, AVERROR(ENOSYS) on invalid or unknown pixel format
+ */
+int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt,
+                                     int *h_shift, int *v_shift);
+
+/**
+ * @return number of planes in pix_fmt, a negative AVERROR if pix_fmt is not a
+ * valid pixel format.
+ */
+int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt);
+
+void ff_check_pixfmt_descriptors(void);
+
+/**
+ * Utility function to swap the endianness of a pixel format.
+ *
+ * @param[in]  pix_fmt the pixel format
+ *
+ * @return pixel format with swapped endianness if it exists,
+ * otherwise AV_PIX_FMT_NONE
+ */
+enum AVPixelFormat av_pix_fmt_swap_endianness(enum AVPixelFormat pix_fmt);
+
+
+#endif /* AVUTIL_PIXDESC_H */

+ 397 - 0
wave420l/code/ffmpeg/include/libavutil/pixfmt.h

@@ -0,0 +1,397 @@
+/*
+ * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_PIXFMT_H
+#define AVUTIL_PIXFMT_H
+
+/**
+ * @file
+ * pixel format definitions
+ *
+ */
+
+#include "libavutil/avconfig.h"
+#include "version.h"
+
+#define AVPALETTE_SIZE 1024
+#define AVPALETTE_COUNT 256
+
+/**
+ * Pixel format.
+ *
+ * @note
+ * AV_PIX_FMT_RGB32 is handled in an endian-specific manner. An RGBA
+ * color is put together as:
+ *  (A << 24) | (R << 16) | (G << 8) | B
+ * This is stored as BGRA on little-endian CPU architectures and ARGB on
+ * big-endian CPUs.
+ *
+ * @par
+ * When the pixel format is palettized RGB (AV_PIX_FMT_PAL8), the palettized
+ * image data is stored in AVFrame.data[0]. The palette is transported in
+ * AVFrame.data[1], is 1024 bytes long (256 4-byte entries) and is
+ * formatted the same as in AV_PIX_FMT_RGB32 described above (i.e., it is
+ * also endian-specific). Note also that the individual RGB palette
+ * components stored in AVFrame.data[1] should be in the range 0..255.
+ * This is important as many custom PAL8 video codecs that were designed
+ * to run on the IBM VGA graphics adapter use 6-bit palette components.
+ *
+ * @par
+ * For all the 8bit per pixel formats, an RGB32 palette is in data[1] like
+ * for pal8. This palette is filled in automatically by the function
+ * allocating the picture.
+ *
+ * @note
+ * Make sure that all newly added big-endian formats have (pix_fmt & 1) == 1
+ * and that all newly added little-endian formats have (pix_fmt & 1) == 0.
+ * This allows simpler detection of big vs little-endian.
+ */
+enum AVPixelFormat {
+    AV_PIX_FMT_NONE = -1,
+    AV_PIX_FMT_YUV420P,   ///< planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
+    AV_PIX_FMT_YUYV422,   ///< packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
+    AV_PIX_FMT_RGB24,     ///< packed RGB 8:8:8, 24bpp, RGBRGB...
+    AV_PIX_FMT_BGR24,     ///< packed RGB 8:8:8, 24bpp, BGRBGR...
+    AV_PIX_FMT_YUV422P,   ///< planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
+    AV_PIX_FMT_YUV444P,   ///< planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
+    AV_PIX_FMT_YUV410P,   ///< planar YUV 4:1:0,  9bpp, (1 Cr & Cb sample per 4x4 Y samples)
+    AV_PIX_FMT_YUV411P,   ///< planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
+    AV_PIX_FMT_GRAY8,     ///<        Y        ,  8bpp
+    AV_PIX_FMT_MONOWHITE, ///<        Y        ,  1bpp, 0 is white, 1 is black, in each byte pixels are ordered from the msb to the lsb
+    AV_PIX_FMT_MONOBLACK, ///<        Y        ,  1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb
+    AV_PIX_FMT_PAL8,      ///< 8 bit with PIX_FMT_RGB32 palette
+    AV_PIX_FMT_YUVJ420P,  ///< planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV420P and setting color_range
+    AV_PIX_FMT_YUVJ422P,  ///< planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV422P and setting color_range
+    AV_PIX_FMT_YUVJ444P,  ///< planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV444P and setting color_range
+    AV_PIX_FMT_XVMC_MPEG2_MC,///< XVideo Motion Acceleration via common packet passing
+    AV_PIX_FMT_XVMC_MPEG2_IDCT,
+    AV_PIX_FMT_UYVY422,   ///< packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
+    AV_PIX_FMT_UYYVYY411, ///< packed YUV 4:1:1, 12bpp, Cb Y0 Y1 Cr Y2 Y3
+    AV_PIX_FMT_BGR8,      ///< packed RGB 3:3:2,  8bpp, (msb)2B 3G 3R(lsb)
+    AV_PIX_FMT_BGR4,      ///< packed RGB 1:2:1 bitstream,  4bpp, (msb)1B 2G 1R(lsb), a byte contains two pixels, the first pixel in the byte is the one composed by the 4 msb bits
+    AV_PIX_FMT_BGR4_BYTE, ///< packed RGB 1:2:1,  8bpp, (msb)1B 2G 1R(lsb)
+    AV_PIX_FMT_RGB8,      ///< packed RGB 3:3:2,  8bpp, (msb)2R 3G 3B(lsb)
+    AV_PIX_FMT_RGB4,      ///< packed RGB 1:2:1 bitstream,  4bpp, (msb)1R 2G 1B(lsb), a byte contains two pixels, the first pixel in the byte is the one composed by the 4 msb bits
+    AV_PIX_FMT_RGB4_BYTE, ///< packed RGB 1:2:1,  8bpp, (msb)1R 2G 1B(lsb)
+    AV_PIX_FMT_NV12,      ///< planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (first byte U and the following byte V)
+    AV_PIX_FMT_NV21,      ///< as above, but U and V bytes are swapped
+
+    AV_PIX_FMT_ARGB,      ///< packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
+    AV_PIX_FMT_RGBA,      ///< packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
+    AV_PIX_FMT_ABGR,      ///< packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
+    AV_PIX_FMT_BGRA,      ///< packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
+
+    AV_PIX_FMT_GRAY16BE,  ///<        Y        , 16bpp, big-endian
+    AV_PIX_FMT_GRAY16LE,  ///<        Y        , 16bpp, little-endian
+    AV_PIX_FMT_YUV440P,   ///< planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
+    AV_PIX_FMT_YUVJ440P,  ///< planar YUV 4:4:0 full scale (JPEG), deprecated in favor of PIX_FMT_YUV440P and setting color_range
+    AV_PIX_FMT_YUVA420P,  ///< planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
+#if FF_API_VDPAU
+    AV_PIX_FMT_VDPAU_H264,///< H.264 HW decoding with VDPAU, data[0] contains a vdpau_render_state struct which contains the bitstream of the slices as well as various fields extracted from headers
+    AV_PIX_FMT_VDPAU_MPEG1,///< MPEG-1 HW decoding with VDPAU, data[0] contains a vdpau_render_state struct which contains the bitstream of the slices as well as various fields extracted from headers
+    AV_PIX_FMT_VDPAU_MPEG2,///< MPEG-2 HW decoding with VDPAU, data[0] contains a vdpau_render_state struct which contains the bitstream of the slices as well as various fields extracted from headers
+    AV_PIX_FMT_VDPAU_WMV3,///< WMV3 HW decoding with VDPAU, data[0] contains a vdpau_render_state struct which contains the bitstream of the slices as well as various fields extracted from headers
+    AV_PIX_FMT_VDPAU_VC1, ///< VC-1 HW decoding with VDPAU, data[0] contains a vdpau_render_state struct which contains the bitstream of the slices as well as various fields extracted from headers
+#endif
+    AV_PIX_FMT_RGB48BE,   ///< packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as big-endian
+    AV_PIX_FMT_RGB48LE,   ///< packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as little-endian
+
+    AV_PIX_FMT_RGB565BE,  ///< packed RGB 5:6:5, 16bpp, (msb)   5R 6G 5B(lsb), big-endian
+    AV_PIX_FMT_RGB565LE,  ///< packed RGB 5:6:5, 16bpp, (msb)   5R 6G 5B(lsb), little-endian
+    AV_PIX_FMT_RGB555BE,  ///< packed RGB 5:5:5, 16bpp, (msb)1A 5R 5G 5B(lsb), big-endian, most significant bit to 0
+    AV_PIX_FMT_RGB555LE,  ///< packed RGB 5:5:5, 16bpp, (msb)1A 5R 5G 5B(lsb), little-endian, most significant bit to 0
+
+    AV_PIX_FMT_BGR565BE,  ///< packed BGR 5:6:5, 16bpp, (msb)   5B 6G 5R(lsb), big-endian
+    AV_PIX_FMT_BGR565LE,  ///< packed BGR 5:6:5, 16bpp, (msb)   5B 6G 5R(lsb), little-endian
+    AV_PIX_FMT_BGR555BE,  ///< packed BGR 5:5:5, 16bpp, (msb)1A 5B 5G 5R(lsb), big-endian, most significant bit to 1
+    AV_PIX_FMT_BGR555LE,  ///< packed BGR 5:5:5, 16bpp, (msb)1A 5B 5G 5R(lsb), little-endian, most significant bit to 1
+
+    AV_PIX_FMT_VAAPI_MOCO, ///< HW acceleration through VA API at motion compensation entry-point, Picture.data[3] contains a vaapi_render_state struct which contains macroblocks as well as various fields extracted from headers
+    AV_PIX_FMT_VAAPI_IDCT, ///< HW acceleration through VA API at IDCT entry-point, Picture.data[3] contains a vaapi_render_state struct which contains fields extracted from headers
+    AV_PIX_FMT_VAAPI_VLD,  ///< HW decoding through VA API, Picture.data[3] contains a vaapi_render_state struct which contains the bitstream of the slices as well as various fields extracted from headers
+
+    AV_PIX_FMT_YUV420P16LE,  ///< planar YUV 4:2:0, 24bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
+    AV_PIX_FMT_YUV420P16BE,  ///< planar YUV 4:2:0, 24bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
+    AV_PIX_FMT_YUV422P16LE,  ///< planar YUV 4:2:2, 32bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
+    AV_PIX_FMT_YUV422P16BE,  ///< planar YUV 4:2:2, 32bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
+    AV_PIX_FMT_YUV444P16LE,  ///< planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
+    AV_PIX_FMT_YUV444P16BE,  ///< planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
+#if FF_API_VDPAU
+    AV_PIX_FMT_VDPAU_MPEG4,  ///< MPEG4 HW decoding with VDPAU, data[0] contains a vdpau_render_state struct which contains the bitstream of the slices as well as various fields extracted from headers
+#endif
+    AV_PIX_FMT_DXVA2_VLD,    ///< HW decoding through DXVA2, Picture.data[3] contains a LPDIRECT3DSURFACE9 pointer
+
+    AV_PIX_FMT_RGB444LE,  ///< packed RGB 4:4:4, 16bpp, (msb)4A 4R 4G 4B(lsb), little-endian, most significant bits to 0
+    AV_PIX_FMT_RGB444BE,  ///< packed RGB 4:4:4, 16bpp, (msb)4A 4R 4G 4B(lsb), big-endian, most significant bits to 0
+    AV_PIX_FMT_BGR444LE,  ///< packed BGR 4:4:4, 16bpp, (msb)4A 4B 4G 4R(lsb), little-endian, most significant bits to 1
+    AV_PIX_FMT_BGR444BE,  ///< packed BGR 4:4:4, 16bpp, (msb)4A 4B 4G 4R(lsb), big-endian, most significant bits to 1
+    AV_PIX_FMT_GRAY8A,    ///< 8bit gray, 8bit alpha
+    AV_PIX_FMT_BGR48BE,   ///< packed RGB 16:16:16, 48bpp, 16B, 16G, 16R, the 2-byte value for each R/G/B component is stored as big-endian
+    AV_PIX_FMT_BGR48LE,   ///< packed RGB 16:16:16, 48bpp, 16B, 16G, 16R, the 2-byte value for each R/G/B component is stored as little-endian
+
+    /**
+     * The following 12 formats have the disadvantage of needing 1 format for each bit depth.
+     * Notice that each 9/10 bits sample is stored in 16 bits with extra padding.
+     * If you want to support multiple bit depths, then using AV_PIX_FMT_YUV420P16* with the bpp stored separately is better.
+     */
+    AV_PIX_FMT_YUV420P9BE, ///< planar YUV 4:2:0, 13.5bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
+    AV_PIX_FMT_YUV420P9LE, ///< planar YUV 4:2:0, 13.5bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
+    AV_PIX_FMT_YUV420P10BE,///< planar YUV 4:2:0, 15bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
+    AV_PIX_FMT_YUV420P10LE,///< planar YUV 4:2:0, 15bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
+    AV_PIX_FMT_YUV422P10BE,///< planar YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
+    AV_PIX_FMT_YUV422P10LE,///< planar YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
+    AV_PIX_FMT_YUV444P9BE, ///< planar YUV 4:4:4, 27bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
+    AV_PIX_FMT_YUV444P9LE, ///< planar YUV 4:4:4, 27bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
+    AV_PIX_FMT_YUV444P10BE,///< planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
+    AV_PIX_FMT_YUV444P10LE,///< planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
+    AV_PIX_FMT_YUV422P9BE, ///< planar YUV 4:2:2, 18bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
+    AV_PIX_FMT_YUV422P9LE, ///< planar YUV 4:2:2, 18bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
+    AV_PIX_FMT_VDA_VLD,    ///< hardware decoding through VDA
+
+#ifdef AV_PIX_FMT_ABI_GIT_MASTER
+    AV_PIX_FMT_RGBA64BE,  ///< packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is stored as big-endian
+    AV_PIX_FMT_RGBA64LE,  ///< packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is stored as little-endian
+    AV_PIX_FMT_BGRA64BE,  ///< packed RGBA 16:16:16:16, 64bpp, 16B, 16G, 16R, 16A, the 2-byte value for each R/G/B/A component is stored as big-endian
+    AV_PIX_FMT_BGRA64LE,  ///< packed RGBA 16:16:16:16, 64bpp, 16B, 16G, 16R, 16A, the 2-byte value for each R/G/B/A component is stored as little-endian
+#endif
+    AV_PIX_FMT_GBRP,      ///< planar GBR 4:4:4 24bpp
+    AV_PIX_FMT_GBRP9BE,   ///< planar GBR 4:4:4 27bpp, big-endian
+    AV_PIX_FMT_GBRP9LE,   ///< planar GBR 4:4:4 27bpp, little-endian
+    AV_PIX_FMT_GBRP10BE,  ///< planar GBR 4:4:4 30bpp, big-endian
+    AV_PIX_FMT_GBRP10LE,  ///< planar GBR 4:4:4 30bpp, little-endian
+    AV_PIX_FMT_GBRP16BE,  ///< planar GBR 4:4:4 48bpp, big-endian
+    AV_PIX_FMT_GBRP16LE,  ///< planar GBR 4:4:4 48bpp, little-endian
+
+    /**
+     * duplicated pixel formats for compatibility with libav.
+     * FFmpeg supports these formats since May 8 2012 and Jan 28 2012 (commits f9ca1ac7 and 143a5c55)
+     * Libav added them Oct 12 2012 with incompatible values (commit 6d5600e85)
+     */
+    AV_PIX_FMT_YUVA422P_LIBAV,  ///< planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
+    AV_PIX_FMT_YUVA444P_LIBAV,  ///< planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
+
+    AV_PIX_FMT_YUVA420P9BE,  ///< planar YUV 4:2:0 22.5bpp, (1 Cr & Cb sample per 2x2 Y & A samples), big-endian
+    AV_PIX_FMT_YUVA420P9LE,  ///< planar YUV 4:2:0 22.5bpp, (1 Cr & Cb sample per 2x2 Y & A samples), little-endian
+    AV_PIX_FMT_YUVA422P9BE,  ///< planar YUV 4:2:2 27bpp, (1 Cr & Cb sample per 2x1 Y & A samples), big-endian
+    AV_PIX_FMT_YUVA422P9LE,  ///< planar YUV 4:2:2 27bpp, (1 Cr & Cb sample per 2x1 Y & A samples), little-endian
+    AV_PIX_FMT_YUVA444P9BE,  ///< planar YUV 4:4:4 36bpp, (1 Cr & Cb sample per 1x1 Y & A samples), big-endian
+    AV_PIX_FMT_YUVA444P9LE,  ///< planar YUV 4:4:4 36bpp, (1 Cr & Cb sample per 1x1 Y & A samples), little-endian
+    AV_PIX_FMT_YUVA420P10BE, ///< planar YUV 4:2:0 25bpp, (1 Cr & Cb sample per 2x2 Y & A samples, big-endian)
+    AV_PIX_FMT_YUVA420P10LE, ///< planar YUV 4:2:0 25bpp, (1 Cr & Cb sample per 2x2 Y & A samples, little-endian)
+    AV_PIX_FMT_YUVA422P10BE, ///< planar YUV 4:2:2 30bpp, (1 Cr & Cb sample per 2x1 Y & A samples, big-endian)
+    AV_PIX_FMT_YUVA422P10LE, ///< planar YUV 4:2:2 30bpp, (1 Cr & Cb sample per 2x1 Y & A samples, little-endian)
+    AV_PIX_FMT_YUVA444P10BE, ///< planar YUV 4:4:4 40bpp, (1 Cr & Cb sample per 1x1 Y & A samples, big-endian)
+    AV_PIX_FMT_YUVA444P10LE, ///< planar YUV 4:4:4 40bpp, (1 Cr & Cb sample per 1x1 Y & A samples, little-endian)
+    AV_PIX_FMT_YUVA420P16BE, ///< planar YUV 4:2:0 40bpp, (1 Cr & Cb sample per 2x2 Y & A samples, big-endian)
+    AV_PIX_FMT_YUVA420P16LE, ///< planar YUV 4:2:0 40bpp, (1 Cr & Cb sample per 2x2 Y & A samples, little-endian)
+    AV_PIX_FMT_YUVA422P16BE, ///< planar YUV 4:2:2 48bpp, (1 Cr & Cb sample per 2x1 Y & A samples, big-endian)
+    AV_PIX_FMT_YUVA422P16LE, ///< planar YUV 4:2:2 48bpp, (1 Cr & Cb sample per 2x1 Y & A samples, little-endian)
+    AV_PIX_FMT_YUVA444P16BE, ///< planar YUV 4:4:4 64bpp, (1 Cr & Cb sample per 1x1 Y & A samples, big-endian)
+    AV_PIX_FMT_YUVA444P16LE, ///< planar YUV 4:4:4 64bpp, (1 Cr & Cb sample per 1x1 Y & A samples, little-endian)
+
+    AV_PIX_FMT_VDPAU,     ///< HW acceleration through VDPAU, Picture.data[3] contains a VdpVideoSurface
+
+    AV_PIX_FMT_XYZ12LE,      ///< packed XYZ 4:4:4, 36 bpp, (msb) 12X, 12Y, 12Z (lsb), the 2-byte value for each X/Y/Z is stored as little-endian, the 4 lower bits are set to 0
+    AV_PIX_FMT_XYZ12BE,      ///< packed XYZ 4:4:4, 36 bpp, (msb) 12X, 12Y, 12Z (lsb), the 2-byte value for each X/Y/Z is stored as big-endian, the 4 lower bits are set to 0
+    AV_PIX_FMT_NV16,         ///< interleaved chroma YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
+    AV_PIX_FMT_NV20LE,       ///< interleaved chroma YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
+    AV_PIX_FMT_NV20BE,       ///< interleaved chroma YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
+
+#ifndef AV_PIX_FMT_ABI_GIT_MASTER
+    AV_PIX_FMT_RGBA64BE=0x123,  ///< packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is stored as big-endian
+    AV_PIX_FMT_RGBA64LE,  ///< packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is stored as little-endian
+    AV_PIX_FMT_BGRA64BE,  ///< packed RGBA 16:16:16:16, 64bpp, 16B, 16G, 16R, 16A, the 2-byte value for each R/G/B/A component is stored as big-endian
+    AV_PIX_FMT_BGRA64LE,  ///< packed RGBA 16:16:16:16, 64bpp, 16B, 16G, 16R, 16A, the 2-byte value for each R/G/B/A component is stored as little-endian
+#endif
+    AV_PIX_FMT_0RGB=0x123+4,      ///< packed RGB 8:8:8, 32bpp, 0RGB0RGB...
+    AV_PIX_FMT_RGB0,      ///< packed RGB 8:8:8, 32bpp, RGB0RGB0...
+    AV_PIX_FMT_0BGR,      ///< packed BGR 8:8:8, 32bpp, 0BGR0BGR...
+    AV_PIX_FMT_BGR0,      ///< packed BGR 8:8:8, 32bpp, BGR0BGR0...
+    AV_PIX_FMT_YUVA444P,  ///< planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
+    AV_PIX_FMT_YUVA422P,  ///< planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
+
+    AV_PIX_FMT_YUV420P12BE, ///< planar YUV 4:2:0,18bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
+    AV_PIX_FMT_YUV420P12LE, ///< planar YUV 4:2:0,18bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
+    AV_PIX_FMT_YUV420P14BE, ///< planar YUV 4:2:0,21bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
+    AV_PIX_FMT_YUV420P14LE, ///< planar YUV 4:2:0,21bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
+    AV_PIX_FMT_YUV422P12BE, ///< planar YUV 4:2:2,24bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
+    AV_PIX_FMT_YUV422P12LE, ///< planar YUV 4:2:2,24bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
+    AV_PIX_FMT_YUV422P14BE, ///< planar YUV 4:2:2,28bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
+    AV_PIX_FMT_YUV422P14LE, ///< planar YUV 4:2:2,28bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
+    AV_PIX_FMT_YUV444P12BE, ///< planar YUV 4:4:4,36bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
+    AV_PIX_FMT_YUV444P12LE, ///< planar YUV 4:4:4,36bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
+    AV_PIX_FMT_YUV444P14BE, ///< planar YUV 4:4:4,42bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
+    AV_PIX_FMT_YUV444P14LE, ///< planar YUV 4:4:4,42bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
+    AV_PIX_FMT_GBRP12BE,    ///< planar GBR 4:4:4 36bpp, big-endian
+    AV_PIX_FMT_GBRP12LE,    ///< planar GBR 4:4:4 36bpp, little-endian
+    AV_PIX_FMT_GBRP14BE,    ///< planar GBR 4:4:4 42bpp, big-endian
+    AV_PIX_FMT_GBRP14LE,    ///< planar GBR 4:4:4 42bpp, little-endian
+    AV_PIX_FMT_GBRAP,       ///< planar GBRA 4:4:4:4 32bpp
+    AV_PIX_FMT_GBRAP16BE,   ///< planar GBRA 4:4:4:4 64bpp, big-endian
+    AV_PIX_FMT_GBRAP16LE,   ///< planar GBRA 4:4:4:4 64bpp, little-endian
+    AV_PIX_FMT_YUVJ411P,    ///< planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor of PIX_FMT_YUV411P and setting color_range
+
+    AV_PIX_FMT_BAYER_BGGR8,    ///< bayer, BGBG..(odd line), GRGR..(even line), 8-bit samples */
+    AV_PIX_FMT_BAYER_RGGB8,    ///< bayer, RGRG..(odd line), GBGB..(even line), 8-bit samples */
+    AV_PIX_FMT_BAYER_GBRG8,    ///< bayer, GBGB..(odd line), RGRG..(even line), 8-bit samples */
+    AV_PIX_FMT_BAYER_GRBG8,    ///< bayer, GRGR..(odd line), BGBG..(even line), 8-bit samples */
+    AV_PIX_FMT_BAYER_BGGR16LE, ///< bayer, BGBG..(odd line), GRGR..(even line), 16-bit samples, little-endian */
+    AV_PIX_FMT_BAYER_BGGR16BE, ///< bayer, BGBG..(odd line), GRGR..(even line), 16-bit samples, big-endian */
+    AV_PIX_FMT_BAYER_RGGB16LE, ///< bayer, RGRG..(odd line), GBGB..(even line), 16-bit samples, little-endian */
+    AV_PIX_FMT_BAYER_RGGB16BE, ///< bayer, RGRG..(odd line), GBGB..(even line), 16-bit samples, big-endian */
+    AV_PIX_FMT_BAYER_GBRG16LE, ///< bayer, GBGB..(odd line), RGRG..(even line), 16-bit samples, little-endian */
+    AV_PIX_FMT_BAYER_GBRG16BE, ///< bayer, GBGB..(odd line), RGRG..(even line), 16-bit samples, big-endian */
+    AV_PIX_FMT_BAYER_GRBG16LE, ///< bayer, GRGR..(odd line), BGBG..(even line), 16-bit samples, little-endian */
+    AV_PIX_FMT_BAYER_GRBG16BE, ///< bayer, GRGR..(odd line), BGBG..(even line), 16-bit samples, big-endian */
+
+    AV_PIX_FMT_NB,        ///< number of pixel formats, DO NOT USE THIS if you want to link with shared libav* because the number of formats might differ between versions
+
+#if FF_API_PIX_FMT
+#include "old_pix_fmts.h"
+#endif
+};
+
+#if AV_HAVE_INCOMPATIBLE_LIBAV_ABI
+#define AV_PIX_FMT_YUVA422P AV_PIX_FMT_YUVA422P_LIBAV
+#define AV_PIX_FMT_YUVA444P AV_PIX_FMT_YUVA444P_LIBAV
+#endif
+
+
+#define AV_PIX_FMT_Y400A AV_PIX_FMT_GRAY8A
+#define AV_PIX_FMT_GBR24P AV_PIX_FMT_GBRP
+
+#if AV_HAVE_BIGENDIAN
+#   define AV_PIX_FMT_NE(be, le) AV_PIX_FMT_##be
+#else
+#   define AV_PIX_FMT_NE(be, le) AV_PIX_FMT_##le
+#endif
+
+#define AV_PIX_FMT_RGB32   AV_PIX_FMT_NE(ARGB, BGRA)
+#define AV_PIX_FMT_RGB32_1 AV_PIX_FMT_NE(RGBA, ABGR)
+#define AV_PIX_FMT_BGR32   AV_PIX_FMT_NE(ABGR, RGBA)
+#define AV_PIX_FMT_BGR32_1 AV_PIX_FMT_NE(BGRA, ARGB)
+#define AV_PIX_FMT_0RGB32  AV_PIX_FMT_NE(0RGB, BGR0)
+#define AV_PIX_FMT_0BGR32  AV_PIX_FMT_NE(0BGR, RGB0)
+
+#define AV_PIX_FMT_GRAY16 AV_PIX_FMT_NE(GRAY16BE, GRAY16LE)
+#define AV_PIX_FMT_RGB48  AV_PIX_FMT_NE(RGB48BE,  RGB48LE)
+#define AV_PIX_FMT_RGB565 AV_PIX_FMT_NE(RGB565BE, RGB565LE)
+#define AV_PIX_FMT_RGB555 AV_PIX_FMT_NE(RGB555BE, RGB555LE)
+#define AV_PIX_FMT_RGB444 AV_PIX_FMT_NE(RGB444BE, RGB444LE)
+#define AV_PIX_FMT_BGR48  AV_PIX_FMT_NE(BGR48BE,  BGR48LE)
+#define AV_PIX_FMT_BGR565 AV_PIX_FMT_NE(BGR565BE, BGR565LE)
+#define AV_PIX_FMT_BGR555 AV_PIX_FMT_NE(BGR555BE, BGR555LE)
+#define AV_PIX_FMT_BGR444 AV_PIX_FMT_NE(BGR444BE, BGR444LE)
+
+#define AV_PIX_FMT_YUV420P9  AV_PIX_FMT_NE(YUV420P9BE , YUV420P9LE)
+#define AV_PIX_FMT_YUV422P9  AV_PIX_FMT_NE(YUV422P9BE , YUV422P9LE)
+#define AV_PIX_FMT_YUV444P9  AV_PIX_FMT_NE(YUV444P9BE , YUV444P9LE)
+#define AV_PIX_FMT_YUV420P10 AV_PIX_FMT_NE(YUV420P10BE, YUV420P10LE)
+#define AV_PIX_FMT_YUV422P10 AV_PIX_FMT_NE(YUV422P10BE, YUV422P10LE)
+#define AV_PIX_FMT_YUV444P10 AV_PIX_FMT_NE(YUV444P10BE, YUV444P10LE)
+#define AV_PIX_FMT_YUV420P12 AV_PIX_FMT_NE(YUV420P12BE, YUV420P12LE)
+#define AV_PIX_FMT_YUV422P12 AV_PIX_FMT_NE(YUV422P12BE, YUV422P12LE)
+#define AV_PIX_FMT_YUV444P12 AV_PIX_FMT_NE(YUV444P12BE, YUV444P12LE)
+#define AV_PIX_FMT_YUV420P14 AV_PIX_FMT_NE(YUV420P14BE, YUV420P14LE)
+#define AV_PIX_FMT_YUV422P14 AV_PIX_FMT_NE(YUV422P14BE, YUV422P14LE)
+#define AV_PIX_FMT_YUV444P14 AV_PIX_FMT_NE(YUV444P14BE, YUV444P14LE)
+#define AV_PIX_FMT_YUV420P16 AV_PIX_FMT_NE(YUV420P16BE, YUV420P16LE)
+#define AV_PIX_FMT_YUV422P16 AV_PIX_FMT_NE(YUV422P16BE, YUV422P16LE)
+#define AV_PIX_FMT_YUV444P16 AV_PIX_FMT_NE(YUV444P16BE, YUV444P16LE)
+
+#define AV_PIX_FMT_RGBA64 AV_PIX_FMT_NE(RGBA64BE, RGBA64LE)
+#define AV_PIX_FMT_BGRA64 AV_PIX_FMT_NE(BGRA64BE, BGRA64LE)
+#define AV_PIX_FMT_GBRP9     AV_PIX_FMT_NE(GBRP9BE ,    GBRP9LE)
+#define AV_PIX_FMT_GBRP10    AV_PIX_FMT_NE(GBRP10BE,    GBRP10LE)
+#define AV_PIX_FMT_GBRP12    AV_PIX_FMT_NE(GBRP12BE,    GBRP12LE)
+#define AV_PIX_FMT_GBRP14    AV_PIX_FMT_NE(GBRP14BE,    GBRP14LE)
+#define AV_PIX_FMT_GBRP16    AV_PIX_FMT_NE(GBRP16BE,    GBRP16LE)
+#define AV_PIX_FMT_GBRAP16   AV_PIX_FMT_NE(GBRAP16BE,   GBRAP16LE)
+
+#define AV_PIX_FMT_BAYER_BGGR16 AV_PIX_FMT_NE(BAYER_BGGR16BE,    BAYER_BGGR16LE)
+#define AV_PIX_FMT_BAYER_RGGB16 AV_PIX_FMT_NE(BAYER_RGGB16BE,    BAYER_RGGB16LE)
+#define AV_PIX_FMT_BAYER_GBRG16 AV_PIX_FMT_NE(BAYER_GBRG16BE,    BAYER_GBRG16LE)
+#define AV_PIX_FMT_BAYER_GRBG16 AV_PIX_FMT_NE(BAYER_GRBG16BE,    BAYER_GRBG16LE)
+
+
+#define AV_PIX_FMT_YUVA420P9  AV_PIX_FMT_NE(YUVA420P9BE , YUVA420P9LE)
+#define AV_PIX_FMT_YUVA422P9  AV_PIX_FMT_NE(YUVA422P9BE , YUVA422P9LE)
+#define AV_PIX_FMT_YUVA444P9  AV_PIX_FMT_NE(YUVA444P9BE , YUVA444P9LE)
+#define AV_PIX_FMT_YUVA420P10 AV_PIX_FMT_NE(YUVA420P10BE, YUVA420P10LE)
+#define AV_PIX_FMT_YUVA422P10 AV_PIX_FMT_NE(YUVA422P10BE, YUVA422P10LE)
+#define AV_PIX_FMT_YUVA444P10 AV_PIX_FMT_NE(YUVA444P10BE, YUVA444P10LE)
+#define AV_PIX_FMT_YUVA420P16 AV_PIX_FMT_NE(YUVA420P16BE, YUVA420P16LE)
+#define AV_PIX_FMT_YUVA422P16 AV_PIX_FMT_NE(YUVA422P16BE, YUVA422P16LE)
+#define AV_PIX_FMT_YUVA444P16 AV_PIX_FMT_NE(YUVA444P16BE, YUVA444P16LE)
+
+#define AV_PIX_FMT_XYZ12      AV_PIX_FMT_NE(XYZ12BE, XYZ12LE)
+#define AV_PIX_FMT_NV20       AV_PIX_FMT_NE(NV20BE,  NV20LE)
+
+#if FF_API_PIX_FMT
+#define PixelFormat AVPixelFormat
+
+#define PIX_FMT_Y400A AV_PIX_FMT_Y400A
+#define PIX_FMT_GBR24P AV_PIX_FMT_GBR24P
+
+#define PIX_FMT_NE(be, le) AV_PIX_FMT_NE(be, le)
+
+#define PIX_FMT_RGB32   AV_PIX_FMT_RGB32
+#define PIX_FMT_RGB32_1 AV_PIX_FMT_RGB32_1
+#define PIX_FMT_BGR32   AV_PIX_FMT_BGR32
+#define PIX_FMT_BGR32_1 AV_PIX_FMT_BGR32_1
+#define PIX_FMT_0RGB32  AV_PIX_FMT_0RGB32
+#define PIX_FMT_0BGR32  AV_PIX_FMT_0BGR32
+
+#define PIX_FMT_GRAY16 AV_PIX_FMT_GRAY16
+#define PIX_FMT_RGB48  AV_PIX_FMT_RGB48
+#define PIX_FMT_RGB565 AV_PIX_FMT_RGB565
+#define PIX_FMT_RGB555 AV_PIX_FMT_RGB555
+#define PIX_FMT_RGB444 AV_PIX_FMT_RGB444
+#define PIX_FMT_BGR48  AV_PIX_FMT_BGR48
+#define PIX_FMT_BGR565 AV_PIX_FMT_BGR565
+#define PIX_FMT_BGR555 AV_PIX_FMT_BGR555
+#define PIX_FMT_BGR444 AV_PIX_FMT_BGR444
+
+#define PIX_FMT_YUV420P9  AV_PIX_FMT_YUV420P9
+#define PIX_FMT_YUV422P9  AV_PIX_FMT_YUV422P9
+#define PIX_FMT_YUV444P9  AV_PIX_FMT_YUV444P9
+#define PIX_FMT_YUV420P10 AV_PIX_FMT_YUV420P10
+#define PIX_FMT_YUV422P10 AV_PIX_FMT_YUV422P10
+#define PIX_FMT_YUV444P10 AV_PIX_FMT_YUV444P10
+#define PIX_FMT_YUV420P12 AV_PIX_FMT_YUV420P12
+#define PIX_FMT_YUV422P12 AV_PIX_FMT_YUV422P12
+#define PIX_FMT_YUV444P12 AV_PIX_FMT_YUV444P12
+#define PIX_FMT_YUV420P14 AV_PIX_FMT_YUV420P14
+#define PIX_FMT_YUV422P14 AV_PIX_FMT_YUV422P14
+#define PIX_FMT_YUV444P14 AV_PIX_FMT_YUV444P14
+#define PIX_FMT_YUV420P16 AV_PIX_FMT_YUV420P16
+#define PIX_FMT_YUV422P16 AV_PIX_FMT_YUV422P16
+#define PIX_FMT_YUV444P16 AV_PIX_FMT_YUV444P16
+
+#define PIX_FMT_RGBA64 AV_PIX_FMT_RGBA64
+#define PIX_FMT_BGRA64 AV_PIX_FMT_BGRA64
+#define PIX_FMT_GBRP9  AV_PIX_FMT_GBRP9
+#define PIX_FMT_GBRP10 AV_PIX_FMT_GBRP10
+#define PIX_FMT_GBRP12 AV_PIX_FMT_GBRP12
+#define PIX_FMT_GBRP14 AV_PIX_FMT_GBRP14
+#define PIX_FMT_GBRP16 AV_PIX_FMT_GBRP16
+#endif
+
+#endif /* AVUTIL_PIXFMT_H */

+ 43 - 0
wave420l/code/ffmpeg/include/libavutil/random_seed.h

@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2009 Baptiste Coudurier <baptiste.coudurier@gmail.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_RANDOM_SEED_H
+#define AVUTIL_RANDOM_SEED_H
+
+#include <stdint.h>
+/**
+ * @addtogroup lavu_crypto
+ * @{
+ */
+
+/**
+ * Get a seed to use in conjunction with random functions.
+ * This function tries to provide a good seed at a best effort bases.
+ * Its possible to call this function multiple times if more bits are needed.
+ * It can be quite slow, which is why it should only be used as seed for a faster
+ * PRNG. The quality of the seed depends on the platform.
+ */
+uint32_t av_get_random_seed(void);
+
+/**
+ * @}
+ */
+
+#endif /* AVUTIL_RANDOM_SEED_H */

+ 155 - 0
wave420l/code/ffmpeg/include/libavutil/rational.h

@@ -0,0 +1,155 @@
+/*
+ * rational numbers
+ * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * rational numbers
+ * @author Michael Niedermayer <michaelni@gmx.at>
+ */
+
+#ifndef AVUTIL_RATIONAL_H
+#define AVUTIL_RATIONAL_H
+
+#include <stdint.h>
+#include <limits.h>
+#include "attributes.h"
+
+/**
+ * @addtogroup lavu_math
+ * @{
+ */
+
+/**
+ * rational number numerator/denominator
+ */
+typedef struct AVRational{
+    int num; ///< numerator
+    int den; ///< denominator
+} AVRational;
+
+/**
+ * Compare two rationals.
+ * @param a first rational
+ * @param b second rational
+ * @return 0 if a==b, 1 if a>b, -1 if a<b, and INT_MIN if one of the
+ * values is of the form 0/0
+ */
+static inline int av_cmp_q(AVRational a, AVRational b){
+    const int64_t tmp= a.num * (int64_t)b.den - b.num * (int64_t)a.den;
+
+    if(tmp) return (int)((tmp ^ a.den ^ b.den)>>63)|1;
+    else if(b.den && a.den) return 0;
+    else if(a.num && b.num) return (a.num>>31) - (b.num>>31);
+    else                    return INT_MIN;
+}
+
+/**
+ * Convert rational to double.
+ * @param a rational to convert
+ * @return (double) a
+ */
+static inline double av_q2d(AVRational a){
+    return a.num / (double) a.den;
+}
+
+/**
+ * Reduce a fraction.
+ * This is useful for framerate calculations.
+ * @param dst_num destination numerator
+ * @param dst_den destination denominator
+ * @param num source numerator
+ * @param den source denominator
+ * @param max the maximum allowed for dst_num & dst_den
+ * @return 1 if exact, 0 otherwise
+ */
+int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max);
+
+/**
+ * Multiply two rationals.
+ * @param b first rational
+ * @param c second rational
+ * @return b*c
+ */
+AVRational av_mul_q(AVRational b, AVRational c) av_const;
+
+/**
+ * Divide one rational by another.
+ * @param b first rational
+ * @param c second rational
+ * @return b/c
+ */
+AVRational av_div_q(AVRational b, AVRational c) av_const;
+
+/**
+ * Add two rationals.
+ * @param b first rational
+ * @param c second rational
+ * @return b+c
+ */
+AVRational av_add_q(AVRational b, AVRational c) av_const;
+
+/**
+ * Subtract one rational from another.
+ * @param b first rational
+ * @param c second rational
+ * @return b-c
+ */
+AVRational av_sub_q(AVRational b, AVRational c) av_const;
+
+/**
+ * Invert a rational.
+ * @param q value
+ * @return 1 / q
+ */
+static av_always_inline AVRational av_inv_q(AVRational q)
+{
+    AVRational r = { q.den, q.num };
+    return r;
+}
+
+/**
+ * Convert a double precision floating point number to a rational.
+ * inf is expressed as {1,0} or {-1,0} depending on the sign.
+ *
+ * @param d double to convert
+ * @param max the maximum allowed numerator and denominator
+ * @return (AVRational) d
+ */
+AVRational av_d2q(double d, int max) av_const;
+
+/**
+ * @return 1 if q1 is nearer to q than q2, -1 if q2 is nearer
+ * than q1, 0 if they have the same distance.
+ */
+int av_nearer_q(AVRational q, AVRational q1, AVRational q2);
+
+/**
+ * Find the nearest value in q_list to q.
+ * @param q_list an array of rationals terminated by {0, 0}
+ * @return the index of the nearest value found in the array
+ */
+int av_find_nearest_q_idx(AVRational q, const AVRational* q_list);
+
+/**
+ * @}
+ */
+
+#endif /* AVUTIL_RATIONAL_H */

+ 75 - 0
wave420l/code/ffmpeg/include/libavutil/ripemd.h

@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2007 Michael Niedermayer <michaelni@gmx.at>
+ * Copyright (C) 2013 James Almer <jamrial@gmail.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_RIPEMD_H
+#define AVUTIL_RIPEMD_H
+
+#include <stdint.h>
+
+#include "attributes.h"
+#include "version.h"
+
+/**
+ * @defgroup lavu_ripemd RIPEMD
+ * @ingroup lavu_crypto
+ * @{
+ */
+
+extern const int av_ripemd_size;
+
+struct AVRIPEMD;
+
+/**
+ * Allocate an AVRIPEMD context.
+ */
+struct AVRIPEMD *av_ripemd_alloc(void);
+
+/**
+ * Initialize RIPEMD hashing.
+ *
+ * @param context pointer to the function context (of size av_ripemd_size)
+ * @param bits    number of bits in digest (128, 160, 256 or 320 bits)
+ * @return        zero if initialization succeeded, -1 otherwise
+ */
+int av_ripemd_init(struct AVRIPEMD* context, int bits);
+
+/**
+ * Update hash value.
+ *
+ * @param context hash function context
+ * @param data    input data to update hash with
+ * @param len     input data length
+ */
+void av_ripemd_update(struct AVRIPEMD* context, const uint8_t* data, unsigned int len);
+
+/**
+ * Finish hashing and output digest value.
+ *
+ * @param context hash function context
+ * @param digest  buffer where output digest value is stored
+ */
+void av_ripemd_final(struct AVRIPEMD* context, uint8_t *digest);
+
+/**
+ * @}
+ */
+
+#endif /* AVUTIL_RIPEMD_H */

+ 256 - 0
wave420l/code/ffmpeg/include/libavutil/samplefmt.h

@@ -0,0 +1,256 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_SAMPLEFMT_H
+#define AVUTIL_SAMPLEFMT_H
+
+#include <stdint.h>
+
+#include "avutil.h"
+#include "attributes.h"
+
+/**
+ * Audio Sample Formats
+ *
+ * @par
+ * The data described by the sample format is always in native-endian order.
+ * Sample values can be expressed by native C types, hence the lack of a signed
+ * 24-bit sample format even though it is a common raw audio data format.
+ *
+ * @par
+ * The floating-point formats are based on full volume being in the range
+ * [-1.0, 1.0]. Any values outside this range are beyond full volume level.
+ *
+ * @par
+ * The data layout as used in av_samples_fill_arrays() and elsewhere in FFmpeg
+ * (such as AVFrame in libavcodec) is as follows:
+ *
+ * For planar sample formats, each audio channel is in a separate data plane,
+ * and linesize is the buffer size, in bytes, for a single plane. All data
+ * planes must be the same size. For packed sample formats, only the first data
+ * plane is used, and samples for each channel are interleaved. In this case,
+ * linesize is the buffer size, in bytes, for the 1 plane.
+ */
+enum AVSampleFormat {
+    AV_SAMPLE_FMT_NONE = -1,
+    AV_SAMPLE_FMT_U8,          ///< unsigned 8 bits
+    AV_SAMPLE_FMT_S16,         ///< signed 16 bits
+    AV_SAMPLE_FMT_S32,         ///< signed 32 bits
+    AV_SAMPLE_FMT_FLT,         ///< float
+    AV_SAMPLE_FMT_DBL,         ///< double
+
+    AV_SAMPLE_FMT_U8P,         ///< unsigned 8 bits, planar
+    AV_SAMPLE_FMT_S16P,        ///< signed 16 bits, planar
+    AV_SAMPLE_FMT_S32P,        ///< signed 32 bits, planar
+    AV_SAMPLE_FMT_FLTP,        ///< float, planar
+    AV_SAMPLE_FMT_DBLP,        ///< double, planar
+
+    AV_SAMPLE_FMT_NB           ///< Number of sample formats. DO NOT USE if linking dynamically
+};
+
+/**
+ * Return the name of sample_fmt, or NULL if sample_fmt is not
+ * recognized.
+ */
+const char *av_get_sample_fmt_name(enum AVSampleFormat sample_fmt);
+
+/**
+ * Return a sample format corresponding to name, or AV_SAMPLE_FMT_NONE
+ * on error.
+ */
+enum AVSampleFormat av_get_sample_fmt(const char *name);
+
+/**
+ * Return the planar<->packed alternative form of the given sample format, or
+ * AV_SAMPLE_FMT_NONE on error. If the passed sample_fmt is already in the
+ * requested planar/packed format, the format returned is the same as the
+ * input.
+ */
+enum AVSampleFormat av_get_alt_sample_fmt(enum AVSampleFormat sample_fmt, int planar);
+
+/**
+ * Get the packed alternative form of the given sample format.
+ *
+ * If the passed sample_fmt is already in packed format, the format returned is
+ * the same as the input.
+ *
+ * @return  the packed alternative form of the given sample format or
+            AV_SAMPLE_FMT_NONE on error.
+ */
+enum AVSampleFormat av_get_packed_sample_fmt(enum AVSampleFormat sample_fmt);
+
+/**
+ * Get the planar alternative form of the given sample format.
+ *
+ * If the passed sample_fmt is already in planar format, the format returned is
+ * the same as the input.
+ *
+ * @return  the planar alternative form of the given sample format or
+            AV_SAMPLE_FMT_NONE on error.
+ */
+enum AVSampleFormat av_get_planar_sample_fmt(enum AVSampleFormat sample_fmt);
+
+/**
+ * Generate a string corresponding to the sample format with
+ * sample_fmt, or a header if sample_fmt is negative.
+ *
+ * @param buf the buffer where to write the string
+ * @param buf_size the size of buf
+ * @param sample_fmt the number of the sample format to print the
+ * corresponding info string, or a negative value to print the
+ * corresponding header.
+ * @return the pointer to the filled buffer or NULL if sample_fmt is
+ * unknown or in case of other errors
+ */
+char *av_get_sample_fmt_string(char *buf, int buf_size, enum AVSampleFormat sample_fmt);
+
+#if FF_API_GET_BITS_PER_SAMPLE_FMT
+/**
+ * @deprecated Use av_get_bytes_per_sample() instead.
+ */
+attribute_deprecated
+int av_get_bits_per_sample_fmt(enum AVSampleFormat sample_fmt);
+#endif
+
+/**
+ * Return number of bytes per sample.
+ *
+ * @param sample_fmt the sample format
+ * @return number of bytes per sample or zero if unknown for the given
+ * sample format
+ */
+int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt);
+
+/**
+ * Check if the sample format is planar.
+ *
+ * @param sample_fmt the sample format to inspect
+ * @return 1 if the sample format is planar, 0 if it is interleaved
+ */
+int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt);
+
+/**
+ * Get the required buffer size for the given audio parameters.
+ *
+ * @param[out] linesize calculated linesize, may be NULL
+ * @param nb_channels   the number of channels
+ * @param nb_samples    the number of samples in a single channel
+ * @param sample_fmt    the sample format
+ * @param align         buffer size alignment (0 = default, 1 = no alignment)
+ * @return              required buffer size, or negative error code on failure
+ */
+int av_samples_get_buffer_size(int *linesize, int nb_channels, int nb_samples,
+                               enum AVSampleFormat sample_fmt, int align);
+
+/**
+ * Fill plane data pointers and linesize for samples with sample
+ * format sample_fmt.
+ *
+ * The audio_data array is filled with the pointers to the samples data planes:
+ * for planar, set the start point of each channel's data within the buffer,
+ * for packed, set the start point of the entire buffer only.
+ *
+ * The value pointed to by linesize is set to the aligned size of each
+ * channel's data buffer for planar layout, or to the aligned size of the
+ * buffer for all channels for packed layout.
+ *
+ * The buffer in buf must be big enough to contain all the samples
+ * (use av_samples_get_buffer_size() to compute its minimum size),
+ * otherwise the audio_data pointers will point to invalid data.
+ *
+ * @see enum AVSampleFormat
+ * The documentation for AVSampleFormat describes the data layout.
+ *
+ * @param[out] audio_data  array to be filled with the pointer for each channel
+ * @param[out] linesize    calculated linesize, may be NULL
+ * @param buf              the pointer to a buffer containing the samples
+ * @param nb_channels      the number of channels
+ * @param nb_samples       the number of samples in a single channel
+ * @param sample_fmt       the sample format
+ * @param align            buffer size alignment (0 = default, 1 = no alignment)
+ * @return                 >=0 on success or a negative error code on failure
+ * @todo return minimum size in bytes required for the buffer in case
+ * of success at the next bump
+ */
+int av_samples_fill_arrays(uint8_t **audio_data, int *linesize,
+                           const uint8_t *buf,
+                           int nb_channels, int nb_samples,
+                           enum AVSampleFormat sample_fmt, int align);
+
+/**
+ * Allocate a samples buffer for nb_samples samples, and fill data pointers and
+ * linesize accordingly.
+ * The allocated samples buffer can be freed by using av_freep(&audio_data[0])
+ * Allocated data will be initialized to silence.
+ *
+ * @see enum AVSampleFormat
+ * The documentation for AVSampleFormat describes the data layout.
+ *
+ * @param[out] audio_data  array to be filled with the pointer for each channel
+ * @param[out] linesize    aligned size for audio buffer(s), may be NULL
+ * @param nb_channels      number of audio channels
+ * @param nb_samples       number of samples per channel
+ * @param align            buffer size alignment (0 = default, 1 = no alignment)
+ * @return                 >=0 on success or a negative error code on failure
+ * @todo return the size of the allocated buffer in case of success at the next bump
+ * @see av_samples_fill_arrays()
+ * @see av_samples_alloc_array_and_samples()
+ */
+int av_samples_alloc(uint8_t **audio_data, int *linesize, int nb_channels,
+                     int nb_samples, enum AVSampleFormat sample_fmt, int align);
+
+/**
+ * Allocate a data pointers array, samples buffer for nb_samples
+ * samples, and fill data pointers and linesize accordingly.
+ *
+ * This is the same as av_samples_alloc(), but also allocates the data
+ * pointers array.
+ *
+ * @see av_samples_alloc()
+ */
+int av_samples_alloc_array_and_samples(uint8_t ***audio_data, int *linesize, int nb_channels,
+                                       int nb_samples, enum AVSampleFormat sample_fmt, int align);
+
+/**
+ * Copy samples from src to dst.
+ *
+ * @param dst destination array of pointers to data planes
+ * @param src source array of pointers to data planes
+ * @param dst_offset offset in samples at which the data will be written to dst
+ * @param src_offset offset in samples at which the data will be read from src
+ * @param nb_samples number of samples to be copied
+ * @param nb_channels number of audio channels
+ * @param sample_fmt audio sample format
+ */
+int av_samples_copy(uint8_t **dst, uint8_t * const *src, int dst_offset,
+                    int src_offset, int nb_samples, int nb_channels,
+                    enum AVSampleFormat sample_fmt);
+
+/**
+ * Fill an audio buffer with silence.
+ *
+ * @param audio_data  array of pointers to data planes
+ * @param offset      offset in samples at which to start filling
+ * @param nb_samples  number of samples to fill
+ * @param nb_channels number of audio channels
+ * @param sample_fmt  audio sample format
+ */
+int av_samples_set_silence(uint8_t **audio_data, int offset, int nb_samples,
+                           int nb_channels, enum AVSampleFormat sample_fmt);
+
+#endif /* AVUTIL_SAMPLEFMT_H */

+ 74 - 0
wave420l/code/ffmpeg/include/libavutil/sha.h

@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2007 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_SHA_H
+#define AVUTIL_SHA_H
+
+#include <stdint.h>
+
+#include "attributes.h"
+#include "version.h"
+
+/**
+ * @defgroup lavu_sha SHA
+ * @ingroup lavu_crypto
+ * @{
+ */
+
+extern const int av_sha_size;
+
+struct AVSHA;
+
+/**
+ * Allocate an AVSHA context.
+ */
+struct AVSHA *av_sha_alloc(void);
+
+/**
+ * Initialize SHA-1 or SHA-2 hashing.
+ *
+ * @param context pointer to the function context (of size av_sha_size)
+ * @param bits    number of bits in digest (SHA-1 - 160 bits, SHA-2 224 or 256 bits)
+ * @return        zero if initialization succeeded, -1 otherwise
+ */
+int av_sha_init(struct AVSHA* context, int bits);
+
+/**
+ * Update hash value.
+ *
+ * @param context hash function context
+ * @param data    input data to update hash with
+ * @param len     input data length
+ */
+void av_sha_update(struct AVSHA* context, const uint8_t* data, unsigned int len);
+
+/**
+ * Finish hashing and output digest value.
+ *
+ * @param context hash function context
+ * @param digest  buffer where output digest value is stored
+ */
+void av_sha_final(struct AVSHA* context, uint8_t *digest);
+
+/**
+ * @}
+ */
+
+#endif /* AVUTIL_SHA_H */

+ 75 - 0
wave420l/code/ffmpeg/include/libavutil/sha512.h

@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2007 Michael Niedermayer <michaelni@gmx.at>
+ * Copyright (C) 2013 James Almer <jamrial@gmail.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_SHA512_H
+#define AVUTIL_SHA512_H
+
+#include <stdint.h>
+
+#include "attributes.h"
+#include "version.h"
+
+/**
+ * @defgroup lavu_sha512 SHA512
+ * @ingroup lavu_crypto
+ * @{
+ */
+
+extern const int av_sha512_size;
+
+struct AVSHA512;
+
+/**
+ * Allocate an AVSHA512 context.
+ */
+struct AVSHA512 *av_sha512_alloc(void);
+
+/**
+ * Initialize SHA-2 512 hashing.
+ *
+ * @param context pointer to the function context (of size av_sha512_size)
+ * @param bits    number of bits in digest (224, 256, 384 or 512 bits)
+ * @return        zero if initialization succeeded, -1 otherwise
+ */
+int av_sha512_init(struct AVSHA512* context, int bits);
+
+/**
+ * Update hash value.
+ *
+ * @param context hash function context
+ * @param data    input data to update hash with
+ * @param len     input data length
+ */
+void av_sha512_update(struct AVSHA512* context, const uint8_t* data, unsigned int len);
+
+/**
+ * Finish hashing and output digest value.
+ *
+ * @param context hash function context
+ * @param digest  buffer where output digest value is stored
+ */
+void av_sha512_final(struct AVSHA512* context, uint8_t *digest);
+
+/**
+ * @}
+ */
+
+#endif /* AVUTIL_SHA512_H */

+ 41 - 0
wave420l/code/ffmpeg/include/libavutil/time.h

@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2000-2003 Fabrice Bellard
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_TIME_H
+#define AVUTIL_TIME_H
+
+#include <stdint.h>
+
+/**
+ * Get the current time in microseconds.
+ */
+int64_t av_gettime(void);
+
+/**
+ * Sleep for a period of time.  Although the duration is expressed in
+ * microseconds, the actual delay may be rounded to the precision of the
+ * system timer.
+ *
+ * @param  usec Number of microseconds to sleep.
+ * @return zero on success or (negative) error code.
+ */
+int av_usleep(unsigned usec);
+
+#endif /* AVUTIL_TIME_H */

+ 140 - 0
wave420l/code/ffmpeg/include/libavutil/timecode.h

@@ -0,0 +1,140 @@
+/*
+ * Copyright (c) 2006 Smartjog S.A.S, Baptiste Coudurier <baptiste.coudurier@gmail.com>
+ * Copyright (c) 2011-2012 Smartjog S.A.S, Clément Bœsch <clement.boesch@smartjog.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * Timecode helpers header
+ */
+
+#ifndef AVUTIL_TIMECODE_H
+#define AVUTIL_TIMECODE_H
+
+#include <stdint.h>
+#include "rational.h"
+
+#define AV_TIMECODE_STR_SIZE 16
+
+enum AVTimecodeFlag {
+    AV_TIMECODE_FLAG_DROPFRAME      = 1<<0, ///< timecode is drop frame
+    AV_TIMECODE_FLAG_24HOURSMAX     = 1<<1, ///< timecode wraps after 24 hours
+    AV_TIMECODE_FLAG_ALLOWNEGATIVE  = 1<<2, ///< negative time values are allowed
+};
+
+typedef struct {
+    int start;          ///< timecode frame start (first base frame number)
+    uint32_t flags;     ///< flags such as drop frame, +24 hours support, ...
+    AVRational rate;    ///< frame rate in rational form
+    unsigned fps;       ///< frame per second; must be consistent with the rate field
+} AVTimecode;
+
+/**
+ * Adjust frame number for NTSC drop frame time code.
+ *
+ * @param framenum frame number to adjust
+ * @param fps      frame per second, 30 or 60
+ * @return         adjusted frame number
+ * @warning        adjustment is only valid in NTSC 29.97 and 59.94
+ */
+int av_timecode_adjust_ntsc_framenum2(int framenum, int fps);
+
+/**
+ * Convert frame number to SMPTE 12M binary representation.
+ *
+ * @param tc       timecode data correctly initialized
+ * @param framenum frame number
+ * @return         the SMPTE binary representation
+ *
+ * @note Frame number adjustment is automatically done in case of drop timecode,
+ *       you do NOT have to call av_timecode_adjust_ntsc_framenum2().
+ * @note The frame number is relative to tc->start.
+ * @note Color frame (CF), binary group flags (BGF) and biphase mark polarity
+ *       correction (PC) bits are set to zero.
+ */
+uint32_t av_timecode_get_smpte_from_framenum(const AVTimecode *tc, int framenum);
+
+/**
+ * Load timecode string in buf.
+ *
+ * @param buf      destination buffer, must be at least AV_TIMECODE_STR_SIZE long
+ * @param tc       timecode data correctly initialized
+ * @param framenum frame number
+ * @return         the buf parameter
+ *
+ * @note Timecode representation can be a negative timecode and have more than
+ *       24 hours, but will only be honored if the flags are correctly set.
+ * @note The frame number is relative to tc->start.
+ */
+char *av_timecode_make_string(const AVTimecode *tc, char *buf, int framenum);
+
+/**
+ * Get the timecode string from the SMPTE timecode format.
+ *
+ * @param buf        destination buffer, must be at least AV_TIMECODE_STR_SIZE long
+ * @param tcsmpte    the 32-bit SMPTE timecode
+ * @param prevent_df prevent the use of a drop flag when it is known the DF bit
+ *                   is arbitrary
+ * @return           the buf parameter
+ */
+char *av_timecode_make_smpte_tc_string(char *buf, uint32_t tcsmpte, int prevent_df);
+
+/**
+ * Get the timecode string from the 25-bit timecode format (MPEG GOP format).
+ *
+ * @param buf     destination buffer, must be at least AV_TIMECODE_STR_SIZE long
+ * @param tc25bit the 25-bits timecode
+ * @return        the buf parameter
+ */
+char *av_timecode_make_mpeg_tc_string(char *buf, uint32_t tc25bit);
+
+/**
+ * Init a timecode struct with the passed parameters.
+ *
+ * @param log_ctx     a pointer to an arbitrary struct of which the first field
+ *                    is a pointer to an AVClass struct (used for av_log)
+ * @param tc          pointer to an allocated AVTimecode
+ * @param rate        frame rate in rational form
+ * @param flags       miscellaneous flags such as drop frame, +24 hours, ...
+ *                    (see AVTimecodeFlag)
+ * @param frame_start the first frame number
+ * @return            0 on success, AVERROR otherwise
+ */
+int av_timecode_init(AVTimecode *tc, AVRational rate, int flags, int frame_start, void *log_ctx);
+
+/**
+ * Parse timecode representation (hh:mm:ss[:;.]ff).
+ *
+ * @param log_ctx a pointer to an arbitrary struct of which the first field is a
+ *                pointer to an AVClass struct (used for av_log).
+ * @param tc      pointer to an allocated AVTimecode
+ * @param rate    frame rate in rational form
+ * @param str     timecode string which will determine the frame start
+ * @return        0 on success, AVERROR otherwise
+ */
+int av_timecode_init_from_string(AVTimecode *tc, AVRational rate, const char *str, void *log_ctx);
+
+/**
+ * Check if the timecode feature is available for the given frame rate
+ *
+ * @return 0 if supported, <0 otherwise
+ */
+int av_timecode_check_frame_rate(AVRational rate);
+
+#endif /* AVUTIL_TIMECODE_H */

+ 74 - 0
wave420l/code/ffmpeg/include/libavutil/timestamp.h

@@ -0,0 +1,74 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * timestamp utils, mostly useful for debugging/logging purposes
+ */
+
+#ifndef AVUTIL_TIMESTAMP_H
+#define AVUTIL_TIMESTAMP_H
+
+#include "common.h"
+
+#define AV_TS_MAX_STRING_SIZE 32
+
+/**
+ * Fill the provided buffer with a string containing a timestamp
+ * representation.
+ *
+ * @param buf a buffer with size in bytes of at least AV_TS_MAX_STRING_SIZE
+ * @param ts the timestamp to represent
+ * @return the buffer in input
+ */
+static inline char *av_ts_make_string(char *buf, int64_t ts)
+{
+    if (ts == AV_NOPTS_VALUE) snprintf(buf, AV_TS_MAX_STRING_SIZE, "NOPTS");
+    else                      snprintf(buf, AV_TS_MAX_STRING_SIZE, "%"PRId64, ts);
+    return buf;
+}
+
+/**
+ * Convenience macro, the return value should be used only directly in
+ * function arguments but never stand-alone.
+ */
+#define av_ts2str(ts) av_ts_make_string((char[AV_TS_MAX_STRING_SIZE]){0}, ts)
+
+/**
+ * Fill the provided buffer with a string containing a timestamp time
+ * representation.
+ *
+ * @param buf a buffer with size in bytes of at least AV_TS_MAX_STRING_SIZE
+ * @param ts the timestamp to represent
+ * @param tb the timebase of the timestamp
+ * @return the buffer in input
+ */
+static inline char *av_ts_make_time_string(char *buf, int64_t ts, AVRational *tb)
+{
+    if (ts == AV_NOPTS_VALUE) snprintf(buf, AV_TS_MAX_STRING_SIZE, "NOPTS");
+    else                      snprintf(buf, AV_TS_MAX_STRING_SIZE, "%.6g", av_q2d(*tb) * ts);
+    return buf;
+}
+
+/**
+ * Convenience macro, the return value should be used only directly in
+ * function arguments but never stand-alone.
+ */
+#define av_ts2timestr(ts, tb) av_ts_make_time_string((char[AV_TS_MAX_STRING_SIZE]){0}, ts, tb)
+
+#endif /* AVUTIL_TIMESTAMP_H */

+ 153 - 0
wave420l/code/ffmpeg/include/libavutil/version.h

@@ -0,0 +1,153 @@
+/*
+ * copyright (c) 2003 Fabrice Bellard
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_VERSION_H
+#define AVUTIL_VERSION_H
+
+/**
+ * @defgroup preproc_misc Preprocessor String Macros
+ *
+ * String manipulation macros
+ *
+ * @{
+ */
+
+#define AV_STRINGIFY(s)         AV_TOSTRING(s)
+#define AV_TOSTRING(s) #s
+
+#define AV_GLUE(a, b) a ## b
+#define AV_JOIN(a, b) AV_GLUE(a, b)
+
+#define AV_PRAGMA(s) _Pragma(#s)
+
+/**
+ * @}
+ */
+
+/**
+ * @defgroup version_utils Library Version Macros
+ *
+ * Useful to check and match library version in order to maintain
+ * backward compatibility.
+ *
+ * @{
+ */
+
+#define AV_VERSION_INT(a, b, c) (a<<16 | b<<8 | c)
+#define AV_VERSION_DOT(a, b, c) a ##.## b ##.## c
+#define AV_VERSION(a, b, c) AV_VERSION_DOT(a, b, c)
+
+/**
+ * @}
+ */
+
+
+/**
+ * @file
+ * @ingroup lavu
+ * Libavutil version macros
+ */
+
+/**
+ * @defgroup lavu_ver Version and Build diagnostics
+ *
+ * Macros and function useful to check at compiletime and at runtime
+ * which version of libavutil is in use.
+ *
+ * @{
+ */
+
+#define LIBAVUTIL_VERSION_MAJOR  52
+#define LIBAVUTIL_VERSION_MINOR  48
+#define LIBAVUTIL_VERSION_MICRO 101
+
+#define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
+                                               LIBAVUTIL_VERSION_MINOR, \
+                                               LIBAVUTIL_VERSION_MICRO)
+#define LIBAVUTIL_VERSION       AV_VERSION(LIBAVUTIL_VERSION_MAJOR,     \
+                                           LIBAVUTIL_VERSION_MINOR,     \
+                                           LIBAVUTIL_VERSION_MICRO)
+#define LIBAVUTIL_BUILD         LIBAVUTIL_VERSION_INT
+
+#define LIBAVUTIL_IDENT         "Lavu" AV_STRINGIFY(LIBAVUTIL_VERSION)
+
+/**
+ * @}
+ *
+ * @defgroup depr_guards Deprecation guards
+ * FF_API_* defines may be placed below to indicate public API that will be
+ * dropped at a future version bump. The defines themselves are not part of
+ * the public API and may change, break or disappear at any time.
+ *
+ * @{
+ */
+
+#ifndef FF_API_GET_BITS_PER_SAMPLE_FMT
+#define FF_API_GET_BITS_PER_SAMPLE_FMT (LIBAVUTIL_VERSION_MAJOR < 53)
+#endif
+#ifndef FF_API_FIND_OPT
+#define FF_API_FIND_OPT                 (LIBAVUTIL_VERSION_MAJOR < 53)
+#endif
+#ifndef FF_API_OLD_AVOPTIONS
+#define FF_API_OLD_AVOPTIONS            (LIBAVUTIL_VERSION_MAJOR < 53)
+#endif
+#ifndef FF_API_PIX_FMT
+#define FF_API_PIX_FMT                  (LIBAVUTIL_VERSION_MAJOR < 53)
+#endif
+#ifndef FF_API_CONTEXT_SIZE
+#define FF_API_CONTEXT_SIZE             (LIBAVUTIL_VERSION_MAJOR < 53)
+#endif
+#ifndef FF_API_PIX_FMT_DESC
+#define FF_API_PIX_FMT_DESC             (LIBAVUTIL_VERSION_MAJOR < 53)
+#endif
+#ifndef FF_API_AV_REVERSE
+#define FF_API_AV_REVERSE               (LIBAVUTIL_VERSION_MAJOR < 53)
+#endif
+#ifndef FF_API_AUDIOCONVERT
+#define FF_API_AUDIOCONVERT             (LIBAVUTIL_VERSION_MAJOR < 53)
+#endif
+#ifndef FF_API_CPU_FLAG_MMX2
+#define FF_API_CPU_FLAG_MMX2            (LIBAVUTIL_VERSION_MAJOR < 53)
+#endif
+#ifndef FF_API_SAMPLES_UTILS_RETURN_ZERO
+#define FF_API_SAMPLES_UTILS_RETURN_ZERO (LIBAVUTIL_VERSION_MAJOR < 53)
+#endif
+#ifndef FF_API_LLS_PRIVATE
+#define FF_API_LLS_PRIVATE              (LIBAVUTIL_VERSION_MAJOR < 53)
+#endif
+#ifndef FF_API_LLS1
+#define FF_API_LLS1                     (LIBAVUTIL_VERSION_MAJOR < 53)
+#endif
+#ifndef FF_API_AVFRAME_LAVC
+#define FF_API_AVFRAME_LAVC             (LIBAVUTIL_VERSION_MAJOR < 53)
+#endif
+#ifndef FF_API_VDPAU
+#define FF_API_VDPAU                    (LIBAVUTIL_VERSION_MAJOR < 53)
+#endif
+#ifndef FF_API_GET_CHANNEL_LAYOUT_COMPAT
+#define FF_API_GET_CHANNEL_LAYOUT_COMPAT (LIBAVUTIL_VERSION_MAJOR < 53)
+#endif
+
+/**
+ * @}
+ */
+
+#endif /* AVUTIL_VERSION_H */
+

+ 62 - 0
wave420l/code/ffmpeg/include/libavutil/xtea.h

@@ -0,0 +1,62 @@
+/*
+ * A 32-bit implementation of the XTEA algorithm
+ * Copyright (c) 2012 Samuel Pitoiset
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_XTEA_H
+#define AVUTIL_XTEA_H
+
+#include <stdint.h>
+
+/**
+ * @defgroup lavu_xtea XTEA
+ * @ingroup lavu_crypto
+ * @{
+ */
+
+typedef struct AVXTEA {
+    uint32_t key[16];
+} AVXTEA;
+
+/**
+ * Initialize an AVXTEA context.
+ *
+ * @param ctx an AVXTEA context
+ * @param key a key of 16 bytes used for encryption/decryption
+ */
+void av_xtea_init(struct AVXTEA *ctx, const uint8_t key[16]);
+
+/**
+ * Encrypt or decrypt a buffer using a previously initialized context.
+ *
+ * @param ctx an AVXTEA context
+ * @param dst destination array, can be equal to src
+ * @param src source array, can be equal to dst
+ * @param count number of 8 byte blocks
+ * @param iv initialization vector for CBC mode, if NULL then ECB will be used
+ * @param decrypt 0 for encryption, 1 for decryption
+ */
+void av_xtea_crypt(struct AVXTEA *ctx, uint8_t *dst, const uint8_t *src,
+                   int count, uint8_t *iv, int decrypt);
+
+/**
+ * @}
+ */
+
+#endif /* AVUTIL_XTEA_H */

+ 94 - 0
wave420l/code/sample/Android.mk

@@ -0,0 +1,94 @@
+
+LOCAL_PATH := $(call my-dir)
+
+# FOR C&M FPGA Environment
+CNM_FPGA_FLAGS := -DCNM_FPGA_PLATFORM -DCNM_FPGA_USB_INTERFACE -DSUPPORT_USB_TRANSFER -DSUPPORT_CONF_TEST
+ifeq ($(PRODUCT), 7Q)
+CNM_CFLAGS := -DCODA7Q $(CNM_FPGA_FLAGS)
+endif
+ifeq ($(PRODUCT), 960)
+CNM_CFLAGS := -DCODA960 $(CNM_FPGA_FLAGS)
+endif
+ifeq ($(PRODUCT), 980)
+CNM_CFLAGS := -DCODA980 $(CNM_FPGA_FLAGS)
+endif
+ifeq ($(PRODUCT), 410)
+CNM_CFLAGS := -DWAVE410 $(CNM_FPGA_FLAGS)
+endif
+ifeq ($(PRODUCT), 412)
+CNM_CFLAGS := -DWAVE412 $(CNM_FPGA_FLAGS)
+endif
+ifeq ($(PRODUCT), 420)
+CNM_CFLAGS := -DWAVE420 $(CNM_FPGA_FLAGS)
+endif
+#
+
+#Building vpurun binary which will be placed in the /system/bin folder
+
+SRC_FILES := helper/main_helper.c				\
+          helper/vpuhelper.c                         \
+          helper/bitstream/bitstreamfeeder.c         \
+          helper/bitstream/bitstreamreader.c         \
+          helper/bitstream/bsfeeder_fixedsize_impl.c \
+          helper/bitstream/bsfeeder_framesize_impl.c \
+          helper/comparator/bin_comparator_impl.c    \
+          helper/comparator/comparator.c             \
+          helper/comparator/md5_comparator_impl.c    \
+          helper/comparator/yuv_comparator_impl.c    \
+          helper/display/fbdev_impl.c                \
+          helper/display/simplerenderer.c            \
+          helper/misc/cfgParser.c                    \
+          helper/misc/cnm_fpga.c                     \
+          helper/misc/cnm_video_helper.c             \
+          helper/misc/container.c                    \
+          helper/misc/datastructure.c                \
+          helper/misc/platform.c                     \
+          helper/yuv/yuvfeeder.c                     \
+          helper/yuv/yuvLoaderfeeder.c               
+	
+
+
+
+
+C_INCLUDES := $(LOCAL_PATH)				\
+		$(TOP)/hardware/vpu/ffmpeg/include	\
+		$(TOP)/hardware/vpu/theoraparser/include	\
+		$(TOP)/hardware/vpu/vpuapi		        \
+		$(TOP)/hardware/vpu/sample			\
+		$(TOP)/hardware/vpu/sample/helper           
+ 
+					
+
+SHARED_LIBRARIES :=       \
+        libvpu			\
+        libtheoraparser         \
+        libutils                \
+
+define build_executable
+	include $(CLEAR_VARS)
+	LOCAL_C_INCLUDES := $(C_INCLUDES)
+	LOCAL_SHARED_LIBRARIES := $(SHARED_LIBRARIES)
+	LOCAL_SRC_FILES := main_$(1).c
+	LOCAL_SRC_FILES += $(SRC_FILES)
+	LOCAL_MODULE_TAGS := eng
+	LOCAL_MODULE := $(1)
+	LOCAL_CFLAGS := $(CNM_CFLAGS)
+	include $(BUILD_EXECUTABLE)
+endef
+
+prog_names := 
+#ifdef CODA980_DEC_SAMPLE
+prog_names := coda980_dec_test
+#endif
+#ifdef CODA980_ENC_SAMPLE
+prog_names += coda980_enc_test
+#endif
+#ifdef WAVE4XX_DEC_SAMPLE 
+prog_names += w4_dec_test
+#endif
+#ifdef WAVE4XX_ENC_SAMPLE 
+prog_names += w4_enc_test
+#endif
+
+$(foreach item,$(prog_names),$(eval $(call build_executable,$(item))))
+

+ 22 - 0
wave420l/code/sample/helper/bitstream/binaryreader.c

@@ -0,0 +1,22 @@
+//--=========================================================================--
+//  This file is a part of VPU Reference API project
+//-----------------------------------------------------------------------------
+//       This confidential and proprietary software may be used only
+//     as authorized by a licensing agreement from Chips&Media Inc.
+//     In the event of publication, the following notice is applicable:
+//
+//            (C) COPYRIGHT 2006 - 2013  CHIPS&MEDIA INC.
+//                      ALL RIGHTS RESERVED
+//
+//       The entire notice above must be reproduced on all authorized
+//       copies.
+//
+//--=========================================================================--
+
+#include "main_helper.h"
+
+
+
+
+
+

+ 505 - 0
wave420l/code/sample/helper/bitstream/bitstreamfeeder.c

@@ -0,0 +1,505 @@
+//--=========================================================================--
+//  This file is a part of VPU Reference API project
+//-----------------------------------------------------------------------------
+//
+//       This confidential and proprietary software may be used only
+//     as authorized by a licensing agreement from Chips&Media Inc.
+//     In the event of publication, the following notice is applicable:
+//
+//            (C) COPYRIGHT CHIPS&MEDIA INC.
+//                      ALL RIGHTS RESERVED
+//
+//       The entire notice above must be reproduced on all authorized
+//       copies.
+//
+//--=========================================================================--
+#include <stdio.h>
+#include <stdarg.h>
+#include <time.h>
+
+#include "vpuapifunc.h"
+#include "main_helper.h"
+
+typedef struct {
+    FeedingMethod   method;
+    Uint8*          remainData;
+    Uint32          remainDataSize;
+    void*           actualFeeder;
+    PhysicalAddress base;
+    Uint32          size;
+    Uint32          fillingMode;
+    BOOL            eos;
+    VpuThread       threadHandle;
+    DecHandle       decHandle;
+    EndianMode      endian;
+    BSFeederHook    observer;
+    void*           observerArg;
+    BOOL            autoUpdate;     /* TRUE - Call VPU_DecUpdateBitstreamBuffer() in the bitstream feeder. default */
+} BitstreamFeeder;
+
+static void BitstreamFeeder_DummyObserver(
+    void*   handle,
+    void*   es,
+    Uint32  size,
+    void*   arg
+    )
+{
+    UNREFERENCED_PARAMETER(handle);
+    UNREFERENCED_PARAMETER(es);
+    UNREFERENCED_PARAMETER(size);
+    UNREFERENCED_PARAMETER(arg);
+}
+
+extern void* BSFeederFixedSize_Create(
+    const char* path,
+    Uint32    chunkSize
+    );
+
+extern BOOL BSFeederFixedSize_Destroy(
+    BSFeeder feeder
+    );
+
+extern Int32 BSFeederFixedSize_Act(
+    void*       feeder,
+    BSChunk*    chunk
+    );
+
+extern Int32 BSFeederFixedSize_Rewind(
+    void*       feeder
+    );
+
+extern void* BSFeederFrameSize_Create(
+    const char* path,
+    CodStd    codec,
+    CodStd*   retCodecId,
+    Uint32*   retMp4ClassId,
+    Uint32*   retSeqWidth,
+    Uint32*   retSeqHeight
+    );
+
+extern BOOL BSFeederFrameSize_Destroy(
+    void*   feeder
+    );
+
+extern Int32 BSFeederFrameSize_Act(
+    void*       feeder,
+    BSChunk*    packet
+    );
+
+extern BOOL BSFeederFrameSize_Rewind(
+    void*       feeder
+    );
+
+extern void* BSFeederSizePlusEs_Create(
+    const char* path
+    );
+
+extern BOOL BSFeederSizePlusEs_Destroy(
+    void* feeder
+    );
+
+extern Int32 BSFeederSizePlusEs_Act(
+    void*       feeder,
+    BSChunk*    chunk
+    );
+
+extern Int32 BSFeederSizePlusEs_Rewind(
+    void*       feeder
+    );
+
+/**
+* Abstract Bitstream Feeader Functions 
+*/
+void* BitstreamFeeder_Create(
+    const char*     path,
+    FeedingMethod   method,
+    PhysicalAddress base,
+    Uint32          size,
+    ...
+    )
+{
+    /*lint -esym(438, ap) */
+    va_list             ap;
+    Uint32              chunkSize;
+    BitstreamFeeder*    handle = NULL;
+    void*               feeder = NULL;
+    CodStd              codecId;
+    CodStd*             retCodecId;
+    Uint32*             retMp4ClassId;
+    Uint32*             retSeqWidth;
+    Uint32*             retSeqHeight;
+
+    switch (method) {
+    case FEEDING_METHOD_FIXED_SIZE:
+        va_start(ap, size);
+        chunkSize = va_arg(ap, int);
+        va_end(ap);
+        feeder = BSFeederFixedSize_Create(path, chunkSize);
+        break;
+    case FEEDING_METHOD_FRAME_SIZE:
+        va_start(ap, size);
+        codecId       = (CodStd)va_arg(ap, Int32);
+        retCodecId    = (CodStd*)va_arg(ap, CodStd*);
+        retMp4ClassId = (Uint32*)va_arg(ap, Uint32*);
+        retSeqWidth   = (Uint32*)va_arg(ap, Uint32*);
+        retSeqHeight  = (Uint32*)va_arg(ap, Uint32*);
+        va_end(ap);
+        feeder = BSFeederFrameSize_Create(path, codecId, retCodecId, retMp4ClassId, retSeqWidth, retSeqHeight);
+        break;
+    case FEEDING_METHOD_SIZE_PLUS_ES:
+        feeder = BSFeederSizePlusEs_Create(path);
+        break;
+    default:
+        feeder = NULL;
+        break;
+    }
+
+    if (feeder != NULL) {
+        if ((handle=(BitstreamFeeder*)osal_malloc(sizeof(BitstreamFeeder))) == NULL) {
+            VLOG(ERR, "%s:%d Failed to allocate memory\n", __FUNCTION__, __LINE__);
+            return NULL;
+        }
+        handle->actualFeeder = feeder;
+        handle->method       = method;
+        handle->remainData   = NULL;
+        handle->remainDataSize = 0;
+        handle->base         = base;
+        handle->size         = size;
+        handle->fillingMode  = (method == FEEDING_METHOD_FIXED_SIZE) ? BSF_FILLING_RINGBUFFER : BSF_FILLING_LINEBUFFER;
+        handle->threadHandle = NULL;
+        handle->eos          = FALSE;
+        handle->observer     = (BSFeederHook)BitstreamFeeder_DummyObserver;
+        handle->observerArg  = NULL;
+        handle->autoUpdate   = TRUE;
+    }
+
+    return handle;
+    /*lint +esym(438, ap) */
+}
+
+void BitstreamFeeder_SetFillMode(
+    BSFeeder    feeder,
+    Uint32      mode
+    )
+{
+    BitstreamFeeder* bsf = (BitstreamFeeder*)feeder;
+
+    switch (mode) {
+    case BSF_FILLING_AUTO:
+        bsf->fillingMode  = (bsf->method == FEEDING_METHOD_FIXED_SIZE) ? BSF_FILLING_RINGBUFFER : BSF_FILLING_LINEBUFFER;
+        break;
+    case BSF_FILLING_RINGBUFFER:
+    case BSF_FILLING_LINEBUFFER:
+    case BSF_FILLING_RINGBUFFER_WITH_ENDFLAG:
+        bsf->fillingMode = mode;
+        break;
+    default:
+        VLOG(INFO, "%s Not supported mode %d\n", __FUNCTION__, mode);
+        break;
+    }
+}
+
+static Uint32 FeedBitstream(
+    BSFeeder        feeder,
+    vpu_buffer_t*   buffer
+    )
+{
+    BitstreamFeeder* bsf = (BitstreamFeeder*)feeder;
+    Int32            feedingSize = 0;
+    BSChunk          chunk = {0};
+    PhysicalAddress  rdPtr, wrPtr;
+    Uint32           room;
+    DecHandle        decHandle;
+    EndianMode       endian;
+    
+    if (bsf == NULL) {
+        VLOG(ERR, "%s:%d Null handle\n", __FUNCTION__, __LINE__);
+        return 0;
+    }
+
+    decHandle = bsf->decHandle;
+    endian    = bsf->endian;
+
+    if (bsf->remainData == NULL) {
+        chunk.size = bsf->size; 
+        chunk.data = osal_malloc(chunk.size);
+        chunk.eos  = FALSE;
+        if (chunk.data == NULL) {
+            VLOG(ERR, "%s:%d failed to allocate memory\n", __FUNCTION__, __LINE__);
+            return 0;
+        }
+        switch (bsf->method) {
+        case FEEDING_METHOD_FIXED_SIZE:
+            feedingSize = BSFeederFixedSize_Act(bsf->actualFeeder, &chunk);
+            break;
+        case FEEDING_METHOD_FRAME_SIZE:
+            feedingSize = BSFeederFrameSize_Act(bsf->actualFeeder, &chunk);
+            break;
+        case FEEDING_METHOD_SIZE_PLUS_ES:
+            feedingSize = BSFeederSizePlusEs_Act(bsf->actualFeeder, &chunk);
+            break;
+        default:
+            VLOG(ERR, "%s:%d Invalid method(%d)\n", __FUNCTION__, __LINE__, bsf->method);
+            osal_free(chunk.data);
+            return 0;
+        }
+    }
+    else {
+        chunk.data  = bsf->remainData;
+        feedingSize = bsf->remainDataSize;
+    }
+
+    bsf->observer((void*)bsf, chunk.data, feedingSize, bsf->observerArg);
+
+    if (feedingSize < 0) {
+        VLOG(ERR, "feeding size is negative value: %d\n", feedingSize);
+        osal_free(chunk.data);
+        return 0;
+    }
+
+    if (feedingSize > 0) {
+        Uint32 coreIdx = VPU_HANDLE_CORE_INDEX(decHandle);
+        Uint32 rightSize=0, leftSize=feedingSize;
+
+        if (buffer == NULL) {
+            VPU_DecGetBitstreamBuffer(decHandle, &rdPtr, &wrPtr, &room);
+        }
+        else {
+            rdPtr = wrPtr = buffer->phys_addr;
+            room  = buffer->size;
+        }
+        if ((Int32)room < feedingSize) {
+            bsf->remainData     = chunk.data;
+            bsf->remainDataSize = feedingSize;
+            return 0;
+        }
+
+        if (bsf->fillingMode == BSF_FILLING_RINGBUFFER || bsf->fillingMode == BSF_FILLING_RINGBUFFER_WITH_ENDFLAG) {
+            if ((wrPtr+feedingSize) >= (bsf->base+bsf->size)) {
+                PhysicalAddress endAddr = bsf->base+bsf->size;
+                rightSize = endAddr-wrPtr;
+                leftSize  = (wrPtr+feedingSize) - endAddr;
+                if (rightSize > 0) {
+                    VpuWriteMem(coreIdx, wrPtr, (unsigned char*)chunk.data, rightSize, (int)endian);
+                }
+                wrPtr     = bsf->base;
+            }
+        }
+        
+        VpuWriteMem(coreIdx, wrPtr, (unsigned char*)chunk.data+rightSize, leftSize, (int)endian);
+    }
+
+    if (bsf->autoUpdate == TRUE) {
+        /* If feedingSize is equal to zero then VPU will be ready to terminate current sequence. */
+        VPU_DecUpdateBitstreamBuffer(decHandle, feedingSize);
+        if (chunk.eos == TRUE || bsf->fillingMode == BSF_FILLING_RINGBUFFER_WITH_ENDFLAG) {
+            VPU_DecUpdateBitstreamBuffer(decHandle, STREAM_END_SET_FLAG);
+        }
+    }
+    bsf->eos = chunk.eos;
+    osal_free(chunk.data);
+
+    bsf->remainData     = NULL;
+    bsf->remainDataSize = 0;
+
+    return feedingSize;
+}
+
+static void FeederThread(
+    void* arg
+    )
+{
+    BitstreamFeeder* bsf = (BitstreamFeeder*)arg;
+
+    while (bsf->eos == FALSE) {
+        MSleep(10);
+        FeedBitstream(bsf, NULL);
+    }
+}
+
+Uint32 BitstreamFeeder_Act(
+    DecHandle       decHandle,
+    BSFeeder        feeder,
+    EndianMode      endian,
+    vpu_buffer_t*   buffer
+    )
+{
+    BitstreamFeeder* bsf = (BitstreamFeeder*)feeder;
+
+    bsf->decHandle = decHandle;
+    bsf->endian    = endian;
+    return FeedBitstream(feeder, buffer);
+}
+
+/* \param   sync    FALSE: The thread fill bitstream into a bitstream buffer continously
+ *                  TRUE:  The thread start to fill bitstream into a bitstream buffer just one time.
+ *                         Client MUST call BitstreamFeeder_Run() with fourth parameter TRUE for every
+ *                         decoding sequence.
+ */
+BOOL BitstreamFeeder_Run(
+    DecHandle   decHandle,
+    BSFeeder    feeder,
+    EndianMode  endian
+    )
+{
+    BitstreamFeeder*    bsf = (BitstreamFeeder*)feeder;
+    VpuThreadRunner     runner = (VpuThreadRunner)FeederThread;
+
+    bsf->decHandle = decHandle;
+    bsf->endian    = endian;
+
+    bsf->threadHandle = VpuThread_Create(runner, (void*)bsf);
+    if (bsf->threadHandle == NULL) {
+        return FALSE;
+    }
+
+    return TRUE;
+}
+
+BOOL BitstreamFeeder_IsEos(
+    BSFeeder    feeder
+    )
+{
+    BitstreamFeeder* bsf = (BitstreamFeeder*)feeder;
+
+    if (bsf == NULL) {
+        VLOG(ERR, "%s:%d Null handle\n", __FUNCTION__, __LINE__);
+        return FALSE;
+    }
+
+    return bsf->eos;
+}
+
+void BitstreamFeeder_Stop(
+    BSFeeder    feeder
+    )
+{
+    BitstreamFeeder* bsf = (BitstreamFeeder*)feeder;
+
+    if (bsf == NULL) {
+        VLOG(ERR, "%s:%d Null handle\n", __FUNCTION__, __LINE__);
+        return;
+    }
+
+    if (bsf->threadHandle != NULL) {
+        bsf->eos = TRUE;
+        VpuThread_Join(bsf->threadHandle);
+        bsf->threadHandle = NULL;
+    }
+}
+
+BOOL BitstreamFeeder_Destroy(
+    BSFeeder feeder
+    )
+{
+    BitstreamFeeder* bsf = (BitstreamFeeder*)feeder;
+
+    if (bsf == NULL) {
+        VLOG(ERR, "%s:%d Null handle\n", __FUNCTION__, __LINE__);
+        return FALSE;
+    }
+
+    if (bsf->threadHandle) {
+        bsf->eos = TRUE;
+        VpuThread_Join(bsf->threadHandle);
+        bsf->threadHandle = NULL;
+    }
+
+    switch (bsf->method) {
+    case FEEDING_METHOD_FIXED_SIZE:
+        BSFeederFixedSize_Destroy(bsf->actualFeeder);
+        break;
+    case FEEDING_METHOD_FRAME_SIZE:
+        BSFeederFrameSize_Destroy(bsf->actualFeeder);
+        break;
+    case FEEDING_METHOD_SIZE_PLUS_ES:
+        BSFeederSizePlusEs_Destroy(bsf->actualFeeder);
+        break;
+    default:
+        VLOG(ERR, "%s:%d Invalid method(%d)\n", __FUNCTION__, __LINE__, bsf->method);
+        break;
+    }
+
+    if (bsf->remainData) {
+        osal_free(bsf->remainData);
+    }
+
+    osal_free(bsf);
+
+    return TRUE;
+}
+
+BOOL BitstreamFeeder_Rewind(
+    BSFeeder feeder
+    )
+{
+    BitstreamFeeder*    bsf = (BitstreamFeeder*)feeder;
+    BOOL                success = FALSE;
+
+    if (bsf == NULL) {
+        VLOG(ERR, "%s:%d handle is NULL\n", __FUNCTION__, __LINE__);
+        return success;
+    }
+
+    switch (bsf->method) {
+    case FEEDING_METHOD_FIXED_SIZE:
+        success = BSFeederFixedSize_Rewind(bsf->actualFeeder);
+        break;
+    case FEEDING_METHOD_FRAME_SIZE:
+        success = BSFeederFrameSize_Rewind(bsf->actualFeeder);
+        break;
+    case FEEDING_METHOD_SIZE_PLUS_ES:
+        success = BSFeederSizePlusEs_Rewind(bsf->actualFeeder);
+        break;
+    default:
+        VLOG(ERR, "%s:%d Invalid method(%d)\n", __FUNCTION__, __LINE__, bsf->method);
+        break;
+    }
+
+    if (success == TRUE) {
+        bsf->eos = FALSE;
+    }
+
+    return success;
+}
+
+BOOL BitstreamFeeder_SetHook(
+    BSFeeder        feeder,
+    BSFeederHook    hookFunc,
+    void*           hookArg
+    )
+{
+    BitstreamFeeder*    bsf = (BitstreamFeeder*)feeder;
+
+    if (bsf == NULL) {
+        VLOG(ERR, "%s:%d handle is NULL\n", __FUNCTION__, __LINE__);
+        return FALSE;
+    }
+
+    if (hookFunc == NULL) {
+        bsf->observer = (BSFeederHook)BitstreamFeeder_DummyObserver;
+    }
+    else {
+        bsf->observer = hookFunc;
+    }
+    bsf->observerArg  = hookArg;
+
+    return TRUE;
+}
+
+BOOL BitstreamFeeder_SetAutoUpdate(
+    BSFeeder        feeder,
+    BOOL            onoff
+    )
+{
+    BitstreamFeeder*    bsf = (BitstreamFeeder*)feeder;
+
+    if (bsf == NULL) {
+        VLOG(ERR, "%s:%d handle is NULL\n", __FUNCTION__, __LINE__);
+        return FALSE;
+    }
+    bsf->autoUpdate = onoff;
+
+    return TRUE;
+}
+ 

+ 165 - 0
wave420l/code/sample/helper/bitstream/bitstreamreader.c

@@ -0,0 +1,165 @@
+//--=========================================================================--
+//  This file is a part of VPU Reference API project
+//-----------------------------------------------------------------------------
+//       This confidential and proprietary software may be used only
+//     as authorized by a licensing agreement from Chips&Media Inc.
+//     In the event of publication, the following notice is applicable:
+//
+//            (C) COPYRIGHT 2006 - 2013  CHIPS&MEDIA INC.
+//                      ALL RIGHTS RESERVED
+//
+//       The entire notice above must be reproduced on all authorized
+//       copies.
+//
+//--=========================================================================--
+
+#include "main_helper.h"
+
+
+typedef struct {
+    Uint32                  type;
+    EndianMode              endian;
+    BitstreamReaderImpl*    impl;
+    osal_file_t*            fp;
+    EncHandle*              handle;
+} AbstractBitstreamReader;
+
+BitstreamReader BitstreamReader_Create(
+    Uint32      type,
+    char*       path,
+    EndianMode  endian,
+    EncHandle*  handle
+    )
+{
+    AbstractBitstreamReader* reader;
+    osal_file_t *fp;
+
+    if ( path == NULL) {
+        VLOG(ERR, "%s:%d path is NULL\n", __FUNCTION__, __LINE__);
+        return NULL;
+    }
+
+    if ((fp=osal_fopen(path, "wb")) == NULL) {
+        VLOG(ERR, "%s:%d failed to open bin file: %s\n", __FUNCTION__, __LINE__, path);
+        return FALSE;
+    }
+    VLOG(INFO, "output bin file: %s\n", path);
+
+    reader = (AbstractBitstreamReader*)osal_malloc(sizeof(AbstractBitstreamReader));
+
+    reader->fp      = fp;
+    reader->handle  = handle;
+    reader->type    = type;
+    reader->endian  = endian;
+
+    return reader;
+}
+
+BOOL BitstreamReader_Act(
+    BitstreamReader reader,
+    PhysicalAddress bitstreamBuffer,
+    Uint32          bitstreamBufferSize,
+    Uint32          streamReadSize,
+    Comparator      comparator
+    )
+{
+    AbstractBitstreamReader* absReader = (AbstractBitstreamReader*)reader;
+    osal_file_t     *fp;
+    EncHandle       *handle;
+    RetCode         ret = RETCODE_SUCCESS;
+    PhysicalAddress paRdPtr;
+    PhysicalAddress paWrPtr;
+    int             size = 0;
+    Int32           loadSize = 0;
+    PhysicalAddress paBsBufStart = bitstreamBuffer;
+    PhysicalAddress paBsBufEnd   = bitstreamBuffer+bitstreamBufferSize;
+    Uint8*          buf          = NULL;
+    Uint32          coreIdx;
+    BOOL            success      = TRUE;
+
+    if (reader == NULL) {
+#ifdef SUPPORT_DONT_READ_STREAM
+        return TRUE;
+#else
+        VLOG(ERR, "%s:%d Invalid handle\n", __FUNCTION__, __LINE__);
+        return FALSE;
+#endif
+    }
+    fp = absReader->fp;
+    handle = absReader->handle;
+    coreIdx = VPU_HANDLE_CORE_INDEX(*handle);
+    
+    ret = VPU_EncGetBitstreamBuffer(*handle, &paRdPtr, &paWrPtr, &size);
+    if (size > 0) {
+        if (streamReadSize > 0) {
+            if ((Uint32)size < streamReadSize) {
+                loadSize = size;
+            } 
+            else {
+                loadSize = streamReadSize;
+            }
+        }
+        else {
+            loadSize = size;
+        }
+
+        buf = (Uint8*)osal_malloc(loadSize);
+        if (buf == NULL) {
+            return FALSE;
+        }
+
+        if (absReader->type == BUFFER_MODE_TYPE_RINGBUFFER) {
+            if ((paRdPtr+loadSize) > paBsBufEnd) {
+                Uint32   room;
+                room = paBsBufEnd - paRdPtr;
+                vdi_read_memory(coreIdx, paRdPtr, buf, room,  absReader->endian);
+                vdi_read_memory(coreIdx, paBsBufStart, buf+room, (loadSize-room), absReader->endian);
+            } 
+            else {
+                vdi_read_memory(coreIdx, paRdPtr, buf, loadSize, absReader->endian); 
+            }
+        } 
+        else {
+            /* Linebuffer */
+            vdi_read_memory(coreIdx, paRdPtr, buf, loadSize, absReader->endian); 
+        }
+
+        if (fp != NULL) {
+            osal_fwrite((void *)buf, sizeof(Uint8), loadSize, fp);
+            osal_fflush(fp);
+        }
+
+        if (comparator != NULL) {
+            if (Comparator_Act(comparator, buf, loadSize) == FALSE) {
+                success = FALSE;
+            }
+        }
+        osal_free(buf);
+
+        ret = VPU_EncUpdateBitstreamBuffer(*handle, loadSize);
+        if( ret != RETCODE_SUCCESS ) {
+            VLOG(ERR, "VPU_EncUpdateBitstreamBuffer failed Error code is 0x%x \n", ret );
+            success = FALSE;
+        }
+    }
+
+    return success;
+}
+
+BOOL BitstreamReader_Destroy(
+    BitstreamReader reader
+    )
+{
+    AbstractBitstreamReader* absReader = (AbstractBitstreamReader*)reader;
+
+    if (reader == NULL) {
+        VLOG(ERR, "%s:%d Invalid handle\n", __FUNCTION__, __LINE__);
+        return FALSE;
+    }
+
+    osal_fclose(absReader->fp);
+    osal_free(absReader);
+
+    return TRUE;
+}
+

+ 144 - 0
wave420l/code/sample/helper/bitstream/bsfeeder_fixedsize_impl.c

@@ -0,0 +1,144 @@
+//--=========================================================================--
+//  This file is a part of VPU Reference API project
+//-----------------------------------------------------------------------------
+//
+//       This confidential and proprietary software may be used only
+//     as authorized by a licensing agreement from Chips&Media Inc.
+//     In the event of publication, the following notice is applicable:
+//
+//            (C) COPYRIGHT CHIPS&MEDIA INC.
+//                      ALL RIGHTS RESERVED
+//
+//       The entire notice above must be reproduced on all authorized
+//       copies.
+//
+//--=========================================================================--
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <errno.h>
+
+#include "vpuapifunc.h"
+#include "main_helper.h"
+
+#define MAX_FEEDING_SIZE        0x400000        /* 4MBytes */
+
+typedef struct struct_ReaderConext {
+    osal_file_t*    fp;
+    Uint32          feedingSize;
+    BOOL            eos;
+} ReaderContext;
+
+void* BSFeederFixedSize_Create(
+    const char* path,
+    Uint32      feedingSize
+    )
+{
+    osal_file_t*    fp = NULL;
+    ReaderContext*  context=NULL;
+
+    if ((fp=osal_fopen(path, "rb")) == NULL) {
+        VLOG(ERR, "%s:%d failed to open %s\n", __FUNCTION__, __LINE__, path);
+        return NULL;
+    }
+
+    context = (ReaderContext*)osal_malloc(sizeof(ReaderContext));
+    if (context == NULL) {
+        VLOG(ERR, "%s:%d failed to allocate memory\n", __FUNCTION__, __LINE__);
+        osal_fclose(fp);
+        return NULL;
+    }
+
+    context->fp          = fp;
+    context->feedingSize = feedingSize;
+    context->eos         = FALSE;
+
+    return (void*)context;
+}
+
+BOOL BSFeederFixedSize_Destroy(
+    void* feeder
+    )
+{
+    ReaderContext* context = (ReaderContext*)feeder;
+
+    if (context == NULL) {
+        VLOG(ERR, "%s:%d Null handle\n", __FUNCTION__, __LINE__);
+        return FALSE;
+    }
+
+    if (context->fp) 
+        osal_fclose(context->fp);
+
+    osal_free(context);
+
+    return TRUE;
+}
+
+Int32 BSFeederFixedSize_Act(
+    void*       feeder,
+    BSChunk*    chunk
+    )
+{
+    ReaderContext*  context = (ReaderContext*)feeder;
+    size_t          nRead;
+    Uint32          size;
+    Uint32          feedingSize;
+
+    if (context == NULL) {
+        VLOG(ERR, "%s:%d Null handle\n", __FUNCTION__, __LINE__);
+        return 0;
+    }
+
+    if (context->eos == TRUE) {
+        chunk->eos = TRUE;
+        return 0;
+    }
+
+    feedingSize = context->feedingSize;
+    if (feedingSize == 0) {
+        Uint32  KB = 1024;
+        BOOL    probability10;
+
+        srand((Uint32)time(NULL));
+        feedingSize   = rand() % MAX_FEEDING_SIZE;
+        probability10 = (BOOL)((feedingSize%100) < 10);
+        if (feedingSize < KB) {
+            if (probability10 == FALSE) 
+                feedingSize *= 100;
+        }
+    }
+
+    size = (chunk->size < feedingSize) ? chunk->size : feedingSize;
+
+    do {
+        nRead = osal_fread(chunk->data, 1, size, context->fp);
+        if (nRead < 0) {
+            VLOG(ERR, "%s:%d failed to read bitstream(errno: %d)\n", __FUNCTION__, __LINE__, errno);
+            return 0;
+        } 
+        else if (nRead < size) {
+            context->eos = TRUE;
+            chunk->eos   = TRUE;
+        }
+    } while (FALSE);
+
+    return nRead;
+}
+
+BOOL BSFeederFixedSize_Rewind(
+    void*       feeder
+    )
+{
+    ReaderContext*  context = (ReaderContext*)feeder;
+    Int32           ret;
+
+    if ((ret=osal_fseek(context->fp, 0, SEEK_SET)) != 0) {
+        VLOG(ERR, "%s:%d Failed to fseek(ret: %d)\n", __FUNCTION__, __LINE__, ret);
+        return FALSE;
+    }
+    context->eos = FALSE;
+
+    return TRUE;
+}
+

+ 1061 - 0
wave420l/code/sample/helper/bitstream/bsfeeder_framesize_impl.c

@@ -0,0 +1,1061 @@
+//--=========================================================================--
+//  This file is a part of QC Tool project
+//-----------------------------------------------------------------------------
+//
+//       This confidential and proprietary software may be used only
+//     as authorized by a licensing agreement from Chips&Media Inc.
+//     In the event of publication, the following notice is applicable:
+//
+//            (C) COPYRIGHT 2004 - 2011   CHIPS&MEDIA INC.
+//                      ALL RIGHTS RESERVED
+//
+//       The entire notice above must be reproduced on all authorized
+//       copies.
+//
+//--=========================================================================--
+#include "main_helper.h"
+#ifdef SUPPORT_FFMPEG_DEMUX
+#include "theora_parser.h"
+#include <libavformat/avformat.h>
+
+#define RCV_V2
+#define IS_VP9_SUPERFRAME(__header)     ((__header & 0xe0) == 0xc0)
+#define MAX_VP9_SUPERFRAME_INDEX_SIZE   34
+#define VP9_MAX_SUBFRAMES               8
+
+typedef struct VP9Superframe {
+    Uint32  nframes;
+    Uint32  frameSize[VP9_MAX_SUBFRAMES];
+    void*   frames[VP9_MAX_SUBFRAMES];   /* A superframe has multiple frames up to 8 frames. */
+    Uint32  currentIndex;
+} VP9Superframe;
+
+typedef struct ReaderContext {
+    AVFormatContext*    avContext;
+    BOOL                isFirstPacket;
+    Uint32              videoIndex;
+    Uint32              standard;
+    Uint32              mp4ClassId;
+    tho_parser_t*       theora;
+    Uint8*              tempBuffer;
+    Uint32              tempRdPtr;
+    Uint32              tempWrPtr;
+    Uint32              seqWidth;
+    Uint32              seqHeight;
+    VP9Superframe       superframe;
+} ReaderContext;
+
+static Uint32 u_bytes(
+    Uint8*  data,
+    Uint32  len
+    )
+{
+    Uint32  i;
+    Uint32  val=0;
+
+    for (i=0; i<len; i++) {
+        val |= data[i] << (i*8);
+    }
+
+    return val;
+}
+
+static BOOL VP9ParseSuperframe(
+    void*           chunk,
+    Uint32          size,
+    VP9Superframe*  superframe
+    )
+{
+    Uint32  startPos;
+    Uint32  frameSizeLength = 0;
+    Uint32  numFrames, totalSubframeSize = 0;
+    Uint32  i;
+    Uint8*  pData = NULL, superframeMarker;
+
+    startPos = size - 1;
+
+    pData = (Uint8*)chunk;
+    pData = &pData[startPos];
+    superframeMarker = *pData;
+
+    frameSizeLength = ((*pData>>3) & 0x03) + 1;
+    numFrames       = (*pData&0x07) + 1;
+    pData           -= frameSizeLength * numFrames + 1;
+    /* Check first SUPERFRAME_MARKER */
+    if (*pData != superframeMarker) {
+        VLOG(ERR, "INVALID POST SUPERFRAME_MARKER\n");
+        return FALSE;
+    }
+    pData++;
+
+    for (i=0; i<numFrames; i++) {
+        superframe->frameSize[i] = u_bytes(pData, frameSizeLength);
+        pData += frameSizeLength;
+    }
+
+    /* Check size */
+    for (i=0; i<numFrames; i++) {
+        totalSubframeSize += superframe->frameSize[i];
+    }
+    if (totalSubframeSize >= size) {
+        VLOG(ERR, "TOTAL SIZE OF SUBFRAMES IS BIGGER THAN CHUNK SIZE\n");
+        return FALSE;
+    }
+
+    pData = (Uint8*)chunk;
+    for (i=0; i<numFrames; i++) {
+        superframe->frames[i] = (void*)osal_malloc(superframe->frameSize[i]);
+        osal_memcpy(superframe->frames[i], (void*)pData, superframe->frameSize[i]);
+        pData += superframe->frameSize[i];
+    }
+    superframe->currentIndex = 0;
+    superframe->nframes      = numFrames;
+
+    return TRUE;
+}
+
+static Int32 BuildSeqHeader(
+    Uint8*        pbHeader, 
+    const CodStd    codStd, 
+    const AVStream* st, 
+    Int32*        sizelength
+    )
+{
+    /*lint -save -e438 */
+    AVCodecContext* avc = st->codec;
+    Uint8*        pbMetaData = avc->extradata;
+    Int32         nMetaData = avc->extradata_size;
+    Uint8* p =    pbMetaData;
+    Uint8 *a =    p + 4 - ((long) p & 3);
+    Uint8* t =    pbHeader;	
+    Int32         size; 
+    Int32         fourcc;
+    Int32         sps, pps, i, nal;
+    Int32         frameRate = 0;
+
+    fourcc = avc->codec_tag;
+    if (!fourcc)
+        fourcc = ConvCodecIdToFourcc(avc->codec_id);
+
+    if (st->avg_frame_rate.den && st->avg_frame_rate.num)
+        frameRate = (Int32)((double)st->avg_frame_rate.num/(double)st->avg_frame_rate.den);
+
+    size = 0;
+    *sizelength = 4; // default size length(in bytes) = 4
+    if (codStd == STD_AVC || codStd == STD_AVS) {
+        if (nMetaData > 1 && pbMetaData && pbMetaData[0] == 0x01) {
+            // check mov/mo4 file format stream
+            p += 4;
+            *sizelength = (*p++ & 0x3) + 1;
+            sps = (*p & 0x1f); // Number of sps
+            p++;
+            for (i = 0; i < sps; i++) {
+                nal = (*p << 8) + *(p + 1) + 2;
+                PUT_BYTE(t, 0x00);
+                PUT_BYTE(t, 0x00);
+                PUT_BYTE(t, 0x00);
+                PUT_BYTE(t, 0x01);
+                PUT_BUFFER(t, p+2, nal-2);
+                p += nal;
+                size += (nal - 2 + 4); // 4 => length of start code to be inserted
+            }
+
+            pps = *(p++); // number of pps
+            for (i = 0; i < pps; i++)
+            {
+                nal = (*p << 8) + *(p + 1) + 2;
+                PUT_BYTE(t, 0x00);
+                PUT_BYTE(t, 0x00);
+                PUT_BYTE(t, 0x00);
+                PUT_BYTE(t, 0x01);
+                PUT_BUFFER(t, p+2, nal-2);
+                p += nal;
+                size += (nal - 2 + 4); // 4 => length of start code to be inserted
+            }
+        }
+        else if(nMetaData > 3) {
+            size = -1;// return to meaning of invalid stream data;		
+            for (; p < a; p++) {
+                if (p[0] == 0 && p[1] == 0 && p[2] == 1)  {
+                    // find startcode
+                    size = avc->extradata_size;
+                    PUT_BUFFER(pbHeader, pbMetaData, size);
+                    break;
+                }
+            }	
+        }
+    }
+    else if (codStd == STD_HEVC) {
+        if (nMetaData > 1 && pbMetaData && pbMetaData[0] == 0x01) {
+            static const Uint8 nalu_header[4] = { 0, 0, 0, 1 };
+            Int32 numOfArrays = 0;
+            Uint16 numNalus = 0;
+            Uint16 nalUnitLength = 0;
+            Uint32 offset = 0;
+
+            p += 21;
+            *sizelength = (*p++ & 0x3) + 1;
+            numOfArrays = *p++;
+
+            while(numOfArrays--) {
+                p++;   // NAL type
+                numNalus = (*p << 8) + *(p + 1);
+                p+=2;
+                for(i = 0;i < numNalus;i++)
+                {
+                    nalUnitLength = (*p << 8) + *(p + 1);
+                    p+=2;
+                    //if(i == 0)
+                    {	
+                        osal_memcpy(pbHeader + offset, nalu_header, 4);
+                        offset += 4;
+                        osal_memcpy(pbHeader + offset, p, nalUnitLength);	
+                        offset += nalUnitLength;
+                    }
+                    p += nalUnitLength;
+                }
+            }
+
+            size = offset;
+        }
+        else if(nMetaData > 3)
+        {
+            size = -1;// return to meaning of invalid stream data;		
+
+            for (; p < a; p++)
+            {
+                if (p[0] == 0 && p[1] == 0 && p[2] == 1) // find startcode
+                {
+                    size = avc->extradata_size;
+                    PUT_BUFFER(pbHeader, pbMetaData, size);
+                    break;
+                }
+            }	
+        }
+    }
+    else if (codStd == STD_VC1)
+    {
+        if (!fourcc)
+            return -1;
+        if (fourcc == MKTAG('W', 'V', 'C', '1') || fourcc == MKTAG('W', 'M', 'V', 'A'))	//VC AP
+        {
+            size = nMetaData;
+            PUT_BUFFER(pbHeader, pbMetaData, size);
+            //if there is no seq startcode in pbMetatData. VPU will be failed at seq_init stage.
+        }
+        else
+        {	
+#ifdef RCV_V2
+            PUT_LE32(pbHeader, ((0xC5 << 24)|0));
+            size += 4; //version
+            PUT_LE32(pbHeader, nMetaData);
+            size += 4;
+            PUT_BUFFER(pbHeader, pbMetaData, nMetaData);
+            size += nMetaData;
+            PUT_LE32(pbHeader, avc->height);
+            size += 4;
+            PUT_LE32(pbHeader, avc->width);
+            size += 4;
+            PUT_LE32(pbHeader, 12);
+            size += 4;
+            PUT_LE32(pbHeader, 2 << 29 | 1 << 28 | 0x80 << 24 | 1 << 0);
+            size += 4; // STRUCT_B_FRIST (LEVEL:3|CBR:1:RESERVE:4:HRD_BUFFER|24)
+            PUT_LE32(pbHeader, avc->bit_rate);
+            size += 4; // hrd_rate
+            PUT_LE32(pbHeader, frameRate);            
+            size += 4; // frameRate
+#else	//RCV_V1
+            PUT_LE32(pbHeader, (0x85 << 24) | 0x00);
+            size += 4; //frames count will be here
+            PUT_LE32(pbHeader, nMetaData);
+            size += 4;
+            PUT_BUFFER(pbHeader, pbMetaData, nMetaData);
+            size += nMetaData;
+            PUT_LE32(pbHeader, avc->height);
+            size += 4;
+            PUT_LE32(pbHeader, avc->width);
+            size += 4;
+#endif
+        }
+    }
+    else if (codStd == STD_RV)
+    {
+        Int32 st_size =0;
+
+        if (!fourcc)
+            return -1;
+        if (fourcc != MKTAG('R','V','3','0') && fourcc != MKTAG('R','V','4','0'))
+            return -1;
+
+        size = 26 + nMetaData;
+        PUT_BE32(pbHeader, size); //Length
+        PUT_LE32(pbHeader, MKTAG('V', 'I', 'D', 'O')); //MOFTag
+        PUT_LE32(pbHeader, fourcc); //SubMOFTagl
+        PUT_BE16(pbHeader, avc->width);
+        PUT_BE16(pbHeader, avc->height);
+        PUT_BE16(pbHeader, 0x0c); //BitCount;
+        PUT_BE16(pbHeader, 0x00); //PadWidth;
+        PUT_BE16(pbHeader, 0x00); //PadHeight;
+
+        PUT_LE32(pbHeader, frameRate);
+        PUT_BUFFER(pbHeader, pbMetaData, nMetaData); //OpaqueDatata
+        size += st_size; //add for startcode pattern.
+    }
+    else if (codStd == STD_DIV3) {
+        // not implemented yet
+        if (!nMetaData) {
+            PUT_LE32(pbHeader, MKTAG('C', 'N', 'M', 'V')); //signature 'CNMV'
+            PUT_LE16(pbHeader, 0x00);                      //version
+            PUT_LE16(pbHeader, 0x20);                      //length of header in bytes
+            PUT_LE32(pbHeader, MKTAG('D', 'I', 'V', '3')); //codec FourCC
+            PUT_LE16(pbHeader, avc->width);                //width
+            PUT_LE16(pbHeader, avc->height);               //height
+            PUT_LE32(pbHeader, st->avg_frame_rate.num);      //frame rate
+            PUT_LE32(pbHeader, st->avg_frame_rate.den);      //time scale(?)
+            PUT_LE32(pbHeader, st->nb_index_entries);      //number of frames in file
+            PUT_LE32(pbHeader, 0); //unused
+            size += 32;		
+            return size;
+        }
+
+        PUT_BE32(pbHeader, nMetaData);
+        size += 4;
+
+        PUT_BUFFER(pbHeader, pbMetaData, nMetaData);
+        size += nMetaData;
+    }
+
+    else if (codStd == STD_VP8) {
+        PUT_LE32(pbHeader, MKTAG('D', 'K', 'I', 'F')); //signature 'DKIF'
+        PUT_LE16(pbHeader, 0x00);                      //version
+        PUT_LE16(pbHeader, 0x20);                      //length of header in bytes
+        PUT_LE32(pbHeader, MKTAG('V', 'P', '8', '0')); //codec FourCC
+        PUT_LE16(pbHeader, avc->width);                //width
+        PUT_LE16(pbHeader, avc->height);               //height
+        PUT_LE32(pbHeader, st->avg_frame_rate.num);      //frame rate
+        PUT_LE32(pbHeader, st->avg_frame_rate.den);      //time scale(?)
+        PUT_LE32(pbHeader, st->nb_index_entries);      //number of frames in file
+        PUT_LE32(pbHeader, 0); //unused
+        size += 32;
+    }
+    else if (codStd == STD_VP9) {
+        PUT_LE32(pbHeader, MKTAG('D', 'K', 'I', 'F')); //signature 'DKIF'
+        PUT_LE16(pbHeader, 0x00);                      //version
+        PUT_LE16(pbHeader, 0x20);                      //length of header in bytes
+        PUT_LE32(pbHeader, MKTAG('V', 'P', '9', '0')); //codec FourCC
+        PUT_LE16(pbHeader, avc->width);                //width
+        PUT_LE16(pbHeader, avc->height);               //height
+        PUT_LE32(pbHeader, st->avg_frame_rate.num);      //frame rate
+        PUT_LE32(pbHeader, st->avg_frame_rate.den);      //time scale(?)
+        PUT_LE32(pbHeader, st->nb_index_entries);      //number of frames in file
+        PUT_LE32(pbHeader, 0); //unused
+        size += 32;
+    }
+    else {
+        PUT_BUFFER(pbHeader, pbMetaData, nMetaData);
+        size = nMetaData;
+    }
+
+    return size;
+    /*lint -restore */
+}
+
+static Int32 BuildPicHeader(
+    Uint8*        pbHeader, 
+    const CodStd    codStd, 
+    const AVStream* st, 
+    const AVPacket* pkt, 
+    Int32         sizelength
+    )
+{
+    AVCodecContext* avc = st->codec;
+    Uint8*        pbChunk = pkt->data;
+    Int32         size = 0;
+    Int32         fourcc;
+    Int32         cSlice, nSlice;
+    Int32         i, val, offset;
+    BOOL            hasStartCode = 0;
+
+    size = 0;
+    offset = 0;
+    fourcc = avc->codec_tag;
+    if (!fourcc)
+        fourcc = ConvCodecIdToFourcc(avc->codec_id);
+
+    if (codStd == STD_VC1) {
+        if (!fourcc)
+            return -1;
+
+        if (fourcc == MKTAG('W', 'V', 'C', '1') || fourcc == MKTAG('W', 'M', 'V', 'A')) {
+            if (pbChunk[0] != 0 || pbChunk[1] != 0 || pbChunk[2] != 1) {
+                // check start code as prefix (0x00, 0x00, 0x01)
+                pbHeader[0] = 0x00;
+                pbHeader[1] = 0x00;
+                pbHeader[2] = 0x01;
+                pbHeader[3] = 0x0D;	// replace to the correct picture header to indicate as frame				
+
+                size += 4;
+            }
+        }
+        else {
+            PUT_LE32(pbHeader, pkt->size | ((pkt->flags & AV_PKT_FLAG_KEY) ? 0x80000000 : 0));
+            size += 4;
+#ifdef RCV_V2
+            if (AV_NOPTS_VALUE == pkt->pts) {
+                PUT_LE32(pbHeader, 0);
+            }
+            else {
+                PUT_LE32(pbHeader, (int)((double)(pkt->pts/st->time_base.den))); // milli_sec
+            }
+            size += 4;
+#endif
+        }
+    }
+    else if (codStd == STD_HEVC) {
+        if(pkt->size < 5)
+            return 0;
+
+        if (!(avc->extradata_size > 1 && avc->extradata && avc->extradata[0] == 0x01))
+        {
+            const Uint8 *pbEnd = pbChunk + 4 - ((intptr_t)pbChunk & 3);
+
+            for (; pbChunk < pbEnd ; pbChunk++) {
+                if (pbChunk[0] == 0 && pbChunk[1] == 0 && pbChunk[2] == 1) {
+                    hasStartCode = TRUE;
+                    break;
+                }
+            }
+        }
+
+        if ((!hasStartCode && avc->extradata[0] == 0x01) || 
+            (avc->extradata_size > 1 && avc->extradata && avc->extradata[0] == 0x01)) {
+            // check sequence metadata if the stream is mov/mo4 file format.
+            pbChunk = pkt->data;
+            while (offset < pkt->size) {
+                if(sizelength == 3) {
+                    nSlice = pbChunk[offset] << 16 | pbChunk[offset+1] << 8 | pbChunk[offset+2];
+
+                    pbChunk[offset] = 0x00;
+                    pbChunk[offset+1] = 0x00;
+                    pbChunk[offset+2] = 0x01;
+
+                    offset += 3;
+                }
+                else {// sizeLength = 4
+                    nSlice = pbChunk[offset] << 24 | pbChunk[offset+1] << 16 | pbChunk[offset+2] << 8 | pbChunk[offset+3];
+
+                    pbChunk[offset] = 0x00;
+                    pbChunk[offset+1] = 0x00;
+                    pbChunk[offset+2] = 0x00;
+                    pbChunk[offset+3] = 0x01;		//replace size to startcode
+
+                    offset += 4;
+                }
+
+                switch ((pbChunk[offset]&0x7E)>>1) { /* NAL unit */
+                case 39: /* PREFIX SEI */
+                case 40: /* SUFFIX SEI */
+                case 32: /* VPS */
+                case 33: /* SPS */
+                case 34: /* PPS */
+                    /* check next */
+                    break;
+                }
+
+                offset += nSlice;
+            }			
+        }
+    }
+    else if (codStd == STD_RV) {
+        int st_size = 0;
+
+        if (!fourcc)
+            return -1;
+        if (fourcc != MKTAG('R','V','3','0') && fourcc != MKTAG('R','V','4','0')) // RV version 8, 9 , 10
+            return -1;
+
+        cSlice = pbChunk[0] + 1;
+        nSlice =  pkt->size - 1 - (cSlice * 8);
+        size = 20 + (cSlice*8);
+
+        PUT_BE32(pbHeader, nSlice);
+        if (AV_NOPTS_VALUE == pkt->pts) {
+            PUT_LE32(pbHeader, 0);
+        }
+        else {
+            PUT_LE32(pbHeader, (int)((double)(pkt->pts/st->time_base.den))); // milli_sec
+        }
+
+        PUT_BE16(pbHeader, avc->frame_number);
+        PUT_BE16(pbHeader, 0x02); //Flags
+        PUT_BE32(pbHeader, 0x00); //LastPacket
+        PUT_BE32(pbHeader, cSlice); //NumSegments
+        offset = 1;
+        for (i = 0; i < (int) cSlice; i++)
+        {
+            val = (pbChunk[offset+3] << 24) | (pbChunk[offset+2] << 16) | (pbChunk[offset+1] << 8) | pbChunk[offset];
+            PUT_BE32(pbHeader, val); //isValid
+            offset += 4;
+            val = (pbChunk[offset+3] << 24) | (pbChunk[offset+2] << 16) | (pbChunk[offset+1] << 8) | pbChunk[offset];
+            PUT_BE32(pbHeader, val); //Offset
+            offset += 4;
+        }
+
+        size += st_size;
+    }
+    else if (codStd == STD_AVC) {
+        if(pkt->size < 5)
+            return 0;
+
+        if (!(avc->extradata_size > 1 && avc->extradata && avc->extradata[0] == 0x01)) {
+            const Uint8 *pbEnd = pbChunk + 4 - ((intptr_t)pbChunk & 3);
+
+            for (; pbChunk < pbEnd ; pbChunk++) {
+                if (pbChunk[0] == 0 && pbChunk[1] == 0 && pbChunk[2] == 1) {
+                    hasStartCode = 1;
+                    break;
+                }
+            }
+        }
+
+        if ((!hasStartCode && avc->extradata[0] == 0x01) || 
+            (avc->extradata_size > 1 && avc->extradata && avc->extradata[0] == 0x01)) {
+            // check sequence metadata if the stream is mov/mo4 file format.
+            pbChunk = pkt->data;
+
+            while (offset < pkt->size) {
+                if(sizelength == 3) {
+                    nSlice = pbChunk[offset] << 16 | pbChunk[offset+1] << 8 | pbChunk[offset+2];
+                    pbChunk[offset] = 0x00;
+                    pbChunk[offset+1] = 0x00;
+                    pbChunk[offset+2] = 0x01;
+                    offset += 3;
+                }
+                else {  // size length = 4
+                    nSlice = pbChunk[offset] << 24 | pbChunk[offset+1] << 16 | pbChunk[offset+2] << 8 | pbChunk[offset+3];
+                    pbChunk[offset] = 0x00;
+                    pbChunk[offset+1] = 0x00;
+                    pbChunk[offset+2] = 0x00;
+                    pbChunk[offset+3] = 0x01;		//replace size to startcode
+                    offset += 4;
+                }
+
+                switch (pbChunk[offset]&0x1f) { /* NAL unit */
+                case 6: /* SEI */
+                case 7: /* SPS */
+                case 8: /* PPS */
+                case 9: /* AU */
+                    /* check next */
+                    break;
+                }
+
+                offset += nSlice;
+            }			
+        }
+    }
+    else if(codStd == STD_AVS) {
+        const Uint8* pbEnd;
+
+        if(pkt->size < 5)
+            return 0;
+
+        pbEnd = pbChunk + 4 - ((intptr_t)pbChunk & 3);
+
+        for (; pbChunk < pbEnd ; pbChunk++) {
+            if (pbChunk[0] == 0 && pbChunk[1] == 0 && pbChunk[2] == 1) {
+                hasStartCode = 1;
+                break;
+            }
+        }
+
+        if(hasStartCode == 0) {
+            pbChunk = pkt->data;
+
+            while (offset < pkt->size) {
+                nSlice = pbChunk[offset] << 24 | pbChunk[offset+1] << 16 | pbChunk[offset+2] << 8 | pbChunk[offset+3];
+
+                pbChunk[offset]   = 0x00;
+                pbChunk[offset+1] = 0x00;
+                pbChunk[offset+2] = 0x00;
+                pbChunk[offset+3] = 0x00;		//replace size to startcode
+                pbChunk[offset+4] = 0x01;
+
+                offset += 4;
+
+                switch (pbChunk[offset]&0x1f) /* NAL unit */
+                {
+                case 6: /* SEI */
+                case 7: /* SPS */
+                case 8: /* PPS */
+                case 9: /* AU */
+                    /* check next */
+                    break;
+                }
+
+                offset += nSlice;
+            }			
+        }
+    }
+    else if (codStd == STD_DIV3 || codStd == STD_VP8 || codStd == STD_VP9) {
+        PUT_LE32(pbHeader,pkt->size);
+        PUT_LE32(pbHeader,0);
+        PUT_LE32(pbHeader,0);
+        size += 12;
+    }
+    return size;
+}
+
+static Int32 MakeupTheoraPacket(
+    tho_parser_t*   theora,
+    BSChunk*        packet,
+    AVPacket*       avPacket,
+    Uint32        seqSize 
+    )
+{
+    size_t size;
+    Int32 ret;
+    Uint8* stream = (Uint8*)packet->data;
+
+    ret = theora->read_frame(theora->handle, avPacket->data, avPacket->size);
+    if (ret < 0) {
+        VLOG(ERR, "%s:%d failed to read theora frame\n", __FUNCTION__, __LINE__);
+        return -1;
+    }
+
+    size = theora_make_stream(theora->handle, stream+seqSize, PIC_RUN);
+
+    return (size + seqSize);
+}
+
+
+void* BSFeederFrameSize_Create(
+    const char* path,
+    CodStd      codecId,
+    CodStd*     retCodecId,
+    Uint32*     retMp4ClassId,
+    Uint32*     retSeqWidth,
+    Uint32*     retSeqHeight
+    )
+{
+    /*lint -esym(438, avContext) */
+    ReaderContext*    ffmpegReader = NULL;
+    AVFormatContext*  avContext    = NULL;
+    AVCodecContext*   codec        = NULL;
+    AVInputFormat*    fmt          = NULL;
+    Int32             error;
+    Int32             videoIndex;
+    Uint32            mp4ClassId;
+    Int32             standard;
+
+    av_register_all();
+    if ((avContext=avformat_alloc_context()) == NULL) {
+        return NULL;
+    }
+
+    avContext->flags |= CODEC_FLAG_TRUNCATED;
+    if ((error=avformat_open_input(&avContext, path, fmt, NULL))) {
+        VLOG(ERR, "%s:%d failed to av_open_input_file error(%d), %s\n",
+             __FILE__, __LINE__, error, path);
+        goto __failed_to_end;
+    }
+
+    if ((error=avformat_find_stream_info(avContext, NULL)) < 0) {
+        VLOG(ERR, "%s:%d failed to avformat_find_stream_info. error(%d)\n",
+            __FUNCTION__, __LINE__, error);
+        goto __failed_to_end;
+    }
+
+    videoIndex = av_find_best_stream(avContext, AVMEDIA_TYPE_VIDEO, -1, -1, NULL, 0);
+    if (videoIndex < 0) {
+        VLOG(ERR, "%s:%d failed to av_find_best_stream.\n", __FUNCTION__, __LINE__);
+        goto __failed_to_end;
+    }
+
+    codec = avContext->streams[videoIndex]->codec;
+    standard = ConvFOURCCToCodStd(codec->codec_tag);
+
+    if (standard == -1) 
+        standard = ConvCodecIdToCodStd(codec->codec_id);
+
+    mp4ClassId = ConvFOURCCToMp4Class(codec->codec_tag);
+    if (mp4ClassId == -1) 
+        mp4ClassId = ConvCodecIdToMp4Class(codec->codec_id);
+
+    if (standard != STD_MPEG4) {
+        mp4ClassId = 0;
+    }
+
+    if (retCodecId != NULL) {
+        *retCodecId = (CodStd)standard;
+    }
+    if (retMp4ClassId != NULL) {
+        *retMp4ClassId = mp4ClassId;
+    }
+
+    if (retSeqWidth != NULL && retSeqHeight != NULL) {
+        *retSeqWidth  = codec->width;
+        *retSeqHeight = codec->height;
+    }
+
+    if ((ffmpegReader=(ReaderContext*)osal_malloc(sizeof(ReaderContext))) == NULL)
+        goto __failed_to_end;
+
+    ffmpegReader->standard      = standard;
+    ffmpegReader->mp4ClassId    = mp4ClassId;
+    ffmpegReader->avContext     = avContext;
+    ffmpegReader->videoIndex    = videoIndex;
+    ffmpegReader->isFirstPacket = TRUE;
+    ffmpegReader->tempBuffer    = NULL;
+    ffmpegReader->tempRdPtr     = 0;
+    ffmpegReader->tempWrPtr     = 0;
+    ffmpegReader->theora        = NULL;
+    osal_memset((void*)&ffmpegReader->superframe, 0x00, sizeof(VP9Superframe));
+
+    if (standard == STD_THO || standard == STD_VP3) {
+        theora_parser_init((void**)&ffmpegReader->theora);
+    }
+
+    return (void*)ffmpegReader;
+
+__failed_to_end:
+    if (avContext) {
+        avformat_free_context(avContext);
+        avContext = NULL;
+    }
+
+    if (ffmpegReader) {
+        if (ffmpegReader->theora) 
+            ffmpegReader->theora->close(ffmpegReader->theora);
+        osal_free(ffmpegReader);
+    }
+
+    return NULL;
+    /*lint +esym(438, avContext) */
+}
+
+BOOL BSFeederFrameSize_Destroy(
+    void*   feeder
+    )
+{
+    ReaderContext*  ctx = (ReaderContext*)feeder;
+    Uint32          i;
+
+
+    if (ctx == NULL) {
+        VLOG(ERR, "%s:%d Invalid handle\n", __FUNCTION__, __LINE__);
+        return FALSE;
+    }
+
+    if (ctx->avContext)
+        avformat_close_input(&ctx->avContext);
+
+    if (ctx->theora)
+        ctx->theora->close(ctx->theora);
+
+    for (i=0; i<ctx->superframe.nframes; i++) {
+        if (ctx->superframe.frames[i] != NULL) {
+            free(ctx->superframe.frames[i]);
+        }
+    }
+
+    osal_free(ctx);
+
+    return TRUE;
+}
+
+Int32 BSFeederFrameSize_Act(
+    void*       feeder,
+    BSChunk*    packet
+    )
+{
+    ReaderContext*      ffmpegReader = (ReaderContext*)feeder;
+    AVFormatContext*    avFormatContext = ffmpegReader->avContext;
+    AVPacket            avpacket;
+    Int32               error;
+    Uint8*              seqHeader = NULL;
+    Uint8*              picHeader = NULL;
+    Uint8*              ptr;
+    Int32               seqHeaderSize;
+    Int32               picHeaderSize;
+    Uint32              vindex, size, thoSeqSize;
+    Int32               retSize = -1;
+    Int32               packetSize = -1;
+
+
+    if (ffmpegReader->tempBuffer) {
+        goto __consume_tempBuffer;
+    }
+
+    if (ffmpegReader->standard == STD_VP9) {
+        VP9Superframe* superframe = &ffmpegReader->superframe;
+        if (superframe->nframes > 0) {
+            Uint32 index = superframe->currentIndex;
+            if (index < superframe->nframes) {
+                osal_memcpy(packet->data, superframe->frames[index], superframe->frameSize[index]);
+                packet->size = superframe->frameSize[index];
+                superframe->currentIndex++;
+                return packet->size;
+            }
+            else {
+                Uint32 i;
+                for (i=0; i<VP9_MAX_SUBFRAMES; i++) {
+                    if (superframe->frames[i] != NULL) {
+                        osal_free(superframe->frames[i]);
+                    }
+                }
+                osal_memset((void*)superframe, 0x00, sizeof(VP9Superframe));
+            }
+        }
+    }
+
+    seqHeaderSize = 0;
+    picHeaderSize = 0;
+    thoSeqSize    = 0;
+
+    av_init_packet(&avpacket);
+    while (TRUE) {
+        error = av_read_frame(avFormatContext, &avpacket);
+        if (error < 0) {
+            if (error == AVERROR_EOF || avFormatContext->pb->eof_reached == TRUE) {
+                packet->eos = TRUE;
+                return 0;
+            }
+            else {
+                VLOG(ERR, "%s:%d failed to av_read_frame error(0x%08x)\n", 
+                    __FUNCTION__, __LINE__, error);
+                goto __end_read;
+            }
+        } 
+
+        if (avpacket.stream_index != ffmpegReader->videoIndex) 
+            continue;
+
+        break;
+    }
+
+    if (avpacket.size == 0) 
+        return 0;
+
+    if (avpacket.size >= (signed)packet->size )
+    {
+        VLOG(ERR, "one packet size(%d) is bigger than STREAM_BUF_SIZE(%d)\n", avpacket.size, packet->size);
+        return -1;
+    }
+   
+    osal_memset(packet->data, 0x00, packet->size);
+
+    vindex = ffmpegReader->videoIndex;
+
+    if (ffmpegReader->isFirstPacket) {
+        AVCodecContext* codec;
+        tho_parser_t*   theora = ffmpegReader->theora;
+        Int32         ret;
+        struct {
+            int frameWidth     ;
+            int frameHeight    ;
+            int picWidth       ;
+            int picHeight      ;
+            int picOffsetX     ;
+            int picOffsetY     ;
+        } theoraScaleInfo;
+
+        codec = ffmpegReader->avContext->streams[vindex]->codec;
+        seqHeader = (Uint8*)osal_malloc(codec->extradata_size + 1024);
+        if (seqHeader == NULL) {
+            goto __end_read;
+        }
+        osal_memset((void*)seqHeader, 0x00, codec->extradata_size + 1024);
+
+        seqHeaderSize = BuildSeqHeader(seqHeader, (CodStd)ffmpegReader->standard,
+                                       ffmpegReader->avContext->streams[vindex], &retSize);
+        if (seqHeaderSize < 0) {
+            VLOG(ERR, "%s:%d Can't make sequence header!\n", __FUNCTION__, __LINE__);
+            packetSize = -1;
+            goto __end_read;
+        }
+
+        if (ffmpegReader->standard == STD_THO || ffmpegReader->standard == STD_VP3) {
+            size = seqHeaderSize;
+            if (ffmpegReader->standard == STD_VP3) {
+                size = 0;
+            }
+
+            ret = theora->open(theora->handle, seqHeader, size, (Int32*)&theoraScaleInfo);
+            if (ret < 0) {
+                VLOG(ERR, "%s:%d failed to open theora parser error(%d)\n", __FUNCTION__, __LINE__, ret);
+                goto __end_read;
+            }
+
+            thoSeqSize = theora_make_stream(theora->handle, (Uint8*)packet->data, DEC_SEQ_INIT);
+
+            osal_free(seqHeader);
+            seqHeader     = NULL;
+            seqHeaderSize = 0;
+        } 
+
+        ffmpegReader->isFirstPacket = FALSE;
+    }
+
+    picHeader     = (Uint8*)osal_malloc(1024);
+    picHeaderSize = BuildPicHeader(picHeader, (CodStd)ffmpegReader->standard,
+                                   ffmpegReader->avContext->streams[vindex], &avpacket, 0);
+    if (picHeaderSize < 0) {
+        VLOG(ERR, "%s:%d failed to build picture header\n", __FUNCTION__, __LINE__);
+        goto __end_read;
+    }
+
+    ptr  = avpacket.data;
+    size = avpacket.size;
+    switch (ffmpegReader->standard) {
+    case STD_RV:
+        if (seqHeaderSize)
+            osal_memcpy((char*)packet->data, seqHeader, seqHeaderSize);
+
+        if (picHeaderSize)
+            osal_memcpy((char*)packet->data+seqHeaderSize, picHeader, picHeaderSize);
+
+        if (ffmpegReader->standard == STD_RV) {
+            int cSlice = ptr[0] + 1;
+            int nSlice = avpacket.size - 1 - (cSlice*8);
+            ptr += (1+(cSlice*8));
+            size = nSlice;
+        }
+
+        osal_memcpy((char*)packet->data+seqHeaderSize+picHeaderSize, ptr, size);
+        packetSize = seqHeaderSize + picHeaderSize + size;
+        break;
+    case STD_THO:
+    case STD_VP3:
+        packetSize = MakeupTheoraPacket(ffmpegReader->theora, packet, &avpacket, thoSeqSize);
+        break;
+    case STD_VP9:
+        packet->size    = size;
+        osal_memcpy((char *)packet->data, ptr, size);
+        packetSize      = size;
+        break;
+    default:
+        if (picHeaderSize)
+            osal_memcpy((char*)packet->data, picHeader, picHeaderSize);
+
+        osal_memcpy((char*)packet->data+picHeaderSize, ptr, size);
+        packetSize = picHeaderSize + size;
+        break;
+    }
+
+    if (avFormatContext->pb->eof_reached && avFormatContext->packet_buffer == NULL) {
+        packet->eos = TRUE;
+    }
+
+    // Sequence header data should be only one chunk data unit.
+    // In case of RV, 1st chunk should be Sequence header + 1st frame.
+    if (ffmpegReader->standard != STD_VP9 && ffmpegReader->standard != STD_RV) {
+        if (seqHeaderSize > 0) { 
+            ffmpegReader->tempBuffer = (Uint8*)osal_malloc(packetSize);
+            ffmpegReader->tempWrPtr  = packetSize;
+            osal_memcpy(ffmpegReader->tempBuffer, (Uint8*)(packet->data), packetSize);
+            osal_memcpy(packet->data, seqHeader, seqHeaderSize);
+            packetSize = seqHeaderSize;
+            goto __end_read;
+        }
+    }
+    else if (ffmpegReader->standard == STD_VP9) {
+        Uint8*  pData = (Uint8*)packet->data;
+        Uint32  lastIndex = packet->size - 1;
+
+        if (IS_VP9_SUPERFRAME(pData[lastIndex]) == TRUE) {
+            VP9Superframe*  superframe = &ffmpegReader->superframe;
+            if (VP9ParseSuperframe(pData, packet->size, superframe) == TRUE) {
+                osal_memcpy(packet->data, superframe->frames[0], superframe->frameSize[0]);
+                packet->size = superframe->frameSize[0];
+                packetSize   = packet->size;
+                superframe->currentIndex++;
+            }
+        }
+    }
+
+__end_read:
+    av_free_packet(&avpacket);
+
+    if (picHeader)
+        osal_free(picHeader);
+    if (seqHeader)
+        osal_free(seqHeader);
+
+    return packetSize;
+
+__consume_tempBuffer:
+    if (ffmpegReader->tempBuffer != NULL) {
+        osal_memcpy(packet->data, ffmpegReader->tempBuffer, ffmpegReader->tempWrPtr);
+        packetSize = ffmpegReader->tempWrPtr;
+        osal_free(ffmpegReader->tempBuffer);
+        ffmpegReader->tempBuffer = NULL;
+        ffmpegReader->tempWrPtr  = 0;
+        ffmpegReader->tempRdPtr  = 0;
+    }
+
+    return packetSize;
+}
+
+BOOL BSFeederFrameSize_Rewind(
+    void* feeder
+    )
+{
+    ReaderContext*      ffmpegReader = (ReaderContext*)feeder;
+    AVFormatContext*    avFormatContext = ffmpegReader->avContext;
+    Int32               ret;
+
+    if ((ret=av_seek_frame(avFormatContext, ffmpegReader->videoIndex, 0, 0)) < 0) {
+        VLOG(ERR, "%s:%d Failed to av_seek_frame:(ret:%d)\n", __FUNCTION__, __LINE__, ret);
+        return FALSE;
+    }
+
+    return TRUE;
+}
+#else
+void* BSFeederFrameSize_Create(
+    const char* path,
+    CodStd  codecId,
+    CodStd* retCodecId,
+    Uint32* retMp4ClassId,
+    Uint32* retSeqWidth,
+    Uint32* retSeqHeight
+    )
+{
+    UNREFERENCED_PARAMETER(path);
+    UNREFERENCED_PARAMETER(codecId);
+    UNREFERENCED_PARAMETER(retCodecId);
+    UNREFERENCED_PARAMETER(retMp4ClassId);
+    UNREFERENCED_PARAMETER(retSeqWidth);
+    UNREFERENCED_PARAMETER(retSeqHeight);
+
+    VLOG(ERR, "PLEASE PORT THIS %s ON YOUR ANDROID SYSTEM\n", __FUNCTION__);
+
+    return NULL;
+}
+
+BOOL BSFeederFrameSize_Destroy(
+    void*   feeder
+    )
+{
+    UNREFERENCED_PARAMETER(feeder);
+
+    VLOG(ERR, "PLEASE PORT THIS %s ON YOUR ANDROID SYSTEM\n", __FUNCTION__);
+
+    return FALSE;
+}
+
+Int32 BSFeederFrameSize_Act(
+    void*       feeder,
+    BSChunk*    packet
+    )
+{
+    UNREFERENCED_PARAMETER(feeder);
+    UNREFERENCED_PARAMETER(packet);
+
+    VLOG(ERR, "PLEASE PORT THIS %s ON YOUR ANDROID SYSTEM\n", __FUNCTION__);
+
+    return -1;
+}
+
+#endif /* SUPPORT_FFMPEG_DEMUX */
+

+ 124 - 0
wave420l/code/sample/helper/bitstream/bsfeeder_size_plus_es_impl.c

@@ -0,0 +1,124 @@
+//--=========================================================================--
+//  This file is a part of VPU Reference API project
+//-----------------------------------------------------------------------------
+//
+//       This confidential and proprietary software may be used only
+//     as authorized by a licensing agreement from Chips&Media Inc.
+//     In the event of publication, the following notice is applicable:
+//
+//            (C) COPYRIGHT CHIPS&MEDIA INC.
+//                      ALL RIGHTS RESERVED
+//
+//       The entire notice above must be reproduced on all authorized
+//       copies.
+//
+//--=========================================================================--
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <errno.h>
+
+#include "vpuapifunc.h"
+#include "main_helper.h"
+
+#define MAX_FEEDING_SIZE        0x400000        /* 4MBytes */
+
+typedef struct struct_ReaderConext {
+    osal_file_t fp;
+    Uint32      feedingSize;
+    BOOL        eos;
+} ReaderContext;
+
+void* BSFeederSizePlusEs_Create(
+    const char* path
+    )
+{
+    osal_file_t     fp = NULL;
+    ReaderContext*  context=NULL;
+
+    if ((fp=osal_fopen(path, "rb")) == NULL) {
+        VLOG(ERR, "%s:%d failed to open %s\n", __FUNCTION__, __LINE__, path);
+        return NULL;
+    }
+
+    context = (ReaderContext*)osal_malloc(sizeof(ReaderContext));
+    if (context == NULL) {
+        VLOG(ERR, "%s:%d failed to allocate memory\n", __FUNCTION__, __LINE__);
+        osal_fclose(fp);
+        return NULL;
+    }
+
+    context->fp          = fp;
+    context->feedingSize = 0;
+    context->eos         = FALSE;
+
+    return (void*)context;
+}
+
+BOOL BSFeederSizePlusEs_Destroy(
+    void* feeder
+    )
+{
+    ReaderContext* context = (ReaderContext*)feeder;
+
+    if (context == NULL) {
+        VLOG(ERR, "%s:%d Null handle\n", __FUNCTION__, __LINE__);
+        return FALSE;
+    }
+
+    if (context->fp) 
+        osal_fclose(context->fp);
+
+    osal_free(context);
+
+    return TRUE;
+}
+
+Int32 BSFeederSizePlusEs_Act(
+    void*       feeder,
+    BSChunk*    chunk
+    )
+{
+    ReaderContext*  context = (ReaderContext*)feeder;
+    size_t          nRead;
+    Uint32          chunkSize = 0;
+
+    if (context == NULL) {
+        VLOG(ERR, "%s:%d Null handle\n", __FUNCTION__, __LINE__);
+        return FALSE;
+    }
+
+    if (context->eos == TRUE) {
+        return 0;
+    }
+
+    osal_fread(&chunkSize, 1, 4, context->fp);
+
+    nRead = osal_fread(chunk->data, 1, chunkSize, context->fp);
+    if (nRead < 0) {
+        VLOG(ERR, "%s:%d failed to read bitstream(errno: %d)\n", __FUNCTION__, __LINE__, errno);
+        return 0;
+    } 
+    else if (nRead < chunkSize) {
+        context->eos = TRUE;
+    }
+    chunk->size = chunkSize;
+
+    return nRead;
+}
+
+BOOL BSFeederSizePlusEs_Rewind(
+    void*       feeder
+    )
+{
+    ReaderContext*  context = (ReaderContext*)feeder;
+    Int32           ret;
+
+    if ((ret=osal_fseek(context->fp, 0, SEEK_SET)) != 0) {
+        VLOG(ERR, "%s:%d failed osal_fseek(ret:%d)\n", __FUNCTION__, __LINE__, ret);
+        return FALSE;
+    }
+
+    return TRUE;
+}
+

+ 140 - 0
wave420l/code/sample/helper/comparator/bin_comparator_impl.c

@@ -0,0 +1,140 @@
+//--=========================================================================--
+//  This file is a part of VPU Reference API project
+//-----------------------------------------------------------------------------
+//
+//       This confidential and proprietary software may be used only
+//     as authorized by a licensing agreement from Chips&Media Inc.
+//     In the event of publication, the following notice is applicable:
+//
+//            (C) COPYRIGHT CHIPS&MEDIA INC.
+//                      ALL RIGHTS RESERVED
+//
+//       The entire notice above must be reproduced on all authorized
+//       copies.
+//
+//--=========================================================================--
+
+#include "config.h"
+#include "main_helper.h"
+
+typedef struct {
+    FILE*       fp;
+} Context;
+
+BOOL BinComparator_Create(
+    ComparatorImpl* impl,
+    char*           path
+    )
+{
+    Context*    ctx;
+    FILE*       fp;
+
+    if ((fp=osal_fopen(path, "rb")) == NULL) {
+        VLOG(ERR, "%s:%d failed to open bin file: %s\n", __FUNCTION__, __LINE__, path);
+        return FALSE;
+    }
+
+    if ((ctx=(Context*)osal_malloc(sizeof(Context))) == NULL) {
+        osal_fclose(fp);
+        return FALSE;
+    }
+
+    ctx->fp        = fp;
+    impl->context  = ctx;
+    impl->eof      = FALSE;
+
+    return TRUE;
+}
+
+BOOL BinComparator_Destroy(
+    ComparatorImpl*  impl
+    )
+{
+    Context*    ctx = (Context*)impl->context;
+
+    osal_fclose(ctx->fp);
+    osal_free(ctx);
+
+    return TRUE;
+}
+
+BOOL BinComparator_Compare(
+    ComparatorImpl* impl,
+    void*           data,
+    Uint32          size
+    )
+{
+    Uint8*      pBin = NULL;
+    Context*    ctx = (Context*)impl->context;
+    BOOL        match = FALSE;
+
+    pBin = (Uint8*)osal_malloc(size);
+        
+    osal_fread(pBin, size, 1, ctx->fp);
+
+    if (IsEndOfFile(ctx->fp) == TRUE)
+        impl->eof = TRUE;
+    else
+        impl->numOfFrames++;
+
+    match = (osal_memcmp(data, (void*)pBin, size) == 0 ? TRUE : FALSE);
+    if (match == FALSE) {
+        FILE* fpGolden;
+        FILE* fpOutput;
+        char tmp[200];
+
+        if ( impl->curIndex == 1 )//because of header
+            VLOG(ERR, "MISMATCH WITH GOLDEN bin at header\n");
+        else
+            VLOG(ERR, "MISMATCH WITH GOLDEN bin at %d frame\n", impl->curIndex - 1);
+
+        sprintf(tmp, "./golden_%s_%05d.bin", GetBasename(impl->filename), impl->curIndex-1);
+        if ((fpGolden=osal_fopen(tmp, "wb")) == NULL) {
+            VLOG(ERR, "Faild to create %s\n", tmp);
+            osal_free(pBin);
+            return FALSE;
+        }
+        VLOG(ERR, "Saving... Golden Bin at %s\n", tmp);
+        osal_fwrite(pBin, size, 1, fpGolden);
+        osal_fclose(fpGolden);
+
+        sprintf(tmp, "./encoded_%s_%05d.bin", GetBasename(impl->filename), impl->curIndex-1);
+        if ((fpOutput=osal_fopen(tmp, "wb")) == NULL) {
+            VLOG(ERR, "Faild to create %s\n", tmp);
+            osal_free(pBin);
+            return FALSE;
+        }
+        VLOG(ERR, "Saving... encoded Bin at %s\n", tmp);
+        osal_fwrite(data, size, 1, fpOutput);
+        osal_fclose(fpOutput);
+    }
+
+    osal_free(pBin);
+
+    return match;
+}
+
+BOOL BinComparator_Configure(
+    ComparatorImpl*     impl,
+    ComparatorConfType  type,
+    void*               val
+    )
+{
+    UNREFERENCED_PARAMETER(impl);
+    UNREFERENCED_PARAMETER(type);
+    UNREFERENCED_PARAMETER(val);
+    return FALSE;
+}
+
+ComparatorImpl binComparatorImpl = {
+    NULL,
+    NULL,
+    0,
+    0,
+    BinComparator_Create,
+    BinComparator_Destroy,
+    BinComparator_Compare,
+    BinComparator_Configure,
+    FALSE,
+};
+ 

+ 339 - 0
wave420l/code/sample/helper/comparator/comparator.c

@@ -0,0 +1,339 @@
+//--=========================================================================--
+//  This file is a part of VPU Reference API project
+//-----------------------------------------------------------------------------
+//
+//       This confidential and proprietary software may be used only
+//     as authorized by a licensing agreement from Chips&Media Inc.
+//     In the event of publication, the following notice is applicable:
+//
+//            (C) COPYRIGHT CHIPS&MEDIA INC.
+//                      ALL RIGHTS RESERVED
+//
+//       The entire notice above must be reproduced on all authorized
+//       copies.
+//
+//--=========================================================================--
+
+#include <stdarg.h>
+#include "main_helper.h"
+#include "../misc/skip.h"
+
+
+extern ComparatorImpl binComparatorImpl;
+extern ComparatorImpl yuvComparatorImpl;
+
+static BOOL NullComparator_Create(
+    ComparatorImpl* impl,
+    char*           path
+    )
+{
+    UNREFERENCED_PARAMETER(impl);
+    UNREFERENCED_PARAMETER(path);
+    return TRUE;
+}
+
+static BOOL NullComparator_Destroy(
+    ComparatorImpl*  impl
+    )
+{
+    UNREFERENCED_PARAMETER(impl);
+
+    return TRUE;
+}
+
+static BOOL NullComparator_Compare(
+    ComparatorImpl* impl,
+    void*           data,
+    Uint32          size
+    )
+{
+    UNREFERENCED_PARAMETER(impl);
+    UNREFERENCED_PARAMETER(data);
+    UNREFERENCED_PARAMETER(size);
+    return TRUE;
+}
+
+static BOOL NullComparator_Configure(
+    ComparatorImpl*     impl,
+    ComparatorConfType  cmd,
+    void*               val
+    )
+{
+    UNREFERENCED_PARAMETER(impl);
+    UNREFERENCED_PARAMETER(cmd);
+    UNREFERENCED_PARAMETER(val);
+
+    return TRUE;
+}
+
+static BOOL NullComparator_Rewind(
+    ComparatorImpl*     impl
+    )
+{
+    UNREFERENCED_PARAMETER(impl);
+    return TRUE;
+}
+
+ComparatorImpl nullComparatorImpl = {
+    NULL,
+    NULL,
+    0, 
+    0,
+    NullComparator_Create,
+    NullComparator_Destroy,
+    NullComparator_Compare,
+    NullComparator_Configure,
+    NullComparator_Rewind
+};
+
+BOOL BinComparator_Create(
+    ComparatorImpl* impl,
+    char*           path
+);
+
+BOOL BinComparator_Destroy(
+    ComparatorImpl*  impl
+);
+
+BOOL BinComparator_Compare(
+    ComparatorImpl* impl,
+    void*           data,
+    Uint32          size
+);
+
+BOOL BinComparator_Configure(
+    ComparatorImpl*     impl,
+    ComparatorConfType  type,
+    void*               val
+);
+
+BOOL YUVComparator_Create(
+    ComparatorImpl* impl,
+    char*           path
+);
+
+BOOL YUVComparator_Destroy(
+    ComparatorImpl*  impl
+);
+
+BOOL YUVComparator_Compare(
+    ComparatorImpl* impl,
+    void*           data,
+    Uint32          size
+);
+
+BOOL YUVComparator_Configure(
+    ComparatorImpl*    impl,
+    ComparatorConfType cmd,
+    void*              val
+);
+
+BOOL YUVComparator_Rewind(
+    ComparatorImpl*     impl
+    );
+
+Comparator Comparator_Create(
+    Uint32      type,
+    char*       goldenPath,
+    ...
+    )
+{
+    /*lint -esym(438, ap) */
+    AbstractComparator* comp;
+    ComparatorImpl* impl = NULL;
+    va_list         ap;
+    BOOL            success = FALSE;
+
+    if (type != NO_COMPARE && goldenPath == NULL) {
+        VLOG(ERR, "%s:%d golden path is NULL\n", __FUNCTION__, __LINE__);
+        return NULL;
+    }
+
+    switch (type) {
+    case NO_COMPARE:
+        impl = (ComparatorImpl*)osal_malloc(sizeof(ComparatorImpl));
+        osal_memset((void*)impl, 0x00, sizeof(ComparatorImpl));
+        impl->Create    = NullComparator_Create;
+        impl->Compare   = NullComparator_Compare;
+        impl->Destroy   = NullComparator_Destroy;
+        impl->Configure = NullComparator_Configure;
+        impl->Rewind    = NullComparator_Rewind;
+        success = impl->Create(impl, goldenPath);
+        break;
+    case YUV_COMPARE:
+        impl = (ComparatorImpl*)osal_malloc(sizeof(ComparatorImpl));
+        osal_memset((void*)impl, 0x00, sizeof(ComparatorImpl));
+        impl->Create    = YUVComparator_Create;
+        impl->Compare   = YUVComparator_Compare;
+        impl->Destroy   = YUVComparator_Destroy;
+        impl->Configure = YUVComparator_Configure;
+        impl->Rewind    = YUVComparator_Rewind;
+        if ((success=impl->Create(impl, goldenPath)) == TRUE) {
+            PictureInfo picInfo;
+            va_start(ap, goldenPath);
+            picInfo.width  = va_arg(ap, Uint32);
+            picInfo.height = va_arg(ap, Uint32);
+            picInfo.format = (FrameBufferFormat)va_arg(ap, Uint32);
+            picInfo.cbcrInterleave = va_arg(ap, BOOL);
+            picInfo.isVp9  = va_arg(ap, BOOL);
+            va_end(ap);
+            impl->Configure(impl, COMPARATOR_CONF_SET_PICINFO, (void*)&picInfo);
+        }
+        break;
+    case STREAM_COMPARE:
+        impl = osal_malloc(sizeof(ComparatorImpl));
+        osal_memset((void*)impl, 0x00, sizeof(ComparatorImpl));
+        impl->Create = &BinComparator_Create;
+        impl->Compare = &BinComparator_Compare;
+        impl->Destroy = &BinComparator_Destroy;
+        impl->Configure = &BinComparator_Configure;
+        va_start(ap, goldenPath);
+        impl->filename = va_arg(ap, char*);
+        va_end(ap);
+        success = impl->Create(impl, goldenPath);
+        break;
+    default:
+        VLOG(ERR, "Invalid comparison type:%d\n", type);
+        return NULL;
+    }
+
+    if (success == FALSE) 
+        return NULL;
+
+    comp = (AbstractComparator*)osal_malloc(sizeof(AbstractComparator));
+    impl->curIndex      = 0;
+    comp->impl          = impl;
+    comp->totalFrames   = impl->numOfFrames;
+
+    return comp;
+    /*lint +esym(438, ap) */
+}
+
+BOOL Comparator_Destroy(
+    Comparator  comp
+    )
+{
+    ComparatorImpl*     impl = NULL;
+    AbstractComparator* absComp = (AbstractComparator*)comp;
+
+    if (comp == NULL) {
+        VLOG(ERR, "%s:%d Invalid handle\n", __FUNCTION__, __LINE__);
+        return FALSE;
+    }
+
+    impl = absComp->impl;
+
+    impl->Destroy(impl);
+
+    osal_free(impl);
+
+    return TRUE;
+}
+
+BOOL Comparator_Act(
+    Comparator  comp,
+    void*       data,
+    Uint32      size
+    )
+{
+    ComparatorImpl*     impl = NULL;
+    AbstractComparator* absComp = (AbstractComparator*)comp;
+
+    if (comp == NULL) {
+        VLOG(ERR, "%s:%d Invalid handle\n", __FUNCTION__, __LINE__);
+        return FALSE;
+    }
+
+    impl = absComp->impl;
+    impl->curIndex++;
+    if (impl->usePrevDataOneTime == TRUE)
+        impl->curIndex--;
+
+    return impl->Compare(impl, data, size);
+}
+
+BOOL Comparator_CheckFrameCount(
+    Comparator  comp
+    )
+{
+    ComparatorImpl*     impl = NULL;
+    AbstractComparator* absComp = (AbstractComparator*)comp;
+    BOOL                match = TRUE;
+
+    if (comp == NULL) {
+        VLOG(ERR, "%s:%d Invalid handle\n", __FUNCTION__, __LINE__);
+        return FALSE;
+    }
+
+    impl = absComp->impl;
+
+    if (impl->curIndex != absComp->totalFrames) {
+        VLOG(ERR, "MISMATCH FRAME COUNT: GOLDEN(%d) DECODED(%d)\n", 
+            impl->numOfFrames, impl->curIndex);
+        match = FALSE;
+    }
+
+    return match;
+}
+
+/* \brief       When scan mode is enable, Comparator_Act() tries to find data matched with decoded result 
+ *              by scanning all data
+ */
+BOOL Comparator_SetScanMode(
+    Comparator  comp,
+    BOOL        enable
+    )
+{
+    AbstractComparator* absComp = (AbstractComparator*)comp;
+    ComparatorImpl*     impl = NULL;
+
+    if (absComp == NULL) {
+        return FALSE;
+    }
+    impl = absComp->impl;
+
+    impl->enableScanMode = enable;
+
+    return TRUE;
+}
+
+BOOL Comparator_Rewind(
+    Comparator  comp
+    )
+{
+    AbstractComparator* absComp = (AbstractComparator*)comp;
+    ComparatorImpl*     impl = NULL;
+
+    if (absComp == NULL) {
+        return FALSE;
+    }
+    impl                  = absComp->impl;
+    absComp->totalFrames += impl->numOfFrames;
+
+    return impl->Rewind(impl);
+}
+
+BOOL Comparator_CheckEOF(
+    Comparator  comp
+    )
+{
+    ComparatorImpl*     impl     = NULL;
+    AbstractComparator* absComp  = (AbstractComparator*)comp;
+    BOOL                match    = TRUE;
+
+    if (comp == NULL) {
+        VLOG(ERR, "%s:%d Invalid handle\n", __FUNCTION__, __LINE__);
+        return FALSE;
+    }
+
+    impl = absComp->impl;
+
+    if (impl->eof == FALSE) {
+        VLOG(ERR, "It is not the end of file.\n");
+        match = FALSE;
+    }
+
+    return match;
+}
+
+ 

+ 183 - 0
wave420l/code/sample/helper/comparator/md5_comparator_impl.c

@@ -0,0 +1,183 @@
+//--=========================================================================--
+//  This file is a part of VPU Reference API project
+//-----------------------------------------------------------------------------
+//
+//       This confidential and proprietary software may be used only
+//     as authorized by a licensing agreement from Chips&Media Inc.
+//     In the event of publication, the following notice is applicable:
+//
+//            (C) COPYRIGHT CHIPS&MEDIA INC.
+//                      ALL RIGHTS RESERVED
+//
+//       The entire notice above must be reproduced on all authorized
+//       copies.
+//
+//--=========================================================================--
+
+#include <errno.h>
+#include "main_helper.h"
+#include "../misc/skip.h"
+
+typedef struct {
+    osal_file_t     fp;
+    Uint32          md5Size;
+    Uint32          prevMd5[12];
+} Context;
+
+
+BOOL MD5Comparator_Create(
+    ComparatorImpl* impl,
+    char*           path
+    )
+{
+    Context*        ctx;
+    osal_file_t     fp;
+    Uint32        temp;
+
+    if ((fp=osal_fopen(path, "r")) == NULL) {
+        VLOG(ERR, "%s:%d failed to open md5 file: %s, errno(%d)\n", __FUNCTION__, __LINE__, path, errno);
+        return FALSE;
+    }
+
+    if ((ctx=(Context*)osal_malloc(sizeof(Context))) == NULL) {
+        osal_fclose(fp);
+        return FALSE;
+    }
+
+    while (!osal_feof(fp)) {
+        if (osal_fscanf((FILE*)fp, "%08x", &temp) < 1) break;
+        impl->numOfFrames++;
+    }
+
+    osal_fseek(fp, 0, SEEK_SET);
+
+    ctx->fp       = fp;
+    ctx->md5Size  = 12;
+    impl->context = ctx;
+    impl->eof     = FALSE;
+
+    return TRUE;
+}
+
+BOOL MD5Comparator_Destroy(
+    ComparatorImpl*  impl
+    )
+{
+    Context*    ctx = (Context*)impl->context;
+
+    osal_fclose(ctx->fp);
+    osal_free(ctx);
+
+    return TRUE;
+}
+
+BOOL MD5Comparator_Compare(
+    ComparatorImpl* impl,
+    void*           data,
+    Uint32          size
+    )
+{
+    Context*    ctx = (Context*)impl->context;
+    BOOL        match = TRUE;
+    Uint32      md5[12];
+    Uint32      index;
+    Uint32*     decodedMD5 = (Uint32*)data;
+
+    if (ctx->md5Size != size) {
+        VLOG(ERR, "%s:%d different MD5 size\n", __FUNCTION__, __LINE__);
+        return FALSE;
+    }
+
+    do {
+        osal_memset((void*)md5, 0x00, sizeof(md5));
+        if (impl->usePrevDataOneTime == TRUE) {
+            impl->usePrevDataOneTime = FALSE;
+            osal_memcpy(md5, ctx->prevMd5, ctx->md5Size*sizeof(md5[0]));
+        }
+        else {
+            for (index=0; index<ctx->md5Size; index++) {
+                /* FIXME: osal_osal_fscanf has problem on Windows.
+                */
+                osal_fscanf((FILE*)ctx->fp, "%08x", &md5[index]);
+
+                if (IsEndOfFile(ctx->fp) == TRUE) {
+                    impl->eof = TRUE;
+                    break;
+                }
+            }
+        }
+
+        if (data == NULL)
+            return FALSE;
+
+        match = TRUE;
+        for (index=0; index<size; index++) {
+            if (md5[index] != decodedMD5[index]) {
+                match = FALSE;
+                break;
+            }
+        }
+    } while (impl->enableScanMode == TRUE && match == FALSE && impl->eof == FALSE);
+
+    osal_memcpy(ctx->prevMd5, md5, ctx->md5Size*sizeof(md5[0]));
+
+    if (match == FALSE ) {
+        VLOG(ERR, "MISMATCH WITH GOLDEN MD5 at %d frame\n", impl->curIndex);
+        VLOG(ERR, "GOLDEN         DECODED\n"
+                  "-----------------------\n");
+        for (index=0; index<size; index++) 
+            VLOG(ERR, "%08x       %08x \n", md5[index], decodedMD5[index]);
+    }
+
+    return match;
+}
+
+BOOL MD5Comparator_Configure(
+    ComparatorImpl*     impl,
+    ComparatorConfType  type,
+    void*               val
+    )
+{
+    Context*    ctx = (Context*)impl->context;
+    BOOL        ret = TRUE;
+
+    switch (type) {
+    case COMPARATOR_CONF_SET_GOLDEN_DATA_SIZE:
+        ctx->md5Size = *(Uint32*)val;
+        impl->numOfFrames /= ctx->md5Size;
+        break;
+    default:
+        ret = FALSE;
+        break;
+    }
+
+    return ret;
+}
+
+BOOL MD5Comparator_Rewind(
+    ComparatorImpl*     impl
+    )
+{
+    Context*    ctx = (Context*)impl->context;
+    Int32       ret;
+
+    if ((ret=osal_fseek(ctx->fp, 0, SEEK_SET)) != 0) {
+        VLOG(ERR, "%s:%d Failed to osal_fseek(ret: %d)\n", __FUNCTION__, __LINE__, ret);
+        return FALSE;
+    }
+
+    return TRUE;
+}
+
+ComparatorImpl md5ComparatorImpl = {
+    NULL,
+    NULL,
+    0,
+    0,
+    MD5Comparator_Create,
+    MD5Comparator_Destroy,
+    MD5Comparator_Compare,
+    MD5Comparator_Configure,
+    MD5Comparator_Rewind,
+};
+ 

+ 324 - 0
wave420l/code/sample/helper/comparator/yuv_comparator_impl.c

@@ -0,0 +1,324 @@
+//--=========================================================================--
+//  This file is a part of VPU Reference API project
+//-----------------------------------------------------------------------------
+//
+//       This confidential and proprietary software may be used only
+//     as authorized by a licensing agreement from Chips&Media Inc.
+//     In the event of publication, the following notice is applicable:
+//
+//            (C) COPYRIGHT CHIPS&MEDIA INC.
+//                      ALL RIGHTS RESERVED
+//
+//       The entire notice above must be reproduced on all authorized
+//       copies.
+//
+//--=========================================================================--
+
+#include "config.h"
+#include "main_helper.h"
+#include "../misc/skip.h"
+#if defined(PLATFORM_LINUX) || defined(PLATFORM_QNX)
+#include <sys/types.h>
+#include <sys/stat.h>
+#endif
+#ifdef PLATFORM_NON_OS
+#ifdef LIB_C_STUB
+#include <sys/types.h>
+#include <sys/stat.h>
+#endif
+#endif
+
+typedef struct {
+    osal_file_t fp;
+    Uint32      width;
+    Uint32      height;
+    Uint32      frameSize;
+    BOOL        cbcrInterleave;
+    FrameBufferFormat format;
+    char        *path;
+    Uint32      isVp9;
+} Context;
+
+
+#ifndef MAX
+#define MAX(a, b)       (((a) > (b)) ? (a) : (b))
+#endif
+static Uint32 Calculate(
+    Context*    ctx
+    )
+{
+    Uint32      lumaSize   = 0;
+    Uint32      chromaSize = 0;
+    Uint32      frameSize  = 0;
+    Uint32      frames = 0;
+    Uint32      width  = ctx->width;
+    Uint32      height = ctx->height;
+    Uint64      endPos = 0;
+    BOOL        cbcrInterleave = ctx->cbcrInterleave;
+    FrameBufferFormat format = ctx->format;
+#if defined(PLATFORM_LINUX) || defined(PLATFORM_QNX)
+    struct   stat  file_info;
+#endif
+#ifdef PLATFORM_NON_OS
+#ifdef LIB_C_STUB
+    struct   stat  file_info;
+#endif
+#endif
+
+    lumaSize = width * height;
+    switch (format) {
+    case FORMAT_400:
+        chromaSize = 0;
+        break;
+    case FORMAT_YUYV:
+    case FORMAT_YVYU:
+    case FORMAT_UYVY:
+    case FORMAT_VYUY:
+        chromaSize = lumaSize;
+        break;
+    case FORMAT_420:
+        chromaSize = lumaSize / 2;
+        break;
+    case FORMAT_422:
+    case FORMAT_224:
+        chromaSize = lumaSize;
+        break;
+    case FORMAT_444:
+        chromaSize = lumaSize * 2;
+        break;
+    case FORMAT_420_P10_16BIT_LSB:
+    case FORMAT_420_P10_16BIT_MSB:
+        lumaSize  *= 2;
+        chromaSize = lumaSize/2;
+        break;
+    case FORMAT_420_P10_32BIT_LSB:
+    case FORMAT_420_P10_32BIT_MSB:
+#ifdef DUMP_YUV_WHOLE_DATA
+        if (cbcrInterleave) {
+            lumaSize   = ((VPU_ALIGN16(width)+11)/12*16) * height;
+            chromaSize = VPU_ALIGN16(((VPU_ALIGN16(width/2))*2+11)/12*16) * height / 2;
+        }
+        else {
+            lumaSize   = ((VPU_ALIGN16(width)+11)/12*16) * height;
+            chromaSize = VPU_ALIGN16(((VPU_ALIGN16(width/2))+11)/12*16) * height / 2 *2;
+        }
+#else
+        if (cbcrInterleave) {
+            lumaSize   = ((width+2)/3*4) * height;
+            chromaSize = ((width+2)/3*4) * height / 2;
+        }
+        else {
+            lumaSize   = (width+2)/3*4 * height;
+            chromaSize = (width/2+2)/3*4 * height / 2 *2;
+        }
+#endif
+        break;
+    case FORMAT_422_P10_16BIT_MSB:
+    case FORMAT_422_P10_16BIT_LSB:
+        lumaSize  *= 2;
+        chromaSize = lumaSize;
+        break;
+    case FORMAT_422_P10_32BIT_LSB:
+    case FORMAT_422_P10_32BIT_MSB:
+        {
+            Uint32 twice = cbcrInterleave ? 2 : 1;
+            if (ctx->isVp9 == TRUE) {
+                lumaSize   = VPU_ALIGN32(((width+11)/12)*16);
+                chromaSize = (((width/2)+11)*twice/12)*16;
+            }
+            else {
+                width = VPU_ALIGN32(width);
+                lumaSize   = ((VPU_ALIGN16(width)+11)/12)*16;
+                chromaSize = ((VPU_ALIGN16(width/2)+11)*twice/12)*16;
+                if ((chromaSize*2) > lumaSize) {
+                    lumaSize = chromaSize * 2;
+                }
+            }
+            if (cbcrInterleave == TRUE) {
+                lumaSize = MAX(lumaSize, chromaSize);
+            }
+        }
+        break;
+    default:
+        VLOG(ERR, "%s:%d Invalid format: %d\n", __FILE__, __LINE__, format);
+    }
+    frameSize = lumaSize + chromaSize;
+
+#ifdef PLATFORM_WIN32
+#if (_MSC_VER == 1200)
+    osal_fseek(ctx->fp, 0, SEEK_END);
+    endPos = ftell(ctx->fp);
+    osal_fseek(ctx->fp, 0, SEEK_SET);
+#else
+    _fseeki64((FILE*)ctx->fp, 0LL, SEEK_END);
+    endPos = _ftelli64((FILE*)ctx->fp);
+    _fseeki64((FILE*)ctx->fp, 0LL, SEEK_SET);
+#endif
+#else
+    stat( ctx->path, &file_info);
+    endPos = file_info.st_size;
+#endif
+
+    frames = (Uint32)(endPos / frameSize);
+
+    if (endPos % frameSize) {
+        VLOG(ERR, "%s:%d Mismatch - file_size: %llu frameSize: %d\n",
+            __FUNCTION__, __LINE__, endPos, frameSize);
+    }
+    ctx->frameSize  = frameSize;
+
+    return frames;
+}
+
+BOOL YUVComparator_Create(
+    ComparatorImpl* impl,
+    char*           path
+    )
+{
+    Context*        ctx;
+    osal_file_t*    fp;
+
+    if ((fp=osal_fopen(path, "rb")) == NULL) {
+        VLOG(ERR, "%s:%d failed to open yuv file: %s\n", __FUNCTION__, __LINE__, path);
+        return FALSE;
+    }
+
+    if ((ctx=(Context*)osal_malloc(sizeof(Context))) == NULL) {
+        osal_fclose(fp);
+        return FALSE;
+    }
+
+    ctx->fp        = fp;
+    ctx->path      = path;
+    impl->context  = ctx;
+    impl->eof      = FALSE;
+
+    return TRUE;
+}
+
+BOOL YUVComparator_Destroy(
+    ComparatorImpl*  impl
+    )
+{
+    Context*    ctx = (Context*)impl->context;
+
+    osal_fclose(ctx->fp);
+    osal_free(ctx);
+
+    return TRUE;
+}
+
+BOOL YUVComparator_Compare(
+    ComparatorImpl* impl,
+    void*           data,
+    Uint32          size
+    )
+{
+    Uint8*      pYuv = NULL;
+    Context*    ctx = (Context*)impl->context;
+    BOOL        match = FALSE;
+
+    if ( data == (void *)COMPARATOR_SKIP ) {
+        int fpos;
+        fpos = osal_ftell(ctx->fp);
+        osal_fseek(ctx->fp, fpos+size, SEEK_SET);
+
+        if (IsEndOfFile(ctx->fp) == TRUE)
+            impl->eof = TRUE;
+
+        return TRUE;
+    }
+
+    pYuv = (Uint8*)osal_malloc(size);
+    osal_fread(pYuv, 1, size, ctx->fp);
+
+    if (IsEndOfFile(ctx->fp) == TRUE)
+        impl->eof = TRUE;
+
+    match = (osal_memcmp(data, (void*)pYuv, size) == 0 ? TRUE : FALSE);
+    if (match == FALSE) {
+        osal_file_t* fpGolden;
+        osal_file_t* fpOutput;
+        char tmp[200];
+
+        VLOG(ERR, "MISMATCH WITH GOLDEN YUV at %d frame\n", impl->curIndex);
+        sprintf(tmp, "./golden.yuv");
+        if ((fpGolden=osal_fopen(tmp, "wb")) == NULL) {
+            VLOG(ERR, "Faild to create golden.yuv\n");
+            osal_free(pYuv);
+            return FALSE;
+        }
+        VLOG(ERR, "Saving... Golden YUV at %s\n", tmp);
+
+        sprintf(tmp, "./decoded.yuv");
+        osal_fwrite(pYuv, 1, size, fpGolden);
+        osal_fclose(fpGolden);
+        if ((fpOutput=osal_fopen(tmp, "wb")) == NULL) {
+            VLOG(ERR, "Faild to create golden.yuv\n");
+            osal_free(pYuv);
+            return FALSE;
+        }
+        VLOG(ERR, "Saving... decoded YUV at %s\n", tmp);
+        osal_fwrite(data, 1, size, fpOutput);
+        osal_fclose(fpOutput);
+    }
+    osal_free(pYuv);
+
+    return match;
+}
+
+BOOL YUVComparator_Configure(
+    ComparatorImpl*     impl,
+    ComparatorConfType  type,
+    void*               val
+    )
+{
+    PictureInfo*        yuv = NULL;
+    Context*            ctx = (Context*)impl->context;
+    BOOL                ret = TRUE;
+
+    switch (type) {
+    case COMPARATOR_CONF_SET_PICINFO:
+        yuv = (PictureInfo*)val;
+        ctx->width  = yuv->width;
+        ctx->height = yuv->height;
+        ctx->format = yuv->format;
+        ctx->cbcrInterleave = yuv->cbcrInterleave;
+        //can not calculate a sequence changed YUV
+        impl->numOfFrames   = Calculate(ctx);
+        break;
+    default:
+        ret = FALSE;
+        break;
+    }
+    return ret;
+}
+
+BOOL YUVComparator_Rewind(
+    ComparatorImpl*     impl
+    )
+{
+    Context*    ctx = (Context*)impl->context;
+    Int32       ret;
+
+    if ((ret=osal_fseek(ctx->fp, 0, SEEK_SET)) != 0) {
+        VLOG(ERR, "%s:%d failed to osal_fseek(ret:%d)\n", __FUNCTION__, __LINE__, ret);
+        return FALSE;
+    }
+
+    return TRUE;
+}
+
+ComparatorImpl yuvComparatorImpl = {
+    NULL,
+    NULL,
+    0,
+    0,
+    YUVComparator_Create,
+    YUVComparator_Destroy,
+    YUVComparator_Compare,
+    YUVComparator_Configure,
+    YUVComparator_Rewind,
+    FALSE,
+};
+ 

+ 858 - 0
wave420l/code/sample/helper/display/fbdev_impl.c

@@ -0,0 +1,858 @@
+//--=========================================================================--
+//  This file is a part of VPU Reference API project
+//-----------------------------------------------------------------------------
+//
+//       This confidential and proprietary software may be used only
+//     as authorized by a licensing agreement from Chips&Media Inc.
+//     In the event of publication, the following notice is applicable:
+//
+//            (C) COPYRIGHT 2006 - 2013  CHIPS&MEDIA INC.
+//                      ALL RIGHTS RESERVED
+//
+//       The entire notice above must be reproduced on all authorized
+//       copies.
+//
+//--=========================================================================--
+
+#include "main_helper.h"
+
+typedef enum { 
+    YUV444, YUV422, YUV420, NV12, NV21, 
+    YUV400, YUYV, YVYU, UYVY, VYUY, YYY, 
+    RGB_PLANAR, RGB32, RGB24, RGB16, 
+    YUV2RGB_COLOR_FORMAT_MAX 
+} YUV2RGBColorFmt;
+
+#if defined(PLATFORM_LINUX) || defined(PLATFORM_QNX)
+#include <unistd.h>
+#endif
+
+#if defined(PLATFORM_WIN32) || defined(PLATFORM_LINUX) || defined(PLATFORM_QNX)
+static void ConvertYuvToRgb(
+    Uint32      width, 
+    Uint32      height, 
+    YUV2RGBColorFmt format, 
+    Uint8*      src, 
+    Uint8*      rgba, 
+    BOOL        chroma_reverse
+    );
+
+static YUV2RGBColorFmt ConvertToDeviceColorFormat(
+    int yuv_format, 
+    int interleave
+    );
+#endif // defined(PLATFORM_WIN32) || defined(PLATFORM_LINUX)
+
+#if defined(PLATFORM_WIN32) 
+#include <windows.h>
+#include <stdio.h>
+
+#pragma comment(lib,"User32.lib")
+#pragma comment(lib,"gdi32.lib")
+
+#define DRAW_IN_WINDOW
+typedef struct
+{
+    BITMAPINFOHEADER bmih;
+    RGBQUAD rgb[256];
+} BITMAPINFO2;
+
+static LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
+
+typedef struct 
+{
+    HBITMAP		s_dib_section;
+    void		*s_dib_buffer;
+    HDC			s_hdc_memory;
+    HGDIOBJ		s_old_hobject;
+    HWND	s_hWnd;
+    int wndShow;
+    Uint32      winWidth;
+    Uint32      winHeight;
+} FBDev;
+
+static FBDev s_mixer[MAX_NUM_VPU_CORE*MAX_NUM_INSTANCE];
+#endif	//defined(PLATFORM_WIN32) 
+
+#ifdef PLATFORM_LINUX
+
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include <fcntl.h>
+#include <sys/time.h>
+#include <linux/fb.h>
+
+typedef struct 
+{
+    int s_fd;
+    unsigned char *s_scr_ptr;
+    unsigned char *s_rgb_ptr;
+    unsigned long s_product;
+    int s_fb_stride;
+    int s_fb_height;
+    int s_fb_width;
+    int s_fb_bpp;	
+} FBDev;
+
+static struct fb_var_screeninfo vscr_info;
+static struct fb_fix_screeninfo fscr_info;
+
+static FBDev s_mixer[MAX_NUM_VPU_CORE*MAX_NUM_INSTANCE];
+#endif //PLATFORM_LINUX
+
+static Int32 PlatformDev_Open(
+    Uint32      coreIndex, 
+    Int32       width, 
+    Int32       height
+    )
+{	
+#ifdef PLATFORM_LINUX	
+    FBDev *mixer = &s_mixer[coreIndex];
+    char fb_name[256];
+
+    if (mixer->s_fd)
+        return 1;
+#ifdef ANDROID
+    sprintf(fb_name, "/dev/graphics/fb%d", coreIndex);
+#else
+    sprintf(fb_name, "/dev/fb%d", coreIndex);
+#endif
+
+    mixer->s_fd = open(fb_name, O_RDWR);
+    if (mixer->s_fd< 0) {
+        VLOG(ERR, "Unable to open framebuffer %s\n", fb_name);
+        return 0;
+    }
+    /** frame buffer display configuration get */
+    if (ioctl(mixer->s_fd, FBIOGET_VSCREENINFO, &vscr_info) != 0 || ioctl(mixer->s_fd, FBIOGET_FSCREENINFO, &fscr_info) != 0) {
+        VLOG(ERR, "Error during ioctl to get framebuffer parameters!\n");
+        return 0;
+    }
+    mixer->s_fb_bpp = vscr_info.bits_per_pixel/8;
+    mixer->s_fb_width = vscr_info.xres;
+    mixer->s_fb_stride = fscr_info.line_length;
+    mixer->s_fb_height = vscr_info.yres;
+    mixer->s_product= mixer->s_fb_stride * mixer->s_fb_height;
+    /** memory map frame buf memory */
+    mixer->s_scr_ptr = (unsigned char*) mmap(0, mixer->s_product, PROT_READ | PROT_WRITE, MAP_SHARED, mixer->s_fd, 0);
+    if (mixer->s_scr_ptr == NULL)
+    {
+        VLOG(ERR, "in %s Failed to mmap framebuffer memory!\n", __func__);
+        close (mixer->s_fd);
+        return 0;
+    }
+
+    mixer->s_rgb_ptr = osal_malloc(width*height*mixer->s_fb_bpp);
+    if (mixer->s_rgb_ptr == NULL) {
+        VLOG(ERR, "in %s Failed to allocate rgb memory!\n", __func__);
+        close (mixer->s_fd);
+        return 0;
+    }
+    VLOG(TRACE, "Successfully opened %s for display.\n", fb_name);
+    VLOG(TRACE, "mmap framebuffer memory =%p product=%d\n", mixer->s_scr_ptr, (unsigned int)mixer->s_product, (int)width);
+    VLOG(TRACE, "Display Size: width=%d, height=%d, stride=%d, Bit Count: %d \n", (int)mixer->s_fb_width, (int)mixer->s_fb_height, (int)mixer->s_fb_stride, (int)mixer->s_fb_bpp);
+
+#endif	//#ifdef PLATFORM_LINUX
+
+#if defined(PLATFORM_WIN32) 
+    FBDev *mixer = &s_mixer[coreIndex];
+
+    HDC hdc;
+    BITMAPINFO2	bmi2;
+    if (mixer->s_dib_section)
+        return 0;
+
+    osal_memset(&bmi2, 0x00, sizeof(bmi2));
+    bmi2.bmih.biSize = sizeof(BITMAPINFOHEADER);
+    bmi2.bmih.biWidth = width;
+    bmi2.bmih.biHeight = -(height);
+    bmi2.bmih.biPlanes = 1;
+    bmi2.bmih.biBitCount = 32;
+    bmi2.bmih.biCompression = BI_RGB;
+    if( bmi2.bmih.biBitCount == 16 )
+    {
+        bmi2.bmih.biCompression = BI_BITFIELDS;
+        *(DWORD *)(&bmi2.rgb[0]) = 0xF800;
+        *(DWORD *)(&bmi2.rgb[1]) = 0x07e0;
+        *(DWORD *)(&bmi2.rgb[2]) = 0x001F;
+    }
+    else
+        bmi2.bmih.biCompression = BI_RGB;
+
+    mixer->s_dib_section = CreateDIBSection(
+        NULL,
+        (PBITMAPINFO)&bmi2,
+        DIB_RGB_COLORS,
+        &mixer->s_dib_buffer,
+        NULL,
+        0
+        );
+
+    hdc = GetDC( mixer->s_hWnd );
+    mixer->s_hdc_memory = CreateCompatibleDC( hdc );
+    if (!mixer->s_hdc_memory)
+        return 0;
+    ReleaseDC(mixer->s_hWnd, hdc);
+
+    mixer->s_old_hobject = SelectObject(mixer->s_hdc_memory, mixer->s_dib_section);
+    if (!mixer->s_old_hobject)
+        return 0;
+
+#ifdef DRAW_IN_WINDOW
+    {
+        WNDCLASSEX wcex;
+
+        wcex.cbSize = sizeof(WNDCLASSEX); 
+        wcex.style   = CS_HREDRAW | CS_VREDRAW;
+        wcex.lpfnWndProc = WndProc;
+        wcex.cbClsExtra  = 0;
+        wcex.cbWndExtra  = 0;
+        wcex.hInstance  = GetModuleHandle(NULL);
+        wcex.hIcon   = LoadIcon(NULL, IDI_APPLICATION);
+        wcex.hCursor  = LoadCursor(NULL, IDC_ARROW);
+        wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
+        wcex.lpszMenuName = NULL;
+        wcex.lpszClassName = (LPCTSTR)"CNMMIXER";
+        wcex.hIconSm  = LoadIcon(NULL, IDI_APPLICATION);
+
+        RegisterClassEx(&wcex);
+
+        mixer->s_hWnd = CreateWindow((LPCTSTR)"CNMMIXER", (LPCTSTR)"C&M YuvViewer", WS_OVERLAPPEDWINDOW,
+            CW_USEDEFAULT, CW_USEDEFAULT, width, height, NULL, NULL, GetModuleHandle(NULL), NULL);
+        MoveWindow(mixer->s_hWnd, coreIndex*width, 0, width+16, height+38, TRUE);
+        mixer->wndShow = 0;
+    }
+#endif
+#endif //#if defined(PLATFORM_WIN32) 
+
+#if defined(PLATFORM_QNX)
+#endif
+    return 1;
+
+}
+
+#ifdef PLATFORM_WIN32
+static Uint8* convert16bitTo8bit(
+    Uint8* src, 
+    Uint32 w, 
+    Uint32 h, 
+    FrameBufferFormat format
+    )
+{
+    Uint8* dst;
+    Uint8* pdst;
+    Uint16* psrc = (Uint16*)src;
+    Uint32 x, y, shift;
+
+    if (format == FORMAT_420_P10_16BIT_MSB) 
+        shift = 8;
+    else 
+        shift = 2;
+
+    pdst = dst = (Uint8*)osal_malloc(w*h*3/2);
+    /* Y */
+    for (y=0; y<h; y++) {
+        for (x=0; x<w; x++) {
+            *dst++ = ((*psrc++)>>shift)&0xff;
+        }
+    }
+    /* Cb */
+    for (y=0; y<h/2; y++) {
+        for (x=0; x<w/2; x++) {
+            *dst++ = (*psrc++>>shift)&0xff;
+        }
+    }
+    /* Cr */
+    for (y=0; y<h/2; y++) {
+        for (x=0; x<w/2; x++) {
+            *dst++ = (*psrc++>>shift)&0xff;
+        }
+    }
+
+    return pdst;
+}
+#endif /* PLATFORM_WIN32 */
+
+static void PlatformDev_Close(
+    Uint32 coreIndex
+    )
+{
+#ifdef PLATFORM_LINUX
+    FBDev *mixer = &s_mixer[coreIndex];
+    if (mixer->s_scr_ptr)
+    {
+        munmap(mixer->s_scr_ptr, mixer->s_product);
+        mixer->s_scr_ptr = NULL;
+    }
+    if (mixer->s_rgb_ptr)
+    {
+        osal_free(mixer->s_rgb_ptr);
+        mixer->s_rgb_ptr = NULL;
+    }
+
+    if (mixer->s_fd)
+    {
+        close(mixer->s_fd);
+        mixer->s_fd = 0;
+    }
+#endif
+
+#if defined(PLATFORM_WIN32) 
+    FBDev *mixer = &s_mixer[coreIndex];
+    if (mixer->s_old_hobject)
+    {
+        SelectObject(mixer->s_hdc_memory,mixer->s_old_hobject);
+    }
+    if (mixer->s_hdc_memory)
+    {
+        DeleteDC(mixer->s_hdc_memory);
+    }
+    if (mixer->s_dib_section)
+    {
+        DeleteObject(mixer->s_dib_section);
+    }
+
+    if (mixer->s_hWnd)
+    {
+        DestroyWindow(mixer->s_hWnd);
+    }
+
+    osal_memset(mixer, 0x00, sizeof(FBDev));
+#endif	//#if defined(PLATFORM_WIN32) 
+
+#if defined(PLATFORM_QNX)
+#endif
+}
+
+static int PlatformDev_Draw(
+    Uint32      coreIndex, 
+    Uint32      x, 
+    Uint32      y, 
+    Uint32      width, 
+    Uint32      height, 
+    FrameBufferFormat   format, 
+    Uint8*      pbImage, 
+    BOOL        interleave, 
+    Uint32      bpp
+    )
+{
+
+#ifdef PLATFORM_LINUX
+    FBDev *mixer = &s_mixer[coreIndex];
+    unsigned char* src_ptr = pbImage;
+    YUV2RGBColorFmt colorFormat;
+
+    if (mixer->s_fd < 0)
+        return 0;
+
+    colorFormat = ConvertToDeviceColorFormat(format, interleave);
+    if (colorFormat == YUV2RGB_COLOR_FORMAT_MAX) {
+        VLOG(ERR, "[ERROR]not supported image format\n");
+        return 0;
+    }
+
+    if (mixer->s_fb_bpp == 8) {
+        ConvertYuvToRgb(width, height, colorFormat, src_ptr,  mixer->s_rgb_ptr, 1);
+    }
+    else {
+        return 0;
+    }
+    // Not implemented yet
+#endif	//#ifdef PLATFORM_LINUX
+
+#if defined(PLATFORM_WIN32) 
+    FBDev *mixer = &s_mixer[coreIndex];
+    HDC hdc_screen;
+    YUV2RGBColorFmt color_format;
+    Uint8* pYuv = NULL;
+
+    if (mixer->winWidth != width || mixer->winHeight != height) {
+        /* re-create window */
+        PlatformDev_Close(coreIndex);
+        PlatformDev_Open(coreIndex, width, height);
+        mixer->winWidth  = width;
+        mixer->winHeight = height;
+    }
+
+    if (!mixer->wndShow) {
+        ShowWindow(mixer->s_hWnd, SW_SHOW);
+        UpdateWindow(mixer->s_hWnd);
+        //SetForegroundWindow(mixer->s_hWnd);
+        mixer->wndShow = 1;
+    }
+    else
+    {
+        MSG msg={0};
+        while(1)
+        {
+            if (PeekMessage(&msg, mixer->s_hWnd, 0, 0, PM_REMOVE))
+            {
+                TranslateMessage(&msg);
+                DispatchMessage(&msg);
+            }
+            else
+                break;
+        }		
+    }
+
+#ifdef DRAW_IN_WINDOW
+    hdc_screen = GetDC( mixer->s_hWnd );
+#else
+    hdc_screen = GetDC( NULL );
+#endif
+
+    color_format  = ConvertToDeviceColorFormat(format, interleave);
+
+    if (color_format == YUV2RGB_COLOR_FORMAT_MAX)
+    {
+        VLOG(ERR, "[ERROR]not supported image format\n");
+        return 0;
+    }
+
+    if (bpp == 16)
+        pYuv = convert16bitTo8bit(pbImage, width, height, format);
+    else
+        pYuv = pbImage;
+
+    ConvertYuvToRgb(width, height, color_format, pYuv, (unsigned char *)mixer->s_dib_buffer, 1);
+
+    if (bpp == 16) 
+        osal_free(pYuv);
+
+    if( hdc_screen ) {
+#if 0
+        RECT    rc;
+        Int32   dispWidth;
+        Int32   dispHeight;
+        GetClientRect(mixer->s_hWnd, &rc);
+        dispWidth = rc.right - rc.left;
+        dispHeight = rc.bottom - rc.top;
+        if (width != dispWidth || height != dispHeight)
+            StretchBlt(hdc_screen, 0, 0, dispWidth, dispHeight, mixer->s_hdc_memory, x, y, width, height, SRCCOPY); 
+        else
+            BitBlt( hdc_screen, x, y, width, height, mixer->s_hdc_memory, 0,0, SRCCOPY );	
+#else
+        BitBlt( hdc_screen, x, y, width, height, mixer->s_hdc_memory, 0,0, SRCCOPY );    
+#endif
+
+        ReleaseDC(mixer->s_hWnd, hdc_screen);
+    }
+
+    //SetForegroundWindow(s_hWnd);
+#endif	//#if defined(PLATFORM_WIN32) 
+
+#if defined(PLATFORM_QNX)
+#endif
+    return 1;
+
+}
+
+#if defined(PLATFORM_WIN32) 
+static LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
+{
+    PAINTSTRUCT ps;
+    switch (message)
+    {
+    case WM_CREATE:
+        return (0);
+
+    case WM_PAINT:
+        BeginPaint (hwnd, &ps);
+
+        EndPaint (hwnd, &ps);
+        return (0);
+
+    case WM_CLOSE:
+        return (0);
+
+    case WM_DESTROY:
+        PostQuitMessage (0);
+        return (0);
+    }
+    return DefWindowProc (hwnd, message, wParam, lParam);
+}
+
+#endif //defined(PLATFORM_WIN32) 
+
+#if defined(PLATFORM_WIN32) || defined(PLATFORM_LINUX) || defined(PLATFORM_QNX)
+// inteleave : 0 (chroma separate mode), 1 (cbcr interleave mode), 2 (crcb interleave mode)
+static YUV2RGBColorFmt ConvertToDeviceColorFormat(
+    int yuv_format, 
+    int interleave
+    ) 
+{      
+    YUV2RGBColorFmt format;
+
+    switch(yuv_format)
+    {
+    case FORMAT_400: format = YUV400; break;
+    case FORMAT_444: format = YUV444; break;
+    case FORMAT_224:
+    case FORMAT_422: format = YUV422; break;
+    case FORMAT_420_P10_16BIT_LSB:
+    case FORMAT_420_P10_16BIT_MSB:
+    case FORMAT_420: 
+        if (interleave == 0)
+            format = YUV420; 
+        else if (interleave == 1)
+            format = NV12;				
+        else
+            format = NV21; 
+        break;
+    default:
+        format = YUV2RGB_COLOR_FORMAT_MAX; 
+    }
+
+    return format;
+}  
+#endif // defined(PLATFORM_WIN32) || defined(PLATFORM_LINUX)
+
+#if defined(PLATFORM_WIN32) || defined(PLATFORM_LINUX) || defined(PLATFORM_QNX)
+static void ConvertYuvToRgb(
+    Uint32          width, 
+    Uint32          height, 
+    YUV2RGBColorFmt format, 
+    Uint8*          src, 
+    Uint8*          rgba, 
+    BOOL            cbcr_reverse
+    )
+{
+#define CLIP(var) ((var>=255)?255:(var<=0)?0:var)
+    Uint32   j, i;
+    Int32    c, d, e;
+
+    Uint8*   line = rgba;
+    Uint8*   cur;
+    Uint8*   y = NULL;
+    Uint8*   u = NULL;
+    Uint8*   v = NULL;
+    Uint8*   misc = NULL;
+
+    Uint32   frame_size_y;
+    Uint32   frame_size_uv;
+    Uint32   t_width;
+
+    frame_size_y = width*height;
+
+    if( format == YUV444 || format == RGB_PLANAR)
+        frame_size_uv = width*height;
+    else if( format == YUV422 )
+        frame_size_uv = (width*height)>>1;
+    else if( format == YUV420 || format == NV12 || format == NV21 )
+        frame_size_uv = (width*height)>>2;
+    else 
+        frame_size_uv = 0;
+
+    t_width = width;
+
+    if( format == YUYV || format == YVYU  || format == UYVY  || format == VYUY ) {
+        misc = src;
+    }
+    else if( format == NV12 || format == NV21) {	
+        y = src;
+        misc = src + frame_size_y;
+    }
+    else if( format == RGB32 || format == RGB24 || format == RGB16 ) {
+        misc = src;
+    }
+    else {
+        y = src;
+        u = src + frame_size_y;
+        v = src + frame_size_y + frame_size_uv;		
+    }
+
+    if( format == YUV444 ){
+
+        for( j = 0 ; j < height ; j++ ){
+            cur = line;
+            for( i = 0 ; i < width ; i++ ){
+                c = y[j*width+i] - 16;
+                d = u[j*width+i] - 128;
+                e = v[j*width+i] - 128;
+
+                if (!cbcr_reverse) {
+                    d = u[j*width+i] - 128;
+                    e = v[j*width+i] - 128;
+                } else {
+                    e = u[j*width+i] - 128;
+                    e = v[j*width+i] - 128;
+                }
+                (*cur) = (BYTE)CLIP(( 298 * c           + 409 * e + 128) >> 8);cur++;
+                (*cur) = (BYTE)CLIP(( 298 * c - 100 * d - 208 * e + 128) >> 8);cur++;
+                (*cur) = (BYTE)CLIP(( 298 * c + 516 * d           + 128) >> 8);cur++;
+                (*cur) = 0; cur++;
+            }
+            line += t_width<<2;
+        }
+    }
+    else if( format == YUV422){
+        for( j = 0 ; j < height ; j++ ){
+            cur = line;
+            for( i = 0 ; i < width ; i++ ){
+                c = y[j*width+i] - 16;
+                d = u[j*(width>>1)+(i>>1)] - 128;
+                e = v[j*(width>>1)+(i>>1)] - 128;
+
+                if (!cbcr_reverse) {
+                    d = u[j*(width>>1)+(i>>1)] - 128;
+                    e = v[j*(width>>1)+(i>>1)] - 128;
+                } else {
+                    e = u[j*(width>>1)+(i>>1)] - 128;
+                    d = v[j*(width>>1)+(i>>1)] - 128;
+                }
+
+                (*cur) = (BYTE)CLIP(( 298 * c           + 409 * e + 128) >> 8);cur++;
+                (*cur) = (BYTE)CLIP(( 298 * c - 100 * d - 208 * e + 128) >> 8);cur++;
+                (*cur) = (BYTE)CLIP(( 298 * c + 516 * d           + 128) >> 8);cur++;
+                (*cur) = 0; cur++;
+            }
+            line += t_width<<2;
+        }
+    }
+    else if( format == YUYV || format == YVYU  || format == UYVY  || format == VYUY )
+    {
+        unsigned char* t = misc;
+        for( j = 0 ; j < height ; j++ ){
+            cur = line;
+            for( i = 0 ; i < width ; i+=2 ){
+                switch( format) {
+                case YUYV:
+                    c = *(t  ) - 16;
+                    if (!cbcr_reverse) {
+                        d = *(t+1) - 128;
+                        e = *(t+3) - 128;
+                    } else {
+                        e = *(t+1) - 128;
+                        d = *(t+3) - 128;
+                    }
+                    break;
+                case YVYU:
+                    c = *(t  ) - 16;
+                    if (!cbcr_reverse) {
+                        d = *(t+3) - 128;
+                        e = *(t+1) - 128;
+                    } else {
+                        e = *(t+3) - 128;
+                        d = *(t+1) - 128;
+                    }
+                    break;
+                case UYVY:
+                    c = *(t+1) - 16;
+                    if (!cbcr_reverse) {
+                        d = *(t  ) - 128;
+                        e = *(t+2) - 128;
+                    } else {
+                        e = *(t  ) - 128;
+                        d = *(t+2) - 128;
+                    }
+                    break;
+                case VYUY:
+                    c = *(t+1) - 16;
+                    if (!cbcr_reverse) {
+                        d = *(t+2) - 128;
+                        e = *(t  ) - 128;
+                    } else {
+                        e = *(t+2) - 128;
+                        d = *(t  ) - 128;
+                    }
+                    break;
+                default: // like YUYV
+                    c = *(t  ) - 16;
+                    if (!cbcr_reverse) {
+                        d = *(t+1) - 128;
+                        e = *(t+3) - 128;
+                    } else {
+                        e = *(t+1) - 128;
+                        d = *(t+3) - 128;
+                    }
+                    break;
+                }       
+
+                (*cur) = (BYTE)CLIP(( 298 * c           + 409 * e + 128) >> 8);cur++;
+                (*cur) = (BYTE)CLIP(( 298 * c - 100 * d - 208 * e + 128) >> 8);cur++;
+                (*cur) = (BYTE)CLIP(( 298 * c + 516 * d           + 128) >> 8);cur++;
+                (*cur) = 0;cur++;
+
+                switch( format) {
+                case YUYV:
+                case YVYU:
+                    c = *(t+2) - 16;
+                    break;
+
+                case VYUY:
+                case UYVY:
+                    c = *(t+3) - 16;
+                    break;
+                default: // like YUYV
+                    c = *(t+2) - 16;
+                    break;
+                }
+
+                (*cur) = (BYTE)CLIP(( 298 * c           + 409 * e + 128) >> 8);cur++;
+                (*cur) = (BYTE)CLIP(( 298 * c - 100 * d - 208 * e + 128) >> 8);cur++;
+                (*cur) = (BYTE)CLIP(( 298 * c + 516 * d           + 128) >> 8);cur++;
+                (*cur) = 0; cur++;
+
+                t += 4;
+            }
+            line += t_width<<2;
+        }
+    }
+    else if( format == YUV420 || format == NV12 || format == NV21){
+        for( j = 0 ; j < height ; j++ ){
+            cur = line;
+            for( i = 0 ; i < width ; i++ ){
+                c = y[j*width+i] - 16;
+                if (format == YUV420) {
+                    if (!cbcr_reverse) {
+                        d = u[(j>>1)*((width)>>1)+(i>>1)] - 128;
+                        e = v[(j>>1)*((width)>>1)+(i>>1)] - 128;					
+                    } else {
+                        e = u[(j>>1)*((width)>>1)+(i>>1)] - 128;
+                        d = v[(j>>1)*((width)>>1)+(i>>1)] - 128;	
+                    }
+                }
+                else if (format == NV12) {
+                    if (!cbcr_reverse) {
+                        d = misc[(j>>1)*width+((i>>1)<<1)  ] - 128;
+                        e = misc[(j>>1)*width+((i>>1)<<1)+1] - 128;					
+                    } else {
+                        e = misc[(j>>1)*width+((i>>1)<<1)  ] - 128;
+                        d = misc[(j>>1)*width+((i>>1)<<1)+1] - 128;	
+                    }
+                }
+                else { // if (m_color == NV21)
+                    if (!cbcr_reverse) {
+                        d = misc[(j>>1)*width+((i>>1)<<1)+1] - 128;
+                        e = misc[(j>>1)*width+((i>>1)<<1)  ] - 128;					
+                    } else {
+                        e = misc[(j>>1)*width+((i>>1)<<1)+1] - 128;
+                        d = misc[(j>>1)*width+((i>>1)<<1)  ] - 128;		
+                    }
+                }
+                (*cur) = (BYTE)CLIP(( 298 * c           + 409 * e + 128) >> 8);cur++;
+                (*cur) = (BYTE)CLIP(( 298 * c - 100 * d - 208 * e + 128) >> 8);cur++;
+                (*cur) = (BYTE)CLIP(( 298 * c + 516 * d           + 128) >> 8);cur++;
+                (*cur) = 0; cur++;
+            }
+            line += t_width<<2;
+        }
+    }
+    else if( format == RGB_PLANAR ){
+        for( j = 0 ; j < height ; j++ ){
+            cur = line;
+            for( i = 0 ; i < width ; i++ ){
+                (*cur) = y[j*width+i];cur++;
+                (*cur) = u[j*width+i];cur++;
+                (*cur) = v[j*width+i];cur++;
+                (*cur) = 0; cur++;
+            }
+            line += t_width<<2;
+        }
+    }
+    else if( format == RGB32 ){
+        for( j = 0 ; j < height ; j++ ){
+            cur = line;
+            for( i = 0 ; i < width ; i++ ){
+                (*cur) = misc[j*width*4+i];cur++;	// R
+                (*cur) = misc[j*width*4+i+1];cur++;	// G
+                (*cur) = misc[j*width*4+i+2];cur++;	// B
+                (*cur) = misc[j*width*4+i+3];cur++;	// A
+            }
+            line += t_width<<2;
+        }
+    }
+    else if( format == RGB24 ){
+        for( j = 0 ; j < height ; j++ ){
+            cur = line;
+            for( i = 0 ; i < width ; i++ ){
+                (*cur) = misc[j*width*3+i];cur++;	// R
+                (*cur) = misc[j*width*3+i+1];cur++;	// G
+                (*cur) = misc[j*width*3+i+2];cur++;	// B
+                (*cur) = 0; cur++;
+            }
+            line += t_width<<2;
+        }
+    }
+    else if( format == RGB16 ){
+        for( j = 0 ; j < height ; j++ ){
+            cur = line;
+            for( i = 0 ; i < width ; i++ ){
+                int tmp = misc[j*width*2+i]<<8 | misc[j*width*2+i+1];
+                (*cur) = (BYTE)((tmp>>11)&0x1F<<3);cur++; // R(5bit)
+                (*cur) = (BYTE)((tmp>>5 )&0x3F<<2);cur++; // G(6bit)
+                (*cur) = (BYTE)((tmp    )&0x1F<<3);cur++; // B(5bit)
+                (*cur) = 0; cur++;
+            }
+            line += t_width<<2;
+        }
+    }
+    else { // YYY
+        for( j = 0 ; j < height ; j++ ){
+            cur = line;
+            for( i = 0 ; i < width ; i++ ){
+                (*cur) = (BYTE)y[j*width+i]; cur++;
+                (*cur) = (BYTE)y[j*width+i]; cur++;
+                (*cur) = (BYTE)y[j*width+i]; cur++;
+                (*cur) = 0; cur++;
+            }
+            line += t_width<<2;
+        }	
+    }
+
+}
+#endif //defined(PLATFORM_WIN32) || defined(PLATFORM_LINUX)
+
+BOOL FBDisplayDevice_Open(
+    RenderDevice*   device
+    )
+{
+    Uint32      coreIndex;
+    DecHandle   decHandle = device->decHandle;
+
+    VLOG(INFO, "%s\n", __FUNCTION__);
+    coreIndex = VPU_HANDLE_CORE_INDEX(decHandle);
+    PlatformDev_Open((coreIndex+1)*(device->decHandle->instIndex), 0, 0);
+
+    return TRUE;
+}
+
+void FBDisplayDevice_Render(
+    RenderDevice*   device,
+    DecOutputInfo*  fbInfo,     //!<< fbInfo is not used
+    Uint8*          pYuv,
+    Uint32          width,
+    Uint32          height
+    )
+{
+    Uint32          coreIndex = VPU_HANDLE_CORE_INDEX(device->decHandle);
+    Uint32          Bpp = 1;                                            //!<< Byte per pixel
+    FrameBuffer*    fbSrc = &fbInfo->dispFrame;
+
+    UNREFERENCED_PARAMETER(fbInfo);
+
+    switch (fbSrc->format) {
+    case FORMAT_420_P10_16BIT_LSB:
+    case FORMAT_420_P10_16BIT_MSB:
+    case FORMAT_420_P10_32BIT_LSB:
+    case FORMAT_420_P10_32BIT_MSB:
+        Bpp = 2;
+        break;
+    default:
+        Bpp = 1;
+    }
+    PlatformDev_Draw((coreIndex+1)*(device->decHandle->instIndex), 0, 0, width, height, fbSrc->format, pYuv, FALSE, Bpp*8);
+}
+
+BOOL FBDisplayDevice_Close(
+    RenderDevice*   device
+    )
+{
+    DecHandle   decHandle = device->decHandle;
+    Uint32      coreIndex = VPU_HANDLE_CORE_INDEX(decHandle);
+
+    PlatformDev_Close((coreIndex+1)*(device->decHandle->instIndex));
+
+    return TRUE;
+}
+ 

+ 163 - 0
wave420l/code/sample/helper/display/hdmi_impl.c

@@ -0,0 +1,163 @@
+//--=========================================================================--
+//  This file is a part of VPU Reference API project
+//-----------------------------------------------------------------------------
+//
+//       This confidential and proprietary software may be used only
+//     as authorized by a licensing agreement from Chips&Media Inc.
+//     In the event of publication, the following notice is applicable:
+//
+//            (C) COPYRIGHT 2006 - 2013  CHIPS&MEDIA INC.
+//                      ALL RIGHTS RESERVED
+//
+//       The entire notice above must be reproduced on all authorized
+//       copies.
+//
+//--=========================================================================--
+
+#include "main_helper.h"
+
+#define WAVE4_FRAME                 0x09000000
+#define DISP_BASE                   0x2a000000
+
+typedef struct HDMIContext_Struct {
+    Uint32   curDPBufY;
+    Uint32   curDPBufU;
+    Uint32   curDPBufV;
+    Uint32   count;
+} HDMIContext;
+
+BOOL HDMIDisplayDevice_Open(
+    RenderDevice*   device
+    )
+{
+    HDMIContext* ctx = (HDMIContext*)osal_malloc(sizeof(HDMIContext));
+    ctx->curDPBufY = 0;
+    ctx->curDPBufU = 0;
+    ctx->curDPBufV = 0;
+    ctx->count     = 0;
+    device->context = ctx;
+    return TRUE;
+}
+
+BOOL HDMIDisplayDevice_Close(
+    RenderDevice*   device
+    )
+{
+    osal_free(device->context);
+
+    return TRUE;
+}
+
+void HDMIDisplayDevice_Render(
+    RenderDevice*   device,
+    DecOutputInfo*  fbInfo,     //!<< fbInfo is not used
+    Uint8*          pYuv,
+    Uint32          width,
+    Uint32          height
+    )
+{
+    HDMIContext* ctx = device->context;
+    Int32        core_idx=0;
+    Int32        fry,frcb,frcr;
+    Int32        DP_BUFF_Y0 = 0x00000000;
+    Int32        DP_BUFF_U0 = 0x00800000;
+    Int32        DP_BUFF_V0 = 0x00c00000;
+    Int32        DP_BUFF_Y1 = 0x01000000;
+    Int32        DP_BUFF_U1 = 0x01800000;
+    Int32        DP_BUFF_V1 = 0x01c00000;
+    FrameBuffer* fp = &fbInfo->dispFrame;
+    BOOL         is4K; 
+    //-----------------------------------------------------------------------------------------------
+    //disp setting
+    is4K = (BOOL)(width > 1920 || height > 1088);
+
+    if (fp->myIndex) {
+        if(ctx->curDPBufY == DP_BUFF_Y1) {
+            ctx->curDPBufY = DP_BUFF_Y0;
+            ctx->curDPBufU = DP_BUFF_U0;
+            ctx->curDPBufV = DP_BUFF_V0;
+        }
+        else {
+            ctx->curDPBufY = DP_BUFF_Y1;
+            ctx->curDPBufU = DP_BUFF_U1;
+            ctx->curDPBufV = DP_BUFF_V1;
+        }
+    }
+    else {
+        if (ctx->curDPBufY == DP_BUFF_Y1) {
+            ctx->curDPBufY =DP_BUFF_Y0;
+            ctx->curDPBufU =DP_BUFF_U0;
+            ctx->curDPBufV =DP_BUFF_V0;
+        }
+        else {
+            ctx->curDPBufY =DP_BUFF_Y1;
+            ctx->curDPBufU =DP_BUFF_U1;
+            ctx->curDPBufV =DP_BUFF_V1;
+        }
+    }
+
+    fry  = fp->bufY; 
+    frcb = fp->bufCb;
+    frcr = fp->bufCr;
+
+    EnterLock(0);
+    //FRAME Y COPY
+    VpuWriteReg(core_idx, WAVE4_FRAME+0xc,  ((frcb- fry)/256));
+    VpuWriteReg(core_idx, WAVE4_FRAME+0x10, fp->bufY );
+    VpuWriteReg(core_idx, DISP_BASE+0x40,   ctx->curDPBufY);
+    VpuWriteReg(core_idx, WAVE4_FRAME+0x4,  0x0);
+
+    while(VpuReadReg(core_idx,WAVE4_FRAME+0x8)) {
+        MSleep(1);
+    }
+    //FRAME cb COPY
+    VpuWriteReg(core_idx, WAVE4_FRAME+0xc,  ((frcr- frcb)/256));
+    VpuWriteReg(core_idx, WAVE4_FRAME+0x10, fp->bufCb );
+    VpuWriteReg(core_idx, DISP_BASE+0x40,   ctx->curDPBufU);
+    VpuWriteReg(core_idx, WAVE4_FRAME+0x4,  0x0);
+
+    while(VpuReadReg(core_idx,WAVE4_FRAME+0x8)) {
+        MSleep(1);
+    }
+
+    //FRAME CR COPY
+    VpuWriteReg(core_idx, WAVE4_FRAME+0xc,  ((frcr- frcb)/256));
+    VpuWriteReg(core_idx, WAVE4_FRAME+0x10, fp->bufCr );
+    VpuWriteReg(core_idx, DISP_BASE+0x40,   ctx->curDPBufV);
+    VpuWriteReg(core_idx, WAVE4_FRAME+0x4,  0x0);
+
+    while(VpuReadReg(core_idx,WAVE4_FRAME+0x8)) {
+        MSleep(1);
+    }
+
+    if (is4K == TRUE) {
+        VpuWriteReg(core_idx, DISP_BASE+0x104, 0x00000000); //CLK 
+        VpuWriteReg(core_idx, DISP_BASE+0x004, 0x00000003); //
+        VpuWriteReg(core_idx, DISP_BASE+0x014, 0x00000006); //format 0 : RGB888i, 4 : YUV420p
+        VpuWriteReg(core_idx, DISP_BASE+0x034, 0x00000f00);
+        VpuWriteReg(core_idx, DISP_BASE+0x030, 0x00000001); //YUV->RGB
+        VpuWriteReg(core_idx, DISP_BASE+0x000, 0x00000001); //start
+    }
+    else {
+        VpuWriteReg(core_idx, DISP_BASE+0x104, 0x01);
+        VpuWriteReg(core_idx, DISP_BASE+0x004, 0x02);
+        VpuWriteReg(core_idx, DISP_BASE+0x034, fp->stride);
+        VpuWriteReg(core_idx, DISP_BASE+0x014, 0x06);
+        VpuWriteReg(core_idx, DISP_BASE+0x030, 0x01);
+        VpuWriteReg(core_idx, DISP_BASE+0x000, 0x01);
+    }
+
+    VpuWriteReg(core_idx, DISP_BASE+0x008, ctx->curDPBufY);
+    VpuWriteReg(core_idx, DISP_BASE+0x00c, ctx->curDPBufU);
+    VpuWriteReg(core_idx, DISP_BASE+0x010, ctx->curDPBufV);
+
+    ctx->count++;
+
+    if (ctx->count == 1) {
+        /* Waiting for initializing HDMI */
+        MSleep(1);
+    }
+
+    LeaveLock(0);
+}
+

+ 373 - 0
wave420l/code/sample/helper/display/simplerenderer.c

@@ -0,0 +1,373 @@
+//--=========================================================================--
+//  This file is a part of VPU Reference API project
+//-----------------------------------------------------------------------------
+//
+//       This confidential and proprietary software may be used only
+//     as authorized by a licensing agreement from Chips&Media Inc.
+//     In the event of publication, the following notice is applicable:
+//
+//            (C) COPYRIGHT 2006 - 2013  CHIPS&MEDIA INC.
+//                      ALL RIGHTS RESERVED
+//
+//       The entire notice above must be reproduced on all authorized
+//       copies.
+//
+//--=========================================================================--
+
+#include "vpuapifunc.h"
+#include <stdint.h>
+#include <string.h>
+#include "main_helper.h"
+
+typedef struct {
+    DecHandle       decHandle;      //!<< decoder handle
+    Uint32          period;         //!<< period of displaying picture in ms 
+    VpuThread       threadHandle;
+    BOOL            isRunning;
+    BOOL            stop;
+    BOOL            hasPrevSequence;
+    Queue*          Q;
+    Queue*          freeQ;
+    VpuMutex        lock;
+    RenderDevice*   device;
+    Uint32          numOfFrames;
+} RendererContext;
+
+typedef struct {
+    DecOutputInfo   fbInfo;
+    Uint8*          pYuv;
+    Uint32          displayWidth;
+    Uint32          displayHeight;
+} DisplayInfo;
+
+static BOOL NullDisplayDevice_Open(
+    RenderDevice*   device
+    )
+{
+    UNREFERENCED_PARAMETER(device);
+
+    return TRUE;
+}
+
+static void NullDisplayDevice_Render(
+    RenderDevice*   device,
+    DecOutputInfo*  fbInfo,
+    Uint8*          pYuv,
+    Uint32          width,
+    Uint32          height
+    )
+{
+    UNREFERENCED_PARAMETER(device);
+    UNREFERENCED_PARAMETER(fbInfo);
+    UNREFERENCED_PARAMETER(pYuv);
+    UNREFERENCED_PARAMETER(width);
+    UNREFERENCED_PARAMETER(height);
+}
+
+static BOOL NullDisplayDevice_Close(
+    RenderDevice*   device
+    )
+{
+    UNREFERENCED_PARAMETER(device);
+
+    return TRUE;
+}
+
+BOOL FBDisplayDevice_Close(
+    RenderDevice*   device
+);
+
+void FBDisplayDevice_Render(
+    RenderDevice*   device,
+    DecOutputInfo*  fbInfo,     //!<< fbInfo is not used
+    Uint8*          pYuv,
+    Uint32          width,
+    Uint32          height
+);
+
+BOOL FBDisplayDevice_Open(
+    RenderDevice*   device
+);
+
+BOOL HDMIDisplayDevice_Close(
+    RenderDevice*   device
+);
+
+void HDMIDisplayDevice_Render(
+    RenderDevice*   device,
+    DecOutputInfo*  fbInfo,     //!<< fbInfo is not used
+    Uint8*          pYuv,
+    Uint32          width,
+    Uint32          height
+);
+
+BOOL HDMIDisplayDevice_Open(
+    RenderDevice*   device
+);
+
+static RenderDevice* CreateRenderDevice(
+    DecHandle           decHandle,
+    RenderDeviceType    type
+    )
+{
+    RenderDevice* device = NULL;
+
+    switch (type) {
+    case RENDER_DEVICE_FBDEV:
+        device = osal_malloc(sizeof(RenderDevice));
+        device->context = NULL;
+        device->Open    = &FBDisplayDevice_Open;
+        device->Render  = &FBDisplayDevice_Render;
+        device->Close   = &FBDisplayDevice_Close;
+        break;
+    case RENDER_DEVICE_HDMI:
+        device = osal_malloc(sizeof(RenderDevice));
+        device->context = NULL;
+        device->Open    = &HDMIDisplayDevice_Open;
+        device->Render  = &HDMIDisplayDevice_Render;
+        device->Close   = &HDMIDisplayDevice_Close;
+        break;
+    default:
+        device = osal_malloc(sizeof(RenderDevice));
+        device->context = NULL;
+        device->Open    = &NullDisplayDevice_Open;
+        device->Render  = &NullDisplayDevice_Render;
+        device->Close   = &NullDisplayDevice_Close;
+        break;
+    }
+
+    device->decHandle = decHandle;
+
+    return device;
+}
+
+static void RenderPicture(
+    void* arg
+    )
+{
+    RendererContext* ctx = (RendererContext*)arg;
+    RenderDevice*    device;
+    DisplayInfo*     temp;
+    DisplayInfo      displayInfo;
+    DecOutputInfo*   fbInfo = NULL; 
+    Uint8*           pYuv  ; 
+    Uint32           width ; 
+    Uint32           height; 
+
+    device = ctx->device;
+
+    do {
+        ctx->isRunning = TRUE;
+        MSleep(ctx->period);
+
+        VpuMutex_Lock(ctx->lock);
+        temp = (DisplayInfo*)Queue_Dequeue(ctx->Q);
+
+        if (temp != NULL) {
+            osal_memcpy((void*)&displayInfo, temp, sizeof(DisplayInfo));
+            fbInfo = &displayInfo.fbInfo;
+            pYuv   = displayInfo.pYuv;
+            width  = displayInfo.displayWidth;
+            height = displayInfo.displayHeight;
+            device->Render(device, fbInfo, pYuv, width, height);
+            Queue_Enqueue(ctx->freeQ, (void*)&displayInfo.fbInfo);
+            if (displayInfo.pYuv) osal_free(displayInfo.pYuv);
+        }
+        VpuMutex_Unlock(ctx->lock);
+    } while (ctx->stop == FALSE);
+
+    VpuMutex_Lock(ctx->lock);
+    while ((temp=(DisplayInfo*)Queue_Dequeue(ctx->Q)) != NULL) {
+        fbInfo = &temp->fbInfo;
+        pYuv   = temp->pYuv;
+        width  = temp->displayWidth;
+        height = temp->displayHeight;
+        device->Render(device, fbInfo, pYuv, width, height);
+        if (temp->pYuv) osal_free(temp->pYuv);
+    }
+    VpuMutex_Unlock(ctx->lock);
+}
+
+Renderer SimpleRenderer_Create(
+    DecHandle           decHandle,
+    RenderDeviceType    deviceType,
+    const char*         yuvPath
+    )
+{
+    RendererContext* ctx = (RendererContext*)osal_malloc(sizeof(RendererContext));
+#ifdef PLATFORM_NON_OS
+#else
+    VpuThreadRunner     runner = (VpuThreadRunner)RenderPicture;
+#endif
+
+    osal_memset((void*)ctx, 0x00, sizeof(RendererContext));
+
+    ctx->decHandle   = decHandle;
+#ifdef PLATFORM_NON_OS
+    ctx->period      = 0;        // 33 ms, NTSC
+    ctx->stop        = TRUE;
+#else
+    ctx->period      = 33;        // 33 ms, NTSC
+    ctx->stop        = FALSE;
+#endif
+    ctx->isRunning   = FALSE;
+    ctx->numOfFrames = 0;
+    if ((ctx->Q=Queue_Create(32, sizeof(DisplayInfo))) == NULL) 
+        goto __FAILURE_RETURN;
+
+    if ((ctx->freeQ=Queue_Create(32, sizeof(DecOutputInfo))) == NULL) 
+        goto __FAILURE_RETURN;
+
+    if ((ctx->lock=VpuMutex_Create()) == NULL) 
+        goto __FAILURE_RETURN;
+
+    if ((ctx->device=CreateRenderDevice(decHandle, deviceType)) == NULL) 
+        goto __FAILURE_RETURN;
+
+    ctx->device->Open(ctx->device);
+    ctx->hasPrevSequence = FALSE;
+
+#ifdef PLATFORM_NON_OS
+    ctx->threadHandle = NULL;
+#else
+    ctx->threadHandle = VpuThread_Create(runner, (void*)ctx);
+    if (ctx->threadHandle == NULL) {
+        ctx->device->Close(ctx->device);
+        osal_free(ctx->device);
+        goto __FAILURE_RETURN;
+    }
+#endif
+
+    return (Renderer)ctx;
+
+__FAILURE_RETURN:
+    if (ctx->Q) Queue_Destroy(ctx->Q);
+    if (ctx->freeQ) Queue_Destroy(ctx->freeQ);
+    if (ctx->lock)  VpuMutex_Destroy(ctx->lock);
+    osal_free(ctx);
+
+    return NULL;
+}
+
+Uint32 SimpleRenderer_Act(
+    Renderer        renderer, 
+    DecOutputInfo*  fbInfo,
+    Uint8*          pYuv,
+    Uint32          width,
+    Uint32          height
+    )
+{
+    RendererContext* ctx = (RendererContext*)renderer;
+    DisplayInfo      displayInfo;
+
+    if (renderer == NULL) {
+        VLOG(ERR, "%s:%d Invalid handle\n", __FUNCTION__, __LINE__);
+        return 0;
+    }
+
+    ctx->numOfFrames++;
+
+    VpuMutex_Lock(ctx->lock);
+    osal_memset((void*)&displayInfo, 0x00, sizeof(DisplayInfo));
+    osal_memcpy((void*)&displayInfo.fbInfo, fbInfo, sizeof(DecOutputInfo));
+    displayInfo.pYuv          = pYuv;
+    displayInfo.displayWidth  = width;
+    displayInfo.displayHeight = height;
+    Queue_Enqueue(ctx->Q, (void*)&displayInfo);
+    VpuMutex_Unlock(ctx->lock);
+#ifdef PLATFORM_NON_OS
+    RenderPicture((void*)ctx);
+#endif
+
+    return ctx->numOfFrames; 
+}
+
+void SimpleRenderer_Flush(
+    Renderer        renderer
+    )
+{
+    RendererContext* ctx = (RendererContext*)renderer;
+    DisplayInfo*     temp = NULL;
+
+    VpuMutex_Lock(ctx->lock);
+
+    while ((temp=(DisplayInfo*)Queue_Dequeue(ctx->Q)) != NULL) {
+        Queue_Enqueue(ctx->freeQ, (void*)&temp->fbInfo);
+        if (temp->pYuv) osal_free(temp->pYuv);
+    } 
+
+    for (temp=NULL; temp!=NULL; temp=(DisplayInfo*)Queue_Dequeue(ctx->freeQ)) {
+        VPU_DecClrDispFlag(ctx->decHandle, temp->fbInfo.indexFrameDisplay);
+    }
+    VpuMutex_Unlock(ctx->lock);
+}
+
+void* SimpleRenderer_GetFreeFrameInfo(
+    Renderer        renderer
+    )
+{
+    RendererContext* ctx = (RendererContext*)renderer;
+    void* data = NULL;
+
+    if (renderer == NULL) {
+        VLOG(ERR, "%s:%d Invalid handle\n", __FUNCTION__, __LINE__);
+        return NULL;
+    }
+
+    VpuMutex_Lock(ctx->lock);
+    data = Queue_Dequeue(ctx->freeQ);
+    VpuMutex_Unlock(ctx->lock);
+
+    return data;
+}
+
+BOOL SimpleRenderer_Destroy(
+    Renderer        renderer
+    )
+{
+    RendererContext* ctx = (RendererContext*)renderer;
+
+    if (renderer == NULL) {
+        VLOG(ERR, "%s:%d Invalid handle\n", __FUNCTION__, __LINE__);
+        return FALSE;
+    }
+
+    ctx->stop = TRUE;
+
+    if (ctx->threadHandle) {
+        VpuThread_Join(ctx->threadHandle);
+    }
+	
+    VpuMutex_Destroy(ctx->lock);
+    Queue_Destroy(ctx->Q);
+    Queue_Destroy(ctx->freeQ);
+    ctx->device->Close(ctx->device);
+
+    osal_free(ctx->device);
+    osal_free(ctx);
+
+    return TRUE;
+}
+
+BOOL SimpleRenderer_SetFrameRate(
+    Renderer        renderer,
+    Uint32          fps
+    )
+{
+    RendererContext* ctx = (RendererContext*)renderer;
+
+    if (renderer == NULL) {
+        VLOG(ERR, "%s:%d Invalid handle\n", __FUNCTION__, __LINE__);
+        return FALSE;
+    }
+
+    if (fps == 0) {
+        ctx->period = 0;
+    }
+    else {
+        ctx->period = (Uint32)(1000/fps);
+    }
+
+    return TRUE;
+}
+ 

+ 2041 - 0
wave420l/code/sample/helper/main_helper.c

@@ -0,0 +1,2041 @@
+//--=========================================================================--
+//  This file is a part of VPU Reference API project
+//-----------------------------------------------------------------------------
+//
+//       This confidential and proprietary software may be used only
+//     as authorized by a licensing agreement from Chips&Media Inc.
+//     In the event of publication, the following notice is applicable:
+//
+//            (C) COPYRIGHT 2006 - 2014  CHIPS&MEDIA INC.
+//                      ALL RIGHTS RESERVED
+//
+//       The entire notice above must be reproduced on all authorized
+//       copies.
+//
+//--=========================================================================--
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <string.h>
+#include <time.h>
+#include <errno.h>
+#include "vpuapifunc.h"
+#include "coda9/coda9_regdefine.h"
+#include "wave/common/common_vpuconfig.h"
+#include "wave/common/common_regdefine.h"
+#include "wave/wave4/wave4_regdefine.h"
+#include "wave/wave5/wave5_regdefine.h"
+#include "wave/coda7q/coda7q_regdefine.h"
+#include "vpuerror.h"
+#include "main_helper.h"
+#ifdef PLATFORM_LINUX
+#include <getopt.h>
+#endif
+
+#define BIT_DUMMY_READ_GEN          0x06000000
+#define BIT_READ_LATENCY            0x06000004
+#define W4_SET_READ_DELAY           0x01000000
+#define W4_SET_WRITE_DELAY          0x01000004
+#define MAX_CODE_BUF_SIZE           (512*1024)
+
+#ifdef PLATFORM_WIN32
+#pragma warning(disable : 4996)     //!<< disable waring C4996: The POSIX name for this item is deprecated. 
+#endif
+
+char* EncPicTypeStringH264[] = {
+    "IDR/I",
+    "P",
+};
+
+char* EncPicTypeStringMPEG4[] = {
+    "I",
+    "P",
+};
+
+char* productNameList[] = {
+    "CODA980",
+    "CODA960",
+    "CODA7503",
+    "WAVE320",
+    "WAVE410",
+    "WAVE4102",
+    "WAVE420",
+    "WAVE412",
+    "WAVE7Q",
+    "WAVE420L",
+    "WAVE510",
+    "WAVE512",
+    "WAVE515",
+    "WAVE520",
+    "Unknown",
+    "Unknown",
+};
+
+#if defined(PLATFORM_LINUX) || defined(PLATFORM_QNX)
+#include <sys/stat.h>
+#include <unistd.h>
+#endif
+
+Int32 LoadFirmware(
+    Int32       productId, 
+    Uint8**     retFirmware, 
+    Uint32*     retSizeInWord, 
+    const char* path
+    )
+{
+    Int32       nread;
+    Uint32      totalRead, allocSize, readSize = 1024*1024;
+    Uint8*      firmware = NULL;
+    osal_file_t fp;    
+
+    if ((fp=osal_fopen(path, "rb")) == NULL)
+    {
+        VLOG(ERR, "Failed to open %s\n", path);
+        return -1;
+    }
+
+    totalRead = 0;
+    if (PRODUCT_ID_W_SERIES(productId)) 
+    {
+        firmware = (Uint8*)osal_malloc(readSize);
+        allocSize = readSize;
+        nread = 0;
+        while (TRUE)
+        {
+            if (allocSize < (totalRead+readSize)) 
+            {
+                allocSize += 2*nread;
+                firmware = (Uint8*)realloc(firmware, allocSize);
+            }
+            nread = osal_fread((void*)&firmware[totalRead], 1, readSize, fp);
+            totalRead += nread;
+            if (nread < (Int32)readSize) break;
+        }
+        *retSizeInWord = (totalRead+1)/2;
+    }
+    else 
+    {
+        Uint16*     pusBitCode;
+        pusBitCode = (Uint16 *)osal_malloc(MAX_CODE_BUF_SIZE);
+        firmware   = (Uint8*)pusBitCode;
+        if (pusBitCode)
+        {
+            int code;
+            while (!osal_feof(fp) || totalRead < (MAX_CODE_BUF_SIZE/2)) {
+                code = -1;
+                if (fscanf(fp, "%x", &code) <= 0) {
+                    /* matching failure or EOF */
+                    break;
+                }
+                pusBitCode[totalRead++] = (Uint16)code;
+            }
+        }
+        *retSizeInWord = totalRead;
+    }
+
+    osal_fclose(fp);
+
+    *retFirmware   = firmware;
+
+    return 0;
+}
+
+void PrintVpuVersionInfo(
+    Uint32   core_idx
+    )
+{
+    Uint32 version;
+    Uint32 revision;
+    Uint32 productId;
+
+    VPU_GetVersionInfo(core_idx, &version, &revision, &productId);	
+
+    VLOG(INFO, "VPU coreNum : [%d]\n", core_idx);
+    VLOG(INFO, "Firmware : CustomerCode: %04x | version : %d.%d.%d rev.%d\n", 
+        (Uint32)(version>>16), (Uint32)((version>>(12))&0x0f), (Uint32)((version>>(8))&0x0f), (Uint32)((version)&0xff), revision);
+    VLOG(INFO, "Hardware : %04x\n", productId);
+    VLOG(INFO, "API      : %d.%d.%d\n\n", API_VERSION_MAJOR, API_VERSION_MINOR, API_VERSION_PATCH);	
+}
+
+BOOL OpenDisplayBufferFile(char *outputPath, VpuRect rcDisplay, TiledMapType mapType, FILE *fp[])
+{
+	char strFile[MAX_FILE_PATH];
+	int width;
+	int height;
+	
+	width = rcDisplay.right - rcDisplay.left;
+	height = rcDisplay.bottom - rcDisplay.top;
+
+	if (mapType == LINEAR_FRAME_MAP) {
+		if ((fp[0]=osal_fopen(outputPath, "wb")) == NULL) {
+			VLOG(ERR, "%s:%d failed to open %s\n", __FUNCTION__, __LINE__, outputPath);
+			goto ERR_OPEN_DISP_BUFFER_FILE;
+		}
+	}
+	else {
+		width = VPU_ALIGN16(width);
+		height = VPU_ALIGN16(height);
+		sprintf(strFile, "%s_%dx%d_fbc_data_y.bin", outputPath, width, height);
+		if ((fp[0]=osal_fopen(strFile, "wb")) == NULL) {
+			VLOG(ERR, "%s:%d failed to open %s\n", __FUNCTION__, __LINE__, strFile);
+			goto ERR_OPEN_DISP_BUFFER_FILE;
+		}
+		sprintf(strFile, "%s_%dx%d_fbc_data_c.bin", outputPath, width, height);
+		if ((fp[1]=osal_fopen(strFile, "wb")) == NULL) {
+			VLOG(ERR, "%s:%d failed to open %s\n", __FUNCTION__, __LINE__, strFile);
+			goto ERR_OPEN_DISP_BUFFER_FILE;
+		}
+		sprintf(strFile, "%s_%dx%d_fbc_table_y.bin", outputPath, width, height);
+		if ((fp[2]=osal_fopen(strFile, "wb")) == NULL) {
+			VLOG(ERR, "%s:%d failed to open %s\n", __FUNCTION__, __LINE__, strFile);
+			goto ERR_OPEN_DISP_BUFFER_FILE;
+		}
+		sprintf(strFile, "%s_%dx%d_fbc_table_c.bin", outputPath, width, height);
+		if ((fp[3]=osal_fopen(strFile, "wb")) == NULL) {
+			VLOG(ERR, "%s:%d failed to open %s\n", __FUNCTION__, __LINE__, strFile);
+			goto ERR_OPEN_DISP_BUFFER_FILE;
+		}
+	}
+	return TRUE;
+ERR_OPEN_DISP_BUFFER_FILE:
+	CloseDisplayBufferFile(fp);
+	return FALSE;
+}
+
+void CloseDisplayBufferFile(FILE *fp[])
+{
+	int i;
+	for (i=0; i < OUTPUT_FP_NUMBER; i++) {
+		if (fp[i] != NULL) {
+			osal_fclose(fp[i]);
+			fp[i] = NULL;
+		}
+	}
+}
+
+void SaveDisplayBufferToFile(DecHandle handle, FrameBuffer dispFrame, VpuRect rcDisplay, FILE *fp[])
+{
+	Uint32   width;
+	Uint32   height;
+	Uint32   bpp;
+	DecGetFramebufInfo  fbInfo;
+
+	if (dispFrame.myIndex < 0)
+		return;
+
+	if (dispFrame.mapType != COMPRESSED_FRAME_MAP) {
+		//VLOG(INFO, "---> DUMP LINEAR(WTL) FRAMEBUFFER #%d\n", dispFrame.myIndex);
+		size_t sizeYuv;
+		Uint8*   pYuv;
+		pYuv = GetYUVFromFrameBuffer(handle, &dispFrame, rcDisplay, &width, &height, &bpp, &sizeYuv);
+		osal_fwrite(pYuv, 1, sizeYuv, fp[0]);
+		osal_free(pYuv);
+	}
+	else {
+		int lumaTblSize;
+		int chromaTblSize;
+		int lSize;
+		int cSize;
+		Uint32   addr;
+		Uint32   fbc_endian;
+		unsigned char *buf;
+
+		int coreIdx = VPU_HANDLE_CORE_INDEX(handle);
+
+		//VLOG(INFO, "---> DUMP COMPRESSED FRAMEBUFFER #%d\n", dispFrame.myIndex);
+		VPU_DecGiveCommand(handle, DEC_GET_FRAMEBUF_INFO, (void*)&fbInfo);
+
+		width = rcDisplay.right - rcDisplay.left;
+		height = rcDisplay.bottom - rcDisplay.top;
+
+		width = VPU_ALIGN16(width);
+		height = VPU_ALIGN16(height);
+
+		switch (dispFrame.format) {
+		case FORMAT_420_P10_16BIT_LSB:
+		case FORMAT_420_P10_16BIT_MSB:
+			bpp = 2;
+			break;
+		case FORMAT_420_P10_32BIT_LSB:
+		case FORMAT_420_P10_32BIT_MSB:
+			bpp = 1;
+			break;
+		default:
+			bpp = 1;
+			break;
+		}
+
+ 		fbc_endian = vdi_convert_endian(coreIdx, dispFrame.endian);
+
+		lSize = width * height * bpp;
+		cSize = width * height * bpp / 2;
+		/* Dump Y compressed data */
+		buf = osal_malloc(lSize);
+		if (buf)
+		{
+			vdi_read_memory(coreIdx, dispFrame.bufY, buf, lSize, fbc_endian);
+			osal_fwrite((void *)buf, sizeof(Uint8), lSize, fp[0]);
+			osal_fflush(fp[0]);
+			osal_free(buf);
+		}
+
+		/* Dump C compressed data */
+		buf = osal_malloc(cSize);
+		if (buf)
+		{
+			vdi_read_memory(coreIdx, dispFrame.bufCb, buf, cSize, fbc_endian);
+			osal_fwrite((void *)buf, sizeof(Uint8), cSize, fp[1]);
+			osal_fflush(fp[1]);
+			osal_free(buf);
+		}
+
+		/* Dump Y Offset table */
+		VPU_GetFBCOffsetTableSize(STD_HEVC, (int)width, (int)height, (int*)&lumaTblSize, (int*)&chromaTblSize);
+
+		addr = fbInfo.vbFbcYTbl[dispFrame.myIndex].phys_addr;
+
+		buf = osal_malloc(lumaTblSize);
+		if (buf)
+		{
+			vdi_read_memory(coreIdx, addr, buf, lumaTblSize, fbc_endian);
+			osal_fwrite((void *)buf, sizeof(Uint8), lumaTblSize, fp[2]);
+			osal_fflush(fp[2]);
+			osal_free(buf);
+		}
+
+		/* Dump C Offset table */		
+		addr = fbInfo.vbFbcCTbl[dispFrame.myIndex].phys_addr;
+
+		buf = osal_malloc(chromaTblSize);
+		if (buf)
+		{
+			vdi_read_memory(coreIdx, addr, buf, chromaTblSize, fbc_endian);
+			osal_fwrite((void *)buf, sizeof(Uint8), chromaTblSize, fp[3]);
+			osal_fflush(fp[3]);
+			osal_free(buf);
+		}
+
+	}
+
+}
+void FreePreviousFramebuffer(
+    Uint32              coreIdx, 
+    DecGetFramebufInfo* fb
+    )
+{
+    int i;
+    if (fb->vbFrame.size > 0) {
+        vdi_free_dma_memory(coreIdx, &fb->vbFrame);
+        osal_memset((void*)&fb->vbFrame, 0x00, sizeof(vpu_buffer_t));
+    }
+    if (fb->vbWTL.size > 0) {
+        vdi_free_dma_memory(coreIdx, &fb->vbWTL);
+        osal_memset((void*)&fb->vbWTL, 0x00, sizeof(vpu_buffer_t));
+    }
+    for ( i=0 ; i<MAX_REG_FRAME; i++) {
+        if (fb->vbFbcYTbl[i].size > 0) {
+            vdi_free_dma_memory(coreIdx, &fb->vbFbcYTbl[i]);
+            osal_memset((void*)&fb->vbFbcYTbl, 0x00, sizeof(vpu_buffer_t));
+        }
+        if (fb->vbFbcCTbl[i].size > 0) {
+            vdi_free_dma_memory(coreIdx, &fb->vbFbcCTbl[i]);
+            osal_memset((void*)&fb->vbFbcCTbl, 0x00, sizeof(vpu_buffer_t));
+        }
+    }
+}
+
+void PrintDecSeqWarningMessages(
+    Uint32          productId, 
+    DecInitialInfo* seqInfo
+    )
+{
+    if (PRODUCT_ID_W_SERIES(productId)) 
+    {
+        if (seqInfo->seqInitErrReason&0x00000001) VLOG(WARN, "sps_max_sub_layer_minus1 shall be 0 to 6\n");
+        if (seqInfo->seqInitErrReason&0x00000002) VLOG(WARN, "general_reserved_zero_44bits shall be 0.\n");
+        if (seqInfo->seqInitErrReason&0x00000004) VLOG(WARN, "reserved_zero_2bits shall be 0\n");
+        if (seqInfo->seqInitErrReason&0x00000008) VLOG(WARN, "sub_layer_reserved_zero_44bits shall be 0");
+        if (seqInfo->seqInitErrReason&0x00000010) VLOG(WARN, "general_level_idc shall have one of level of Table A.1\n");
+        if (seqInfo->seqInitErrReason&0x00000020) VLOG(WARN, "sps_max_dec_pic_buffering[i] <= MaxDpbSize\n");
+        if (seqInfo->seqInitErrReason&0x00000040) VLOG(WARN, "trailing bits shall be 1000... pattern, 7.3.2.1\n");
+        if (seqInfo->seqInitErrReason&0x00100000) VLOG(WARN, "Not supported or undefined profile: %d\n", seqInfo->profile);
+        if (seqInfo->seqInitErrReason&0x00200000) VLOG(WARN, "Spec over level(%d)\n", seqInfo->level);
+    }
+}
+
+void DisplayDecodedInformationForHevc(
+    DecHandle      handle, 
+    Uint32         frameNo, 
+    DecOutputInfo* decodedInfo
+    )
+{
+    Int32 logLevel;
+
+    if (decodedInfo == NULL) {
+        if (handle->productId == PRODUCT_ID_510 || handle->productId == PRODUCT_ID_512) {
+            VLOG(TRACE, "I    NO  T     POC     NAL  DECO  DISP PRESCAN DISPFLAG  RD_PTR   WR_PTR  FRM_START FRM_END   WxH      SEQ  TEMP CYCLE (Seek, Parse, Dec)\n");
+        }
+        else {
+            VLOG(TRACE, "I    NO  T     POC     NAL  DECO  DISP PRESCAN DISPFLAG  RD_PTR   WR_PTR  FRM_START FRM_END   WxH      SEQ  TEMP CYCLE  \n");
+        }
+        VLOG(TRACE, "------------------------------------------------------------------------------------------------------------\n");
+    }
+    else {
+        logLevel = (decodedInfo->decodingSuccess&0x01) == 0 ? ERR : TRACE;
+        if (handle->productId == PRODUCT_ID_4102) {
+            logLevel = (decodedInfo->indexFramePrescan == -2) ? TRACE : logLevel;
+        }
+        // Print informations
+        if (handle->productId == PRODUCT_ID_510 || handle->productId == PRODUCT_ID_512) {
+            VLOG(logLevel, "%02d %5d %d %4d(%4d) %3d %2d(%2d) %2d(%2d) %7d %08x %08x %08x %08x %08x %4dx%-4d %4d  %4d %d(%d,%d,%d)\n",
+                handle->instIndex, frameNo, decodedInfo->picType, 
+                decodedInfo->h265Info.decodedPOC, decodedInfo->h265Info.displayPOC, decodedInfo->nalType,
+                decodedInfo->indexFrameDecoded, decodedInfo->indexFrameDecodedForTiled,
+                decodedInfo->indexFrameDisplay, decodedInfo->indexFrameDisplayForTiled,
+                decodedInfo->indexFramePrescan,
+                decodedInfo->frameDisplayFlag,decodedInfo->rdPtr, decodedInfo->wrPtr, 
+                decodedInfo->bytePosFrameStart, decodedInfo->bytePosFrameEnd,
+                decodedInfo->dispPicWidth, decodedInfo->dispPicHeight, decodedInfo->sequenceNo, 
+                decodedInfo->h265Info.temporalId, decodedInfo->frameCycle, decodedInfo->seekCycle, decodedInfo->parseCycle, decodedInfo->decodeCycle);
+        }
+        else {
+            VLOG(logLevel, "%02d %5d %d %4d(%4d) %3d %2d(%2d) %2d(%2d) %7d %08x %08x %08x %08x %08x %4dx%-4d %4d  %4d %d\n",
+                handle->instIndex, frameNo, decodedInfo->picType, 
+                decodedInfo->h265Info.decodedPOC, decodedInfo->h265Info.displayPOC, decodedInfo->nalType,
+                decodedInfo->indexFrameDecoded, decodedInfo->indexFrameDecodedForTiled,
+                decodedInfo->indexFrameDisplay, decodedInfo->indexFrameDisplayForTiled,
+                decodedInfo->indexFramePrescan,
+                decodedInfo->frameDisplayFlag,decodedInfo->rdPtr, decodedInfo->wrPtr, 
+                decodedInfo->bytePosFrameStart, decodedInfo->bytePosFrameEnd,
+                decodedInfo->dispPicWidth, decodedInfo->dispPicHeight, decodedInfo->sequenceNo, 
+                decodedInfo->h265Info.temporalId, decodedInfo->frameCycle);
+        }
+        if (logLevel == ERR) {
+            VLOG(ERR, "\t>>ERROR REASON: 0x%08x(0x%08x)\n", decodedInfo->errorReason, decodedInfo->errorReasonExt);
+        }
+        if (decodedInfo->numOfErrMBs) {
+            VLOG(WARN, "\t>> ErrorBlock: %d\n", decodedInfo->numOfErrMBs);
+        }
+    }
+}
+
+void DisplayDecodedInformationForVP9(DecHandle handle, Uint32 frameNo, DecOutputInfo* decodedInfo)
+{
+    Int32 logLevel;
+
+    if (decodedInfo == NULL) {
+        // Print header
+        VLOG(TRACE, "I  NO    T   DECO   DISP PRESCAN DISPFLAG   RD_PTR   WR_PTR FRM_START FRM_END    WxH     SEQ  CYCLE\n");
+        VLOG(TRACE, "--------------------------------------------------------------------------------------------\n");
+    }
+    else {
+        logLevel = (decodedInfo->decodingSuccess&0x01) == 0 ? ERR : TRACE;
+        // Print informations
+        VLOG(logLevel, "%02d %5d %d %2d(%2d) %2d(%2d) %7d %08x %08x %08x %08x %08x %4dx%-4d %4d %d\n",
+            handle->instIndex, frameNo, decodedInfo->picType, 
+            decodedInfo->indexFrameDecoded, decodedInfo->indexFrameDecodedForTiled,
+            decodedInfo->indexFrameDisplay, decodedInfo->indexFrameDisplayForTiled,
+            decodedInfo->indexFramePrescan,
+            decodedInfo->frameDisplayFlag,decodedInfo->rdPtr, decodedInfo->wrPtr, 
+            decodedInfo->bytePosFrameStart, decodedInfo->bytePosFrameEnd,
+            decodedInfo->dispPicWidth, decodedInfo->dispPicHeight, 
+            decodedInfo->sequenceNo, decodedInfo->frameCycle
+        );
+        if (logLevel == ERR) {
+            VLOG(ERR, "\t>>ERROR REASON: 0x%08x(0x%08x)\n", decodedInfo->errorReason, decodedInfo->errorReasonExt);
+        }
+        if (decodedInfo->numOfErrMBs) {
+            VLOG(WARN, "\t>> ErrorBlock: %d\n", decodedInfo->numOfErrMBs);
+        }
+    }
+}
+
+void DisplayDecodedInformationCommon(DecHandle handle, CodStd codec, Uint32 frameNo, DecOutputInfo* decodedInfo)
+{
+    Int32 logLevel;
+
+    if (decodedInfo == NULL) {
+        // Print header
+        VLOG(TRACE, "I  NO    T TID DEC_POC   DECO   DISP  DISPFLAG RD_PTR   WR_PTR   FRM_START FRM_END  WxH\n");
+        VLOG(TRACE, "---------------------------------------------------------------------------------------\n");
+    }
+    else {
+        VpuRect rc    = decodedInfo->rcDisplay;
+        Uint32 width  = rc.right - rc.left;
+        Uint32 height = rc.bottom - rc.top;
+        char   strTemporalId[16];
+        char   strPoc[16];
+
+
+        logLevel = (decodedInfo->decodingSuccess&0x01) == 0 ? ERR : TRACE;
+        // Print informations
+        VLOG(logLevel, "%02d %5d %d  %s  %s %2d(%2d) %2d(%2d) %08x %08x %08x %08x  %08x %dx%d\n",
+            handle->instIndex, frameNo, decodedInfo->picType, strTemporalId, strPoc,
+            decodedInfo->indexFrameDecoded, decodedInfo->indexFrameDecodedForTiled,
+            decodedInfo->indexFrameDisplay, decodedInfo->indexFrameDisplayForTiled,
+            decodedInfo->frameDisplayFlag,decodedInfo->rdPtr, decodedInfo->wrPtr, 
+            decodedInfo->bytePosFrameStart, decodedInfo->bytePosFrameEnd,
+            width, height);
+        if (logLevel == ERR) {
+            VLOG(ERR, "\t>>ERROR REASON: 0x%08x(0x%08x)\n", decodedInfo->errorReason, decodedInfo->errorReasonExt);
+        }
+        if (decodedInfo->numOfErrMBs) {
+            VLOG(WARN, "\t>> ErrorBlock: %d\n", decodedInfo->numOfErrMBs);
+        }
+    }
+}
+
+/**
+* \brief                   Print out decoded information such like RD_PTR, WR_PTR, PIC_TYPE, ..
+* \param   decodedInfo     If this parameter is not NULL then print out decoded informations
+*                          otherwise print out header.
+*/
+void DisplayDecodedInformation(DecHandle handle, CodStd codec, Uint32 frameNo, DecOutputInfo* decodedInfo)
+{
+    switch (codec) 
+    {
+    case STD_HEVC:
+        DisplayDecodedInformationForHevc(handle, frameNo, decodedInfo);
+        break;
+    case STD_VP9:
+        DisplayDecodedInformationForVP9(handle, frameNo, decodedInfo);
+        break;
+    default:
+        DisplayDecodedInformationCommon(handle, codec, frameNo, decodedInfo);
+        break;
+    }
+
+    return;
+}
+
+static void Wave4DisplayEncodedInformation(
+    EncHandle       handle, 
+    CodStd          codec,
+    Uint32          frameNo, 
+    EncOutputInfo*  encodedInfo,
+    Int32           srcEndFlag,
+    Int32           srcFrameIdx
+    )
+{
+    if (encodedInfo == NULL) {
+        VLOG(INFO, "------------------------------------------------------------------------------\n");
+        VLOG(INFO, "I     NO     T   RECON   RD_PTR    WR_PTR     BYTES  SRCIDX  USEDSRCIDX Cycle \n");
+        VLOG(INFO, "------------------------------------------------------------------------------\n");
+    } else {
+        VLOG(INFO, "%02d %5d %5d %5d    %08x  %08x %8x     %2d        %2d    %8d\n", 
+            handle->instIndex, encodedInfo->encPicCnt, encodedInfo->picType, encodedInfo->reconFrameIndex, encodedInfo->rdPtr, encodedInfo->wrPtr, 
+            encodedInfo->bitstreamSize, (srcEndFlag == 1 ? -1 : srcFrameIdx), encodedInfo->encSrcIdx, encodedInfo->frameCycle);
+    }
+}
+
+static void Wave5DisplayEncodedInformation(
+    EncHandle       handle, 
+    CodStd          codec,
+    Uint32          frameNo, 
+    EncOutputInfo*  encodedInfo,
+    Int32           srcEndFlag,
+    Int32           srcFrameIdx
+    )
+{
+    if (encodedInfo == NULL) {
+        VLOG(INFO, "--------------------------------------------------------------------------------------------------------------\n");
+        VLOG(INFO, "                                                                        |             Cycle\n");
+        VLOG(INFO, "I     NO     T   RECON   RD_PTR    WR_PTR     BYTES  SRCIDX  USEDSRCIDX | FRAME PREPARING PROCESSING ENCODING\n");
+        VLOG(INFO, "--------------------------------------------------------------------------------------------------------------\n");
+    } else {
+        VLOG(INFO, "%02d %5d %5d %5d    %08x  %08x %8x     %2d        %2d    %8d %8d %8d %8d\n", 
+            handle->instIndex, encodedInfo->encPicCnt, encodedInfo->picType, encodedInfo->reconFrameIndex, encodedInfo->rdPtr, encodedInfo->wrPtr, 
+            encodedInfo->bitstreamSize, (srcEndFlag == 1 ? -1 : srcFrameIdx), encodedInfo->encSrcIdx, 
+            encodedInfo->frameCycle, encodedInfo->encPrepareCycle, encodedInfo->encProcessingCycle, encodedInfo->encEncodingCycle);
+    }
+}
+
+static void Coda9DisplayEncodedInformation(
+    DecHandle       handle, 
+    CodStd          codec,
+    Uint32          frameNo, 
+    EncOutputInfo*  encodedInfo
+    )
+{
+    if (encodedInfo == NULL) {
+        // Print header
+        VLOG(INFO, "I    NO   T   RECON  RD_PTR   WR_PTR \n");
+        VLOG(INFO, "-------------------------------------\n");
+    }
+    else {
+        char** picTypeArray = (codec==STD_AVC ? EncPicTypeStringH264 : EncPicTypeStringMPEG4);
+        char* strPicType;
+
+        if (encodedInfo->picType > 2) strPicType = "?";
+        else                          strPicType = picTypeArray[encodedInfo->picType];
+        // Print informations
+        VLOG(INFO, "%02d %5d %5s %5d  %08x %08x\n",
+            handle->instIndex, frameNo, strPicType,
+            encodedInfo->reconFrameIndex, encodedInfo->rdPtr, encodedInfo->wrPtr);
+    }
+}
+
+/*lint -esym(438, ap) */
+void 
+    DisplayEncodedInformation(
+    EncHandle      handle, 
+    CodStd         codec, 
+    Uint32         frameNo, 
+    EncOutputInfo* encodedInfo,
+    ...
+    )
+{
+    int srcEndFlag;
+    int srcFrameIdx;
+    va_list         ap;
+
+    switch (codec) {
+    case STD_HEVC:
+        va_start(ap, encodedInfo);
+        srcEndFlag = va_arg(ap, Uint32);
+        srcFrameIdx = va_arg(ap, Uint32);
+        va_end(ap);
+        if(handle->productId == PRODUCT_ID_520 )
+            Wave5DisplayEncodedInformation(handle, codec, frameNo, encodedInfo, srcEndFlag , srcFrameIdx);
+        else
+            Wave4DisplayEncodedInformation(handle, codec, frameNo, encodedInfo, srcEndFlag , srcFrameIdx);
+        break;
+    default:
+        Coda9DisplayEncodedInformation(handle, codec, frameNo, encodedInfo);
+        break;
+    }
+
+    return;
+}
+/*lint +esym(438, ap) */
+
+
+
+
+void ChangePathStyle(
+    char *str
+    )
+{
+}
+
+void ReleaseVideoMemory(
+    Uint32          coreIndex,
+    vpu_buffer_t*   memoryArr,
+    Uint32          count
+    )
+{
+    Uint32      index;
+
+    for (index=0; index<count; index++) {
+        if (memoryArr[index].size) 
+            vdi_free_dma_memory(coreIndex, &memoryArr[index]);
+    }
+}
+
+BOOL AllocateDecFrameBuffer(
+    DecHandle       decHandle,
+    TestDecConfig*  config,
+    Uint32          tiledFbCount,
+    Uint32          linearFbCount,
+    FrameBuffer*    retFbArray,
+    vpu_buffer_t*   retFbAddrs,
+    Uint32*         retStride
+    )
+{
+    Uint32                  framebufSize;
+    Uint32                  totalFbCount;
+    Uint32                  coreIndex;
+    Uint32                  index;
+    FrameBufferFormat       format = config->wtlFormat;
+    DecInitialInfo          seqInfo;
+    FrameBufferAllocInfo    fbAllocInfo;
+    RetCode                 ret;
+    vpu_buffer_t*           pvb;
+    size_t                  framebufStride;
+    size_t                  framebufHeight;
+    Uint32                  productId;
+    DRAMConfig*             pDramCfg        = NULL;
+    DRAMConfig              dramCfg         = {0};
+
+    coreIndex = VPU_HANDLE_CORE_INDEX(decHandle);
+    productId = VPU_HANDLE_PRODUCT_ID(decHandle);
+    VPU_DecGiveCommand(decHandle, DEC_GET_SEQ_INFO, (void*)&seqInfo);
+
+    if (productId == PRODUCT_ID_960) {
+        pDramCfg = &dramCfg;
+        ret = VPU_DecGiveCommand(decHandle, GET_DRAM_CONFIG, pDramCfg);
+    }
+
+    totalFbCount = tiledFbCount + linearFbCount;
+
+    if (productId == PRODUCT_ID_4102 || productId == PRODUCT_ID_420 || productId == PRODUCT_ID_412 || productId == PRODUCT_ID_420L ||
+        productId == PRODUCT_ID_510 || productId == PRODUCT_ID_512 || productId == PRODUCT_ID_515) {
+        format = (seqInfo.lumaBitdepth > 8 || seqInfo.chromaBitdepth > 8) ? FORMAT_420_P10_16BIT_LSB : FORMAT_420;
+    }
+    else if (productId == PRODUCT_ID_7Q) {
+        if (decHandle->codecMode == HEVC_DEC)
+            format = (seqInfo.lumaBitdepth > 8 || seqInfo.chromaBitdepth > 8) ? FORMAT_420_P10_16BIT_LSB : FORMAT_420;
+        else
+            format = FORMAT_420;
+    }
+
+    if (decHandle->codecMode == C7_VP9_DEC) {
+        framebufStride = CalcStride(VPU_ALIGN64(seqInfo.picWidth), seqInfo.picHeight, format, config->cbcrInterleave, config->mapType, TRUE);
+        framebufHeight = VPU_ALIGN64(seqInfo.picHeight);
+        framebufSize   = VPU_GetFrameBufSize(decHandle->coreIdx, framebufStride, framebufHeight, 
+            config->mapType, format, config->cbcrInterleave, NULL);
+        *retStride     = framebufStride;
+    }
+    else if (productId == PRODUCT_ID_7Q && decHandle->codecMode != C7_HEVC_DEC) {
+        framebufStride = CalcStride(seqInfo.picWidth, seqInfo.picHeight, format, config->cbcrInterleave, config->mapType, FALSE);
+        framebufHeight = seqInfo.interlace ? VPU_ALIGN32(seqInfo.picHeight) : VPU_ALIGN16(seqInfo.picHeight);
+        framebufSize   = VPU_GetFrameBufSize(decHandle->coreIdx, framebufStride, framebufHeight, 
+                                             config->mapType, format, config->cbcrInterleave, NULL);
+        *retStride     = framebufStride;
+    }
+    else if (decHandle->codecMode == C7_AVS2_DEC) {
+        framebufStride = CalcStride(seqInfo.picWidth, seqInfo.picHeight, format, config->cbcrInterleave, config->mapType, FALSE);
+        framebufHeight = VPU_ALIGN8(seqInfo.picHeight);
+        framebufSize   = VPU_GetFrameBufSize(decHandle->coreIdx, framebufStride, framebufHeight, 
+            config->mapType, format, config->cbcrInterleave, pDramCfg);
+        *retStride     = framebufStride;
+    }
+    else {
+        *retStride     = VPU_ALIGN32(seqInfo.picWidth);
+        framebufStride = CalcStride(seqInfo.picWidth, seqInfo.picHeight, format, config->cbcrInterleave, config->mapType, FALSE);
+        framebufHeight = seqInfo.picHeight;
+        framebufSize   = VPU_GetFrameBufSize(decHandle->coreIdx, framebufStride, seqInfo.picHeight, 
+                                             config->mapType, format, config->cbcrInterleave, pDramCfg);
+    }
+
+    osal_memset((void*)&fbAllocInfo, 0x00, sizeof(fbAllocInfo));
+    osal_memset((void*)retFbArray,   0x00, sizeof(FrameBuffer)*totalFbCount);
+    fbAllocInfo.format          = format;
+    fbAllocInfo.cbcrInterleave  = config->cbcrInterleave;
+    fbAllocInfo.mapType         = config->mapType;
+    fbAllocInfo.stride          = framebufStride;
+    fbAllocInfo.height          = framebufHeight;
+    fbAllocInfo.size            = framebufSize;
+    fbAllocInfo.lumaBitDepth    = seqInfo.lumaBitdepth;
+    fbAllocInfo.chromaBitDepth  = seqInfo.chromaBitdepth;
+    fbAllocInfo.num             = tiledFbCount;
+    fbAllocInfo.endian          = config->frameEndian;
+    fbAllocInfo.type            = FB_TYPE_CODEC;
+    osal_memset((void*)retFbAddrs, 0x00, sizeof(vpu_buffer_t)*totalFbCount);
+    for (index=0; index<tiledFbCount; index++) {
+        pvb = &retFbAddrs[index];
+        pvb->size = framebufSize;
+        if (vdi_allocate_dma_memory(coreIndex, pvb) < 0) {
+            VLOG(ERR, "%s:%d fail to allocate frame buffer\n", __FUNCTION__, __LINE__);
+            ReleaseVideoMemory(coreIndex, retFbAddrs, totalFbCount);
+            return FALSE;
+        }
+        retFbArray[index].bufY  = pvb->phys_addr;
+        retFbArray[index].bufCb = (PhysicalAddress)-1;
+        retFbArray[index].bufCr = (PhysicalAddress)-1;
+        retFbArray[index].updateFbInfo = TRUE;
+        retFbArray[index].size  = framebufSize;
+    }
+
+    if (tiledFbCount != 0) {
+        if ((ret=VPU_DecAllocateFrameBuffer(decHandle, fbAllocInfo, retFbArray)) != RETCODE_SUCCESS) {
+            VLOG(ERR, "%s:%d failed to VPU_DecAllocateFrameBuffer(), ret(%d)\n", 
+                __FUNCTION__, __LINE__, ret);
+            ReleaseVideoMemory(coreIndex, retFbAddrs, totalFbCount);
+            return FALSE;
+        }
+    }
+
+    if (config->enableWTL == TRUE || linearFbCount != 0) {
+        size_t  linearStride;
+        size_t  picWidth;
+        size_t  picHeight;
+        size_t  fbHeight;
+        Uint32   mapType = LINEAR_FRAME_MAP;
+        FrameBufferFormat outFormat = config->wtlFormat;
+        picWidth  = seqInfo.picWidth;
+        picHeight = seqInfo.picHeight;
+        fbHeight  = picHeight;
+        if (decHandle->codecMode == C7_VP9_DEC) {
+            fbHeight = VPU_ALIGN64(picHeight);
+        }
+        else if (decHandle->codecMode == C7_AVS2_DEC) {
+            fbHeight = VPU_ALIGN8(picHeight);
+        }
+        else if (productId == PRODUCT_ID_7Q && decHandle->codecMode != C7_HEVC_DEC)
+        {
+            fbHeight = seqInfo.interlace ? VPU_ALIGN32(picHeight) : VPU_ALIGN16(picHeight);
+        }
+        else if (productId == PRODUCT_ID_960 || productId == PRODUCT_ID_980)
+        {
+            fbHeight = VPU_ALIGN32(picHeight);
+        }
+        if (decHandle->codecMode == C7_VP9_DEC) {
+            linearStride = CalcStride(VPU_ALIGN64(picWidth), picHeight, outFormat, config->cbcrInterleave, (TiledMapType)mapType, TRUE);
+        }
+        else {
+            linearStride = CalcStride(picWidth, picHeight, outFormat, config->cbcrInterleave, (TiledMapType)mapType, FALSE);
+        }
+        framebufSize = VPU_GetFrameBufSize(coreIndex, linearStride, fbHeight, (TiledMapType)mapType, outFormat, config->cbcrInterleave, pDramCfg);
+
+        for (index=tiledFbCount; index<totalFbCount; index++) {
+            pvb = &retFbAddrs[index];
+            pvb->size = framebufSize;
+            if (vdi_allocate_dma_memory(coreIndex, pvb) < 0) {
+                VLOG(ERR, "%s:%d fail to allocate frame buffer\n", __FUNCTION__, __LINE__);
+                ReleaseVideoMemory(coreIndex, retFbAddrs, totalFbCount);
+                return FALSE;
+            }
+            retFbArray[index].bufY  = pvb->phys_addr;
+            retFbArray[index].bufCb = -1;
+            retFbArray[index].bufCr = -1;
+            retFbArray[index].updateFbInfo = TRUE;
+            retFbArray[index].size  = framebufSize;
+        }
+
+        fbAllocInfo.nv21    = config->nv21;
+        fbAllocInfo.format  = outFormat;
+        fbAllocInfo.num     = linearFbCount;
+        fbAllocInfo.mapType = (TiledMapType)mapType;
+        fbAllocInfo.stride  = linearStride;
+        fbAllocInfo.height  = fbHeight;
+        ret = VPU_DecAllocateFrameBuffer(decHandle, fbAllocInfo, &retFbArray[tiledFbCount]);
+        if (ret != RETCODE_SUCCESS) {
+            VLOG(ERR, "%s:%d failed to VPU_DecAllocateFrameBuffer() ret:%d\n",
+                __FUNCTION__, __LINE__, ret);
+            ReleaseVideoMemory(coreIndex, retFbAddrs, totalFbCount);
+            return FALSE;
+        }
+    }
+
+    return TRUE;
+}
+
+#if defined(_WIN32) || defined(__MSDOS__)
+#define DOS_FILESYSTEM
+#define IS_DIR_SEPARATOR(__c) ((__c == '/') || (__c == '\\'))
+#else
+/* UNIX style */
+#define IS_DIR_SEPARATOR(__c) (__c == '/')
+#endif
+
+char* GetDirname(
+    const char* path
+    )
+{
+    int length;
+    int i;
+    char* upper_dir;
+
+    if (path == NULL) return NULL;
+
+    length = strlen(path);
+    for (i=length-1; i>=0; i--) {
+        if (IS_DIR_SEPARATOR(path[i])) break;
+    }
+
+    if (i<0) {
+        upper_dir = strdup(".");
+    } else {
+        upper_dir = strdup(path);
+        upper_dir[i] = 0;
+    }
+
+    return upper_dir;
+}
+
+char* GetBasename(
+    const char* pathname
+    )
+{
+    const char* base = NULL;
+    const char* p    = pathname;
+
+    if (p == NULL) {
+        return NULL;
+    }
+
+#if defined(DOS_FILESYSTEM)
+    if (isalpha((int)p[0]) && p[1] == ':') {
+        p += 2;
+    }
+#endif
+
+    for (base=p; *p; p++) {
+        if (IS_DIR_SEPARATOR(*p)) {
+            base = p+1;
+        }
+    }
+
+    return (char*)base;
+}
+
+char* GetFileExtension(
+    const char* filename 
+    )
+{
+    Uint32      len;
+    Uint32      i;
+
+    len = strlen(filename);
+    for (i=len-1; i>=0; i--) {
+        if (filename[i] == '.') {
+            return (char*)&filename[i+1];
+        }
+    }
+
+    return NULL;
+}
+
+void byte_swap(unsigned char* data, int len)
+{
+    Uint8 temp;
+    Int32 i;
+
+    for (i=0; i<len; i+=2) {
+        temp      = data[i];
+        data[i]   = data[i+1];
+        data[i+1] = temp;
+    }
+}
+
+BOOL IsEndOfFile(FILE* fp)
+{
+    BOOL  result = FALSE;
+    Int32 index  = 0;
+    char  cTemp;
+
+    // Check current fp pos
+    if (osal_feof(fp) != 0) {
+        result = TRUE;
+    }
+
+    // Check next fp pos
+    // Ignore newline character
+    do {
+        cTemp = fgetc(fp);
+        index++;
+
+        if (osal_feof(fp) != 0) {
+            result = TRUE;
+            break;
+        }
+    } while (cTemp == '\n' || cTemp == '\r');
+
+    // Revert fp pos
+    index *= (-1);
+    osal_fseek(fp, index, SEEK_CUR);
+
+    return result;
+}
+
+BOOL CalcYuvSize(
+    Int32   format,
+    Int32   picWidth,
+    Int32   picHeight,
+    Int32   cbcrInterleave,
+    size_t  *lumaSize,
+    size_t  *chromaSize,
+    size_t  *frameSize,
+    Int32   *bitDepth,
+    Int32   *packedFormat,
+    Int32   *yuv3p4b)
+{
+    Int32   temp_picWidth;
+    Int32   chromaWidth;
+
+    if ( bitDepth != 0)
+        *bitDepth = 0;
+    if ( packedFormat != 0)
+        *packedFormat = 0;
+    if ( yuv3p4b != 0)
+        *yuv3p4b = 0;
+
+    switch (format)
+    {
+    case FORMAT_420:
+        if (lumaSize)   *lumaSize = picWidth * picHeight;
+        if (chromaSize) *chromaSize = picWidth * picHeight / 2;
+        if (frameSize)  *frameSize = picWidth * picHeight * 3 /2;
+        break;
+    case FORMAT_YUYV:
+    case FORMAT_YVYU:
+    case FORMAT_UYVY:
+    case FORMAT_VYUY:
+        if ( packedFormat != 0)
+            *packedFormat = 1;
+        if (lumaSize)   *lumaSize = picWidth * picHeight;
+        if (chromaSize) *chromaSize = picWidth * picHeight;
+        if (frameSize)  *frameSize = *lumaSize + *chromaSize;
+        break;
+    case FORMAT_224:
+        if (lumaSize)   *lumaSize = picWidth * picHeight;
+        if (chromaSize) *chromaSize = picWidth * picHeight;
+        if (frameSize)  *frameSize = picWidth * picHeight * 4 / 2;
+        break;
+    case FORMAT_422:
+        if (lumaSize)   *lumaSize = picWidth * picHeight;
+        if (chromaSize) *chromaSize = picWidth * picHeight;
+        if (frameSize)  *frameSize = picWidth * picHeight * 4 / 2;
+        break;
+    case FORMAT_444:
+        if (lumaSize)   *lumaSize  = picWidth * picHeight;
+        if (chromaSize) *chromaSize = picWidth * picHeight * 2;
+        if (frameSize)  *frameSize = picWidth * picHeight * 3;
+        break;
+    case FORMAT_400:
+        if (lumaSize)   *lumaSize  = picWidth * picHeight;
+        if (chromaSize) *chromaSize = 0;
+        if (frameSize)  *frameSize = picWidth * picHeight;
+        break;
+    case FORMAT_422_P10_16BIT_MSB:
+    case FORMAT_422_P10_16BIT_LSB:
+        if ( bitDepth != NULL) {
+            *bitDepth = 10;
+        }
+        if (lumaSize)   *lumaSize = picWidth * picHeight * 2;
+        if (chromaSize) *chromaSize = *lumaSize;
+        if (frameSize)  *frameSize = *lumaSize + *chromaSize;
+        break;
+    case FORMAT_420_P10_16BIT_MSB:
+    case FORMAT_420_P10_16BIT_LSB:
+        if ( bitDepth != 0)
+            *bitDepth = 10;
+        if (lumaSize)   *lumaSize = picWidth * picHeight * 2;
+        if (chromaSize) *chromaSize = picWidth * picHeight;
+        if (frameSize)  *frameSize = *lumaSize + *chromaSize;
+        break;
+    case FORMAT_YUYV_P10_16BIT_MSB:   // 4:2:2 10bit packed
+    case FORMAT_YUYV_P10_16BIT_LSB:
+    case FORMAT_YVYU_P10_16BIT_MSB:
+    case FORMAT_YVYU_P10_16BIT_LSB:
+    case FORMAT_UYVY_P10_16BIT_MSB:
+    case FORMAT_UYVY_P10_16BIT_LSB:
+    case FORMAT_VYUY_P10_16BIT_MSB:
+    case FORMAT_VYUY_P10_16BIT_LSB:
+        if ( bitDepth != 0)
+            *bitDepth = 10;
+        if ( packedFormat != 0)
+            *packedFormat = 1;
+        if (lumaSize)   *lumaSize = picWidth * picHeight * 2;
+        if (chromaSize) *chromaSize = picWidth * picHeight * 2;
+        if (frameSize)  *frameSize = *lumaSize + *chromaSize;
+        break;
+    case FORMAT_420_P10_32BIT_MSB:
+    case FORMAT_420_P10_32BIT_LSB:
+        if ( bitDepth != 0)
+            *bitDepth = 10;
+        if ( yuv3p4b != 0)
+            *yuv3p4b = 1;
+        temp_picWidth = VPU_ALIGN32(picWidth);
+        chromaWidth = ((VPU_ALIGN16(temp_picWidth/2*(1<<cbcrInterleave))+2)/3*4);
+        if ( cbcrInterleave == 1)
+        {
+            if (lumaSize)   *lumaSize = (temp_picWidth+2)/3*4 * picHeight;
+            if (chromaSize) *chromaSize = chromaWidth * picHeight/2;
+        } else {
+            if (lumaSize)   *lumaSize = (temp_picWidth+2)/3*4 * picHeight;
+            if (chromaSize) *chromaSize = chromaWidth * picHeight/2*2;
+        }
+        if (frameSize) *frameSize = *lumaSize + *chromaSize;
+        break;
+    case FORMAT_YUYV_P10_32BIT_MSB:
+    case FORMAT_YUYV_P10_32BIT_LSB:
+    case FORMAT_YVYU_P10_32BIT_MSB:
+    case FORMAT_YVYU_P10_32BIT_LSB:
+    case FORMAT_UYVY_P10_32BIT_MSB:
+    case FORMAT_UYVY_P10_32BIT_LSB:
+    case FORMAT_VYUY_P10_32BIT_MSB:
+    case FORMAT_VYUY_P10_32BIT_LSB:
+        if ( bitDepth != 0)
+            *bitDepth = 10;
+        if ( packedFormat != 0)
+            *packedFormat = 1;
+        if ( yuv3p4b != 0)
+            *yuv3p4b = 1;
+        if (frameSize)  *frameSize = ((picWidth*2)+2)/3*4 * picHeight;
+        if (lumaSize)   *lumaSize = *frameSize/2;
+        if (chromaSize) *chromaSize = *frameSize/2;
+        break;
+    default:
+        if (frameSize) *frameSize = picWidth * picHeight * 3 / 2;
+        VLOG(ERR, "%s:%d Not supported format(%d)\n", __FILE__, __LINE__, format);
+        return FALSE;
+    }
+    return TRUE;
+}
+
+int GetPackedFormat (
+    int srcBitDepth, 
+    int packedType,
+    int p10bits,
+    int msb)
+{
+    int format = FORMAT_YUYV;
+
+    // default pixel format = P10_16BIT_LSB (p10bits = 16, msb = 0)
+    if (srcBitDepth == 8) {
+
+        switch(packedType) {
+        case PACKED_YUYV:
+            format = FORMAT_YUYV;
+            break;
+        case PACKED_YVYU:
+            format = FORMAT_YVYU;
+            break;
+        case PACKED_UYVY:
+            format = FORMAT_UYVY;
+            break;
+        case PACKED_VYUY:
+            format = FORMAT_VYUY;
+            break;
+        default:
+            format = -1;
+        }
+    }
+    else if (srcBitDepth == 10) {
+        switch(packedType) {
+        case PACKED_YUYV:
+            if (p10bits == 16) {
+                format = (msb == 0) ? FORMAT_YUYV_P10_16BIT_LSB : FORMAT_YUYV_P10_16BIT_MSB;
+            }
+            else if (p10bits == 32) {
+                format = (msb == 0) ? FORMAT_YUYV_P10_32BIT_LSB : FORMAT_YUYV_P10_32BIT_MSB;
+            }
+            else {
+                format = -1;
+            }
+            break;
+        case PACKED_YVYU:
+            if (p10bits == 16) {
+                format = (msb == 0) ? FORMAT_YVYU_P10_16BIT_LSB : FORMAT_YVYU_P10_16BIT_MSB; 
+            }
+            else if (p10bits == 32) {
+                format = (msb == 0) ? FORMAT_YVYU_P10_32BIT_LSB : FORMAT_YVYU_P10_32BIT_MSB;
+            }
+            else {
+                format = -1;
+            }
+            break;
+        case PACKED_UYVY:
+            if (p10bits == 16) {
+                format = (msb == 0) ? FORMAT_UYVY_P10_16BIT_LSB : FORMAT_UYVY_P10_16BIT_MSB;
+            }
+            else if (p10bits == 32) {
+                format = (msb == 0) ? FORMAT_UYVY_P10_32BIT_LSB : FORMAT_UYVY_P10_32BIT_MSB;
+            }
+            else {
+                format = -1;
+            }
+            break;
+        case PACKED_VYUY:
+            if (p10bits == 16) {
+                format = (msb == 0) ? FORMAT_VYUY_P10_16BIT_LSB : FORMAT_VYUY_P10_16BIT_MSB;
+            }
+            else if (p10bits == 32) {
+                format = (msb == 0) ? FORMAT_VYUY_P10_32BIT_LSB : FORMAT_VYUY_P10_32BIT_MSB;
+            }
+            else {
+                format = -1;
+            }
+            break;
+        default:
+            format = -1;
+        }
+    }
+    else {
+        format = -1;
+    }
+
+    return format;
+}
+
+
+void GenRegionToMap(
+    VpuRect *region,        /**< The size of the ROI region for H.265 (start X/Y in CTU, end X/Y int CTU)  */
+    int *roiLevel,
+    int num,
+    Uint32 mapWidth,
+    Uint32 mapHeight,
+    Uint8 *roiCtuMap)
+{
+    Int32 roi_id, blk_addr;
+    Uint32 roi_map_size      = mapWidth * mapHeight;
+
+    //init roi map
+    for (blk_addr=0; blk_addr<(Int32)roi_map_size; blk_addr++)
+        roiCtuMap[blk_addr] = 0;
+
+    //set roi map. roi_entry[i] has higher priority than roi_entry[i+1]
+    for (roi_id=(Int32)num-1; roi_id>=0; roi_id--)
+    {
+        Uint32 x, y;
+        VpuRect *roi = region + roi_id;
+
+        for (y=roi->top; y<=roi->bottom; y++)
+        {
+            for (x=roi->left; x<=roi->right; x++)
+            {
+                roiCtuMap[y*mapWidth + x] = *(roiLevel + roi_id);
+            }
+        }
+    }
+}
+
+
+void GenRegionToQpMap(
+    VpuRect *region,        /**< The size of the ROI region for H.265 (start X/Y in CTU, end X/Y int CTU)  */
+    int *roiLevel,
+    int num,
+    int initQp,
+    Uint32 mapWidth,
+    Uint32 mapHeight,
+    Uint8 *roiCtuMap)
+{
+    Int32 roi_id, blk_addr;
+    Uint32 roi_map_size      = mapWidth * mapHeight;
+
+    //init roi map
+    for (blk_addr=0; blk_addr<(Int32)roi_map_size; blk_addr++)
+        roiCtuMap[blk_addr] = initQp;
+
+    //set roi map. roi_entry[i] has higher priority than roi_entry[i+1]
+    for (roi_id=(Int32)num-1; roi_id>=0; roi_id--)
+    {
+        Uint32 x, y;
+        VpuRect *roi = region + roi_id;
+
+        for (y=roi->top; y<=roi->bottom; y++)
+        {
+            for (x=roi->left; x<=roi->right; x++)
+            {
+                roiCtuMap[y*mapWidth + x] = *(roiLevel + roi_id);
+            }
+        }
+    }
+}
+
+
+
+Int32 writeVuiRbsp(int coreIdx, TestEncConfig *encConfig, EncOpenParam *encOP, vpu_buffer_t *vbVuiRbsp)
+{
+    if (encOP->encodeVuiRbsp == TRUE) {
+        vbVuiRbsp->size = VUI_HRD_RBSP_BUF_SIZE;
+
+        if (vdi_allocate_dma_memory(coreIdx, vbVuiRbsp) < 0) {
+            VLOG(ERR, "fail to allocate VUI rbsp buffer\n" );
+            return FALSE;
+        }
+        encOP->vuiRbspDataAddr = vbVuiRbsp->phys_addr;
+
+        if (encConfig->vui_rbsp_file_name) {
+            Uint8   *pVuiRbspBuf;
+            Int32   rbspSizeInByte = (encOP->vuiRbspDataSize+7)>>3;
+            ChangePathStyle(encConfig->vui_rbsp_file_name);
+            if ((encConfig->vui_rbsp_fp = osal_fopen(encConfig->vui_rbsp_file_name, "r")) == NULL) {
+                VLOG(ERR, "fail to open Prefix SEI NAL Data file, %s\n", encConfig->vui_rbsp_file_name);
+                return FALSE;
+            }
+
+            if (rbspSizeInByte > (Uint32)VUI_HRD_RBSP_BUF_SIZE)
+                VLOG(ERR, "VUI Rbsp size is bigger than buffer size\n");
+
+            pVuiRbspBuf = (Uint8*)osal_malloc(VUI_HRD_RBSP_BUF_SIZE);
+            osal_memset(pVuiRbspBuf, 0, VUI_HRD_RBSP_BUF_SIZE);
+            osal_fread(pVuiRbspBuf, 1, rbspSizeInByte, encConfig->vui_rbsp_fp);
+            vdi_write_memory(coreIdx, encOP->vuiRbspDataAddr, pVuiRbspBuf,  rbspSizeInByte, encOP->streamEndian);
+            osal_free(pVuiRbspBuf);
+        }
+    }
+    return TRUE;
+}
+
+Int32 writeHrdRbsp(int coreIdx, TestEncConfig *encConfig, EncOpenParam *encOP, vpu_buffer_t *vbHrdRbsp)
+{
+    if (encOP->encodeHrdRbspInVPS || encOP->encodeHrdRbspInVUI)
+    {
+        vbHrdRbsp->size    = VUI_HRD_RBSP_BUF_SIZE;
+        if (vdi_allocate_dma_memory(coreIdx, vbHrdRbsp) < 0) {
+            VLOG(ERR, "fail to allocate HRD rbsp buffer\n" );
+            return FALSE;
+        }
+
+        encOP->hrdRbspDataAddr = vbHrdRbsp->phys_addr;
+
+        if (encConfig->hrd_rbsp_file_name) {
+            Uint8   *pHrdRbspBuf;
+            Int32   rbspSizeInByte = (encOP->hrdRbspDataSize+7)>>3;
+            ChangePathStyle(encConfig->hrd_rbsp_file_name);
+            if ((encConfig->hrd_rbsp_fp = osal_fopen(encConfig->hrd_rbsp_file_name, "r")) == NULL) {
+                VLOG(ERR, "fail to open Prefix SEI NAL Data file, %s\n", encConfig->hrd_rbsp_file_name);
+                return FALSE;
+            }
+
+            if (rbspSizeInByte > (Uint32)VUI_HRD_RBSP_BUF_SIZE)
+                VLOG(ERR, "HRD Rbsp size is bigger than buffer size\n");
+
+            pHrdRbspBuf = (Uint8*)osal_malloc(VUI_HRD_RBSP_BUF_SIZE);
+            osal_memset(pHrdRbspBuf, 0, VUI_HRD_RBSP_BUF_SIZE);
+            osal_fread(pHrdRbspBuf, 1, rbspSizeInByte, encConfig->hrd_rbsp_fp);
+            vdi_write_memory(coreIdx, encOP->hrdRbspDataAddr, pHrdRbspBuf,  rbspSizeInByte, encOP->streamEndian);
+            osal_free(pHrdRbspBuf);
+        }
+    }
+    return TRUE;
+}
+
+#ifdef TEST_ENCODE_CUSTOM_HEADER
+Int32 writeCustomHeader(int coreIdx, EncOpenParam *encOP, vpu_buffer_t *vbCustomHeader, hrd_t *hrd)
+{
+    Int32 rbspBitSize;
+    Uint8 *pRbspBuf;
+    Int32 rbspByteSize;
+    vui_t vui;
+
+    encOP->encodeVuiRbsp = 1;
+
+    vbCustomHeader->size = VUI_HRD_RBSP_BUF_SIZE;
+
+    if (vdi_allocate_dma_memory(coreIdx, vbCustomHeader) < 0) {
+        VLOG(ERR, "fail to allocate VUI rbsp buffer\n" );
+        return FALSE;
+    }
+
+    encOP->vuiRbspDataAddr = vbCustomHeader->phys_addr;
+
+    pRbspBuf = (Uint8 *)osal_malloc(VUI_HRD_RBSP_BUF_SIZE);
+    if (pRbspBuf) {
+        osal_memset(pRbspBuf, 0, VUI_HRD_RBSP_BUF_SIZE);
+        vui.vui_parameters_presesent_flag = 1;
+        vui.vui_timing_info_present_flag = 1;
+        vui.vui_num_units_in_tick = 1000;
+        vui.vui_time_scale = 60*1000.0;			
+        vui.vui_hrd_parameters_present_flag = 1;	
+        vui.def_disp_win_left_offset = 1;
+        vui.def_disp_win_right_offset = 1;
+        vui.def_disp_win_top_offset = 1;
+        vui.def_disp_win_bottom_offset = 1;
+
+        // HRD param : refer xInitHrdParameters in HM
+        {
+            int useSubCpbParams =0;
+            int bitRate = encOP->bitRate;
+            int isRandomAccess;
+            int cpbSize = bitRate; // Adjusting value to be equal to TargetBitrate
+            int bitRateScale;
+            int cpbSizeScale;
+            int i, j, numSubLayersM1;
+            Uint32 bitrateValue, cpbSizeValue;
+            Uint32 duCpbSizeValue;
+            Uint32 duBitRateValue = 0;
+
+            if (bitRate >0) {
+                hrd->nal_hrd_parameters_present_flag = 1;
+                hrd->vcl_hrd_parameters_present_flag = 1;
+            }
+            else {
+                hrd->nal_hrd_parameters_present_flag = 0;
+                hrd->vcl_hrd_parameters_present_flag = 0;
+            }
+
+            if (encOP->EncStdParam.hevcParam.independSliceMode != 0)
+                useSubCpbParams = 1;
+
+            if (encOP->EncStdParam.hevcParam.intraPeriod > 0)
+                isRandomAccess = 1;
+            else
+                isRandomAccess = 0;
+
+            hrd->sub_pic_hrd_params_present_flag = useSubCpbParams;
+            if (useSubCpbParams) {
+                hrd->tick_divisor_minus2 = 100-2;
+                hrd->du_cpb_removal_delay_increment_length_minus1 = 7;  // 8-bit precision ( plus 1 for last DU in AU )
+                hrd->sub_pic_cpb_params_in_pic_timing_sei_flag = 1;
+                hrd->dpb_output_delay_du_length_minus1 = 5+7; // With sub-clock tick factor of 100, at least 7 bits to have the same value as AU dpb delay
+            }
+            else
+                hrd->sub_pic_cpb_params_in_pic_timing_sei_flag = 0;
+
+            //  calculate scale value of bitrate and initial delay
+            bitRateScale = calcScale(bitRate);
+            if ( bitRateScale <= 6 )
+                hrd->bit_rate_scale = 0;
+            else
+                hrd->bit_rate_scale = bitRateScale -6;
+
+            cpbSizeScale = calcScale(cpbSize);
+            if ( cpbSizeScale <= 4 )
+                hrd->cpb_size_scale = 0;
+            else
+                hrd->cpb_size_scale = cpbSizeScale -4;
+
+            hrd->cpb_size_du_scale = 6; // in units of 2^( 4 + 6 ) = 1,024 bit
+            hrd->initial_cpb_removal_delay_length_minus1 = 15;  // assuming 0.5 sec, log2( 90,000 * 0.5 ) = 16-bit
+
+            if (isRandomAccess > 0) {
+                hrd->au_cpb_removal_delay_length_minus1 = 5;
+                hrd->dpb_output_delay_length_minus1 = 5;
+            }
+            else {
+                hrd->au_cpb_removal_delay_length_minus1 = 9;
+                hrd->dpb_output_delay_length_minus1 = 9;
+            }
+
+            numSubLayersM1 = 0;
+            if (encOP->EncStdParam.hevcParam.gopPresetIdx == 0) { // custom GOP
+                for(i=0; i<encOP->EncStdParam.hevcParam.gopParam.customGopSize; i++) {
+                    if (numSubLayersM1 < encOP->EncStdParam.hevcParam.gopParam.picParam[i].temporalId)
+                        numSubLayersM1 = encOP->EncStdParam.hevcParam.gopParam.picParam[i].temporalId;
+                }
+            }
+            hrd->vps_max_sub_layers_minus1 = numSubLayersM1;
+            // sub_layer_hrd_parameters
+            // BitRate[ i ] = ( bit_rate_value_minus1[ i ] + 1 ) * 2^( 6 + bit_rate_scale )
+            bitrateValue = bitRate / (1 << (6 + hrd->bit_rate_scale) );      // bitRate is in bits, so it needs to be scaled down
+            // CpbSize[ i ] = ( cpb_size_value_minus1[ i ] + 1 ) * 2^( 4 + cpb_size_scale )
+            cpbSizeValue = cpbSize / (1 << (4 + hrd->cpb_size_scale) );      // using bitRate results in 1 second CPB size
+
+            // DU CPB size could be smaller (i.e. bitrateValue / number of DUs), but we don't know 
+            // in how many DUs the slice segment settings will result 
+            duCpbSizeValue = bitrateValue;
+            duBitRateValue = cpbSizeValue;
+
+            for(i=0; i<hrd->vps_max_sub_layers_minus1; i++) {
+                hrd->fixed_pic_rate_general_flag[i] = 1;                                                                                                                                    
+                hrd->fixed_pic_rate_within_cvs_flag[i] = 1; // fixed_pic_rate_general_flag[ i ] is equal to 1, the value of fixed_pic_rate_within_cvs_flag[ i ] is inferred to be equal to 1
+                hrd->elemental_duration_in_tc_minus1[i] = 0; 
+
+                hrd->low_delay_hrd_flag[i] = 0;
+                hrd->cpb_cnt_minus1[i] = 0;
+
+                if (hrd->nal_hrd_parameters_present_flag) {
+                    for (j=0; hrd->cpb_cnt_minus1[i]; j++) {
+                        hrd->bit_rate_value_minus1[j][i] = bitrateValue-1;
+                        hrd->cpb_size_value_minus1[j][i] = cpbSize -1;
+                        hrd->cpb_size_du_value_minus1[j][i] = duCpbSizeValue -1;
+                        hrd->bit_rate_du_value_minus1[j][i] = duBitRateValue -1;
+                        hrd->cbr_flag[j][i] = 0;
+                    }
+                }
+                if (hrd->vcl_hrd_parameters_present_flag) {
+                    for (j=0; hrd->cpb_cnt_minus1[i]; j++) {
+                        hrd->bit_rate_value_minus1[j][i] = bitrateValue-1;
+                        hrd->cpb_size_value_minus1[j][i] = cpbSize -1;
+                        hrd->cpb_size_du_value_minus1[j][i] = duCpbSizeValue -1;
+                        hrd->bit_rate_du_value_minus1[j][i] = duBitRateValue -1;
+                        hrd->cbr_flag[j][i] = 0;
+                    }
+                }
+            }
+        }
+
+        EncodeVUI(&hrd, &vui, pRbspBuf, VUI_HRD_RBSP_BUF_SIZE, &rbspByteSize, &rbspBitSize, 60);
+        encOP->vuiRbspDataSize = rbspBitSize;
+        vdi_write_memory(coreIdx, encOP->vuiRbspDataAddr, pRbspBuf,  rbspByteSize, encOP->streamEndian);
+        osal_free(pRbspBuf);
+    }
+    return TRUE;
+}
+
+Int32 allocateSeiNalDataBuf(int coreIdx, vpu_buffer_t *vbSeiNal, int srcFbNum)
+{
+    Int32 i;
+    for (i = 0; i < srcFbNum; i++) {         // the number of roi buffer should be the same as source buffer num.
+        vbSeiNal[i].size = SEI_NAL_DATA_BUF_SIZE;
+        if (vdi_allocate_dma_memory(coreIdx, &vbSeiNal[i]) < 0) {
+            VLOG(ERR, "fail to allocate SeiNalData buffer\n");
+            return FALSE;
+        }
+    }
+    return TRUE;
+}
+
+Int32 writeSeiNalData(EncHandle handle, int streamEndian, PhysicalAddress prefixSeiNalAddr, hrd_t *hrd)
+{
+    sei_buffering_period_t buffering_period_sei;
+    Uint8 *pSeiBuf;
+    sei_active_parameter_t active_parameter_sei;
+    Int32 seiByteSize = 0;
+    HevcSEIDataEnc seiDataEnc;
+    sei_pic_timing_t pic_timing_sei;
+
+    pSeiBuf = (Uint8 *)osal_malloc(SEI_NAL_DATA_BUF_SIZE);
+    if (pSeiBuf) 
+    {
+        osal_memset(pSeiBuf, 0x00, SEI_NAL_DATA_BUF_SIZE);
+        osal_memset(&seiDataEnc, 0x00, sizeof(seiDataEnc));
+
+        seiDataEnc.prefixSeiNalEnable = 1;
+        seiDataEnc.prefixSeiDataEncOrder = 0;
+        seiDataEnc.prefixSeiNalAddr = prefixSeiNalAddr;
+
+        active_parameter_sei.active_video_parameter_set_id = 0; // vps_video_parameter_set_id of the VPS. wave420 is 0
+        active_parameter_sei.self_contained_cvs_flag = 0;
+        active_parameter_sei.no_parameter_set_update_flag = 0;
+        active_parameter_sei.num_sps_ids_minus1 = 0;
+        active_parameter_sei.active_seq_parameter_set_id[0] = 0;// sps_seq_parameter_set_id of the SPS. wave420 is 0
+
+        // put sei_pic_timing
+        pic_timing_sei.pic_struct = 0;
+        pic_timing_sei.source_scan_type = 1;
+        pic_timing_sei.duplicate_flag = 0;
+
+        buffering_period_sei.nal_initial_cpb_removal_delay[0] = 2229;
+        buffering_period_sei.nal_initial_cpb_removal_offset[0] = 0;
+
+        seiByteSize = EncodePrefixSEI(&active_parameter_sei, &pic_timing_sei, &buffering_period_sei, &hrd, pSeiBuf, SEI_NAL_DATA_BUF_SIZE);
+        seiDataEnc.prefixSeiDataSize = seiByteSize;
+        vdi_write_memory(handle->coreIdx, seiDataEnc.prefixSeiNalAddr, pSeiBuf, seiDataEnc.prefixSeiDataSize, streamEndian);
+
+        free(pSeiBuf);
+    }
+    VPU_EncGiveCommand(handle, ENC_SET_SEI_NAL_DATA, &seiDataEnc);
+    return TRUE;
+}
+#endif
+
+
+int setRoiMap(int coreIdx, TestEncConfig *encConfig, EncOpenParam encOP, PhysicalAddress addrRoiMap,
+    Uint8 *roiMapBuf, int srcFrameWidth, int srcFrameHeight, EncParam *encParam, int maxCtuNum)
+{
+    int i;
+    if (encConfig->roi_enable && encParam->srcEndFlag != 1) {
+        int roiNum=0;
+        // sample code to convert ROI coordinate to ROI map.
+        osal_memset(&encConfig->region[0], 0, sizeof(VpuRect)*MAX_ROI_NUMBER);
+        osal_memset(&encConfig->roiLevel[0], 0, sizeof(int)*MAX_ROI_NUMBER);
+        if (encConfig->roi_file_name) {
+            char lineStr[256] = {0, };
+            int  val;
+            fgets(lineStr, 256, encConfig->roi_file);
+            sscanf(lineStr, "%x\n", &val);
+            if (val != 0xFFFF)
+                VLOG(ERR, "can't find the picture delimiter \n");
+
+            fgets(lineStr, 256, encConfig->roi_file);
+            sscanf(lineStr, "%d\n", &val);  // picture index
+
+            fgets(lineStr, 256, encConfig->roi_file);   
+            sscanf(lineStr, "%d\n", &roiNum);   // number of roi regions
+
+            for (i = 0; i < roiNum; i++) {
+                fgets(lineStr, 256, encConfig->roi_file);
+                if (parseRoiCtuModeParam(lineStr, &encConfig->region[i], &encConfig->roiLevel[i], srcFrameWidth, srcFrameHeight) == 0 ) {
+                    VLOG(ERR, "CFG file error : %s value is not available. \n", encConfig->roi_file_name);
+                }
+            }
+        }
+        encParam->ctuOptParam.addrRoiCtuMap = addrRoiMap;
+        encParam->ctuOptParam.mapEndian     = VDI_LITTLE_ENDIAN;
+        encParam->ctuOptParam.mapStride     = ((encOP.picWidth+63)&~63)>>6;
+        encParam->ctuOptParam.roiEnable     = (roiNum != 0) ? encConfig->roi_enable : 0;
+        encParam->ctuOptParam.roiDeltaQp    = encConfig->roi_delta_qp;
+
+        if (encParam->ctuOptParam.roiEnable) {
+            GenRegionToMap(&encConfig->region[0], &encConfig->roiLevel[0], roiNum, encParam->ctuOptParam.mapStride , ((encOP.picHeight+63)&~63)>>6, &roiMapBuf[0]);   
+            vdi_write_memory(coreIdx, encParam->ctuOptParam.addrRoiCtuMap, roiMapBuf, maxCtuNum, encParam->ctuOptParam.mapEndian);
+        }
+    }
+    return TRUE;
+}
+
+int checkParamRestriction(Uint32 productId, TestEncConfig *encConfig)
+{
+    if ( (encConfig->compare_type & (1<<MODE_SAVE_ENCODED)) && encConfig->bitstreamFileName[0] == 0) {
+        encConfig->compare_type &= ~(1<<MODE_SAVE_ENCODED);
+        VLOG(ERR,"You want to Save bitstream data. Set the path\n");
+    }
+
+    if ( (encConfig->compare_type & (1<<MODE_COMP_ENCODED)) && encConfig->ref_stream_path[0] == 0) {
+        encConfig->compare_type &= ~(1<<MODE_COMP_ENCODED);
+        VLOG(ERR,"You want to Compare bitstream data. Set the path\n");
+    }
+
+
+    /* CHECK PARAMETERS */
+    if (productId == PRODUCT_ID_420L) {
+        if (encConfig->rotAngle != 0) {
+            VLOG(ERR, "WAVE420L Not support rotation option\n");
+            return FALSE;
+        }
+        if (encConfig->mirDir != 0) {
+            VLOG(ERR, "WAVE420L Not support mirror option\n");
+            return FALSE;
+        }
+        if (encConfig->srcFormat3p4b == TRUE) {
+            VLOG(ERR, "WAVE420L Not support 3 pixel 4byte format option\n");
+            return FALSE;
+        }
+
+        if (encConfig->ringBufferEnable == TRUE) {
+            encConfig->ringBufferEnable = FALSE;
+            VLOG(ERR, "WAVE420L doesn't support ring-buffer.\n");
+        }
+    }
+    return TRUE;
+}
+
+
+int openRoiMapFile(TestEncConfig *encConfig) 
+{
+    if (encConfig->roi_enable) {
+        if (encConfig->roi_file_name) {
+            ChangePathStyle(encConfig->roi_file_name);
+            if ((encConfig->roi_file = osal_fopen(encConfig->roi_file_name, "r")) == NULL) {
+                VLOG(ERR, "fail to open ROI file, %s\n", encConfig->roi_file_name);
+                return FALSE;
+            }
+        }
+    }
+    return TRUE;
+}
+
+int allocateRoiMapBuf(int coreIdx, TestEncConfig encConfig, vpu_buffer_t *vbRoi, int srcFbNum, int ctuNum)
+{
+    int i;
+    if (encConfig.roi_enable) {
+        //number of roi buffer should be the same as source buffer num.
+        for (i = 0; i < srcFbNum ; i++) {
+            vbRoi[i].size = ctuNum;
+            if (vdi_allocate_dma_memory(coreIdx, &vbRoi[i]) < 0) {
+                VLOG(ERR, "fail to allocate ROI buffer\n" );
+                return FALSE;
+            }
+        }
+    }
+    return TRUE;
+}
+
+
+int setCtuQpMap(int coreIdx, TestEncConfig *encConfig, EncOpenParam encOP, PhysicalAddress addrCtuQpMap,
+    Uint8 *ctuQpMapBuf, int srcFrameWidth, int srcFrameHeight, EncParam *encParam, int maxCtuNum)
+{
+    int i;
+    if (encConfig->ctu_qp_enable && encParam->srcEndFlag != 1) {
+        int ctuQpNum=0;
+        // sample code to convert CTU coordinate to CTU MODE map.
+        osal_memset(&encConfig->region[0], 0, sizeof(VpuRect)*MAX_ROI_NUMBER);
+        osal_memset(&encConfig->ctuQp[0], 0, sizeof(int)*MAX_ROI_NUMBER);
+        if (encConfig->ctuqp_file_name) {
+            char lineStr[256] = {0, };
+            int  val;
+            fgets(lineStr, 256, encConfig->ctuqp_file);
+            sscanf(lineStr, "%x\n", &val);
+            if (val != 0xFFFF)
+                VLOG(ERR, "can't find the picture delimiter \n");
+
+            fgets(lineStr, 256, encConfig->ctuqp_file);
+            sscanf(lineStr, "%d\n", &val);  // picture index
+
+            fgets(lineStr, 256, encConfig->ctuqp_file);   
+            sscanf(lineStr, "%d\n", &ctuQpNum);   // number of roi regions
+
+            for (i = 0; i < ctuQpNum; i++) {
+                fgets(lineStr, 256, encConfig->ctuqp_file);
+                if (parseRoiCtuModeParam(lineStr, &encConfig->region[i], &encConfig->ctuQp[i], srcFrameWidth, srcFrameHeight) == 0 ) {
+                    VLOG(ERR, "CFG file error : %s value is not available. \n", encConfig->ctuqp_file_name);
+                }
+            }
+        }
+        encParam->ctuOptParam.addrCtuQpMap  = addrCtuQpMap;
+        encParam->ctuOptParam.mapEndian     = VDI_LITTLE_ENDIAN;
+        encParam->ctuOptParam.mapStride     = ((encOP.picWidth+63)&~63)>>6;
+        encParam->ctuOptParam.ctuQpEnable   = encConfig->ctu_qp_enable;
+
+        if (encParam->ctuOptParam.ctuQpEnable) {
+            GenRegionToQpMap(&encConfig->region[0], &encConfig->ctuQp[0], ctuQpNum, encOP.EncStdParam.hevcParam.intraQP, encParam->ctuOptParam.mapStride , ((encOP.picHeight+63)&~63)>>6, &ctuQpMapBuf[0]);   
+            vdi_write_memory(coreIdx, encParam->ctuOptParam.addrCtuQpMap, ctuQpMapBuf, maxCtuNum, encParam->ctuOptParam.mapEndian);
+        }
+    }
+    return TRUE;
+}
+
+int openCtuQpMapFile(TestEncConfig *encConfig) 
+{
+    if (encConfig->ctu_qp_enable) {
+        if (encConfig->ctuqp_file_name[0]) {
+            ChangePathStyle(encConfig->ctuqp_file_name);
+            if ((encConfig->ctuqp_file = osal_fopen(encConfig->ctuqp_file_name, "r")) == NULL) {
+                VLOG(ERR, "fail to open CTU QP file, %s\n", encConfig->ctuqp_file_name);
+                return FALSE;
+            }
+        }
+    }
+    return TRUE;
+}
+
+int allocateCtuQpMapBuf(int coreIdx, TestEncConfig encConfig, vpu_buffer_t *vbCtuQp, int srcFbNum, int ctuNum) {
+    int i;
+    if (encConfig.ctu_qp_enable) {
+        // the number of CTU mode buffer should be the same as source buffer num.
+        for (i = 0; i < srcFbNum; i++) {
+            vbCtuQp[i].size = ctuNum;
+            if (vdi_allocate_dma_memory(coreIdx, &vbCtuQp[i]) < 0) {
+                VLOG(ERR, "fail to allocate CTU QP buffer\n" );
+                return FALSE;
+            }
+        }
+    }
+    return TRUE;
+}
+
+// Define tokens for parsing scaling list file
+const char* MatrixType[SCALING_LIST_SIZE_NUM][SL_NUM_MATRIX] =
+{
+    {"INTRA4X4_LUMA", "INTRA4X4_CHROMAU", "INTRA4X4_CHROMAV", "INTER4X4_LUMA", "INTER4X4_CHROMAU", "INTER4X4_CHROMAV"},  
+    {"INTRA8X8_LUMA", "INTRA8X8_CHROMAU", "INTRA8X8_CHROMAV", "INTER8X8_LUMA", "INTER8X8_CHROMAU", "INTER8X8_CHROMAV"},  
+    {"INTRA16X16_LUMA", "INTRA16X16_CHROMAU", "INTRA16X16_CHROMAV", "INTER16X16_LUMA", "INTER16X16_CHROMAU", "INTER16X16_CHROMAV"},    
+    {"INTRA32X32_LUMA", "INTRA32X32_CHROMAU_FROM16x16_CHROMAU", "INTRA32X32_CHROMAV_FROM16x16_CHROMAV","INTER32X32_LUMA", "INTER32X32_CHROMAU_FROM16x16_CHROMAU", "INTER32X32_CHROMAV_FROM16x16_CHROMAV"}
+};
+
+const char* MatrixType_DC[SCALING_LIST_SIZE_NUM - 2][SL_NUM_MATRIX] =
+{
+    {"INTRA16X16_LUMA_DC", "INTRA16X16_CHROMAU_DC", "INTRA16X16_CHROMAV_DC", "INTER16X16_LUMA_DC", "INTER16X16_CHROMAU_DC", "INTER16X16_CHROMAV_DC"},
+    {"INTRA32X32_LUMA_DC", "INTRA32X32_CHROMAU_DC_FROM16x16_CHROMAU", "INTRA32X32_CHROMAV_DC_FROM16x16_CHROMAV", "INTER32X32_LUMA_DC","INTER32X32_CHROMAU_DC_FROM16x16_CHROMAU","INTER32X32_CHROMAV_DC_FROM16x16_CHROMAV"},
+};
+
+static Uint8* get_sl_addr(UserScalingList* sl, Uint32 size_id, Uint32 mat_id)
+{
+    Uint8* addr = NULL;
+
+    switch(size_id)
+    {
+    case SCALING_LIST_4x4:
+        addr = sl->s4[mat_id];
+        break;
+    case SCALING_LIST_8x8:
+        addr = sl->s8[mat_id];
+        break;
+    case SCALING_LIST_16x16:
+        addr = sl->s16[mat_id];
+        break;
+    case SCALING_LIST_32x32:
+        addr = sl->s32[mat_id];
+        break;
+    }
+    return addr;
+}
+
+int parse_user_scaling_list(UserScalingList* sl, FILE* fp_sl)
+{
+#define LINE_SIZE (1024)
+    const Uint32 scaling_list_size[SCALING_LIST_SIZE_NUM] = {16, 64, 64, 64};
+    char line[LINE_SIZE];
+    Uint32 i;
+    Uint32 size_id, mat_id, data, num_coef = 0;
+    Uint8* src = NULL;
+    Uint8* ref = NULL;
+    char* ret;
+    const char* type_str;
+
+    for(size_id = 0; size_id < SCALING_LIST_SIZE_NUM; size_id++) // for 4, 8, 16, 32
+    {
+        num_coef = scaling_list_size[size_id];
+
+        for(mat_id = 0; mat_id < SL_NUM_MATRIX; mat_id++) // for intra_y, intra_cb, intra_cr, inter_y, inter_cb, inter_cr
+        {
+            src = get_sl_addr(sl, size_id, mat_id);
+
+            if(size_id == SCALING_LIST_32x32 && (mat_id % 3)) // derive scaling list of chroma32x32 from that of chrom16x16
+            {
+                ref = get_sl_addr(sl, size_id - 1, mat_id);
+
+                for(i = 0; i < num_coef; i++)
+                    src[i] = ref[i];
+            }
+            else
+            {
+                fseek(fp_sl,0,0);
+                type_str = MatrixType[size_id][mat_id];
+
+                do 
+                {
+                    ret = fgets(line, LINE_SIZE, fp_sl);
+                    if((ret == NULL) || (strstr(line, type_str) == NULL && feof(fp_sl)))
+                    {
+                        printf("Error: can't read a scaling list matrix(%s)\n", type_str);
+                        return 0;
+                    }
+                } while (strstr(line, type_str) == NULL);
+
+                // get all coeff
+                for(i = 0; i < num_coef; i++)
+                {
+                    if(fscanf(fp_sl, "%d,", &data) != 1)
+                    {
+                        printf("Error: can't read a scaling list matrix(%s)\n", type_str);
+                        return 0;
+                    }
+                    src[i] = data;
+                }
+
+                // get DC coeff for 16, 32
+                if(size_id > SCALING_LIST_8x8)
+                {
+                    fseek(fp_sl,0,0);
+                    type_str = MatrixType_DC[size_id - 2][mat_id];
+
+                    do 
+                    {
+                        ret = fgets(line, LINE_SIZE, fp_sl);
+                        if((ret == NULL) || (strstr(line, type_str) == NULL && feof(fp_sl)))
+                        {
+                            printf("Error: can't read a scaling list matrix(%s)\n", type_str);
+                            return 0;
+                        }
+                    } while (strstr(line, type_str) == NULL);
+
+                    if(fscanf(fp_sl, "%d,", &data) != 1)
+                    {
+                        printf("Error: can't read a scaling list matrix(%s)\n", type_str);
+                        return 0;
+                    }
+
+                    // overwrite DC value
+                    src[0] = data;
+                }
+            }
+        } // for matrix id
+    } // for size id
+    return 1;
+}
+
+int parse_custom_lambda(Uint32 buf[NUM_CUSTOM_LAMBDA], FILE* fp)
+{
+    int i, j = 0;
+    char lineStr[256] = {0, };
+    for(i = 0; i < 52; i++)
+    {
+        if( NULL == fgets(lineStr, 256, fp) )
+        {
+            printf("Error: can't read custom_lambda\n");
+            return 0;
+        }
+        else
+        {
+            sscanf(lineStr, "%d\n", &buf[j++]);
+        }
+    }
+    for(i = 0; i < 52; i++)
+    {
+        if( NULL == fgets(lineStr, 256, fp) )
+        {
+            printf("Error: can't read custom_lambda\n");
+            return 0;
+        }
+        else
+            sscanf(lineStr, "%d\n", &buf[j++]);
+    }
+
+    return 1;
+}
+
+
+#ifdef PLATFORM_LINUX
+struct option* ConvertOptions(
+    struct OptionExt*   cnmOpt,
+    Uint32              nItems
+    )
+{
+    struct option*  opt;
+    Uint32          i;
+
+    opt = (struct option*)osal_malloc(sizeof(struct option) * nItems);
+    if (opt == NULL) {
+        return NULL;
+    }
+
+    for (i=0; i<nItems; i++) {
+        osal_memcpy((void*)&opt[i], (void*)&cnmOpt[i], sizeof(struct option));
+    }
+
+    return opt;
+}
+
+int mkdir_recursive(
+    char *path, 
+    mode_t omode
+    )
+{
+    struct stat sb;
+    mode_t numask, oumask;
+    int first, last, retval;
+    char *p;
+
+    p = path;
+    oumask = 0;
+    retval = 0;
+    if (p[0] == '/')        /* Skip leading '/'. */
+        ++p;
+    for (first = 1, last = 0; !last ; ++p) {
+        if (p[0] == '\0')
+            last = 1;
+        else if (p[0] != '/')
+            continue;
+        *p = '\0';
+        if (p[1] == '\0')
+            last = 1;
+        if (first) {
+            /*
+            * POSIX 1003.2:
+            * For each dir operand that does not name an existing
+            * directory, effects equivalent to those cased by the
+            * following command shall occcur:
+            *
+            * mkdir -p -m $(umask -S),u+wx $(dirname dir) &&
+            *    mkdir [-m mode] dir
+            *
+            * We change the user's umask and then restore it,
+            * instead of doing chmod's.
+            */
+            oumask = umask(0);
+            numask = oumask & ~(S_IWUSR | S_IXUSR);
+            (void)umask(numask);
+            first = 0;
+        }
+        if (last)
+            (void)umask(oumask);
+        if (mkdir(path, last ? omode : S_IRWXU | S_IRWXG | S_IRWXO) < 0) {
+            if (errno == EEXIST || errno == EISDIR) {
+                if (stat(path, &sb) < 0) {
+                    VLOG(INFO, "%s", path);
+                    retval = 1;
+                    break;
+                } else if (!S_ISDIR(sb.st_mode)) {
+                    if (last)
+                        errno = EEXIST;
+                    else
+                        errno = ENOTDIR;
+                    VLOG(INFO, "%s", path);
+                    retval = 1;
+                    break;
+                }
+            } else {
+                VLOG(INFO, "%s", path);
+                retval = 1;
+                break;
+            }
+        } else if (1)
+        {
+            VLOG(INFO, "%s", path);
+            chmod(path, omode);
+        }
+        if (!last)
+            *p = '/';
+    }
+    if (!first && !last)
+        (void)umask(oumask);
+    return (retval);
+}
+#endif
+
+BOOL TestMachineSetup(
+    TestMachine*    machine 
+    )
+{
+    BOOL success = TRUE;
+
+    osal_init_keyboard();
+
+    InitializeDebugEnv(machine->testEnvOptions);
+
+    return success;
+}
+
+void TestMachineCleanUp(
+    TestMachine*    machine
+    )
+{
+    Uint32      i;
+    Listener*   o;
+
+    for (i=0; i<machine->numObservers; i++) {
+        o = &machine->observers[i];
+        o->destruct(o);
+    }
+    ReleaseDebugEnv();
+    osal_close_keyboard();
+}
+
+void TestMachineAddListener(
+    TestMachine* machine,
+    Listener     observer,
+    void*        handle
+    )
+{
+    Uint32 i = machine->numObservers;
+
+    if (i == MAX_OBSERVERS) {
+        return;
+    }
+
+    observer.construct(&observer, handle);
+    osal_memcpy(&machine->observers[i], (void*)&observer, sizeof(Listener));
+    machine->numObservers++;
+}
+
+BOOL TestMachineSetData(
+    TestMachine* machine,
+    void*        data
+    )
+{
+    Listener*   o = NULL;
+    Uint32      i;
+    BOOL        success = TRUE;
+
+    for (i=0; i<machine->numObservers; i++) {
+        o = &machine->observers[i];
+        if (o->update(o, data) == FALSE) {
+            success = FALSE;
+        }
+    }
+
+    return success;
+}
+
+int file_exist(
+    char* path
+    )
+{
+#ifdef _MSC_VER
+    DWORD   attributes;
+    char    temp[4096];
+    LPCTSTR lp_path = (LPCTSTR)temp;
+
+    if (path == NULL) {
+        return False;
+    }
+
+    strcpy(temp, path);
+
+    replace_character(temp, '/', '\\');
+
+    attributes = GetFileAttributes(lp_path);
+    return (attributes != (DWORD)-1);
+#else
+    return !access(path, F_OK);
+#endif
+}
+
+BOOL MkDir(
+    char* path
+    )
+{
+#ifdef _MSC_VER
+    char cmd[4096];
+#endif
+    if (file_exist(path))
+        return TRUE;
+
+#ifdef _MSC_VER
+    sprintf(cmd, "mkdir %s", path);
+    replace_character(cmd, '/', '\\');
+    if (system(cmd)) {
+        return FALSE;
+    }
+    return True;
+#else
+    return mkdir_recursive(path, S_IRWXU | S_IRWXG | S_IRWXO);
+#endif
+}
+ 

+ 1890 - 0
wave420l/code/sample/helper/main_helper.h

@@ -0,0 +1,1890 @@
+//------------------------------------------------------------------------------
+// File: main_helper.h
+//
+// Copyright (c) 2006, Chips & Media.  All rights reserved.
+//------------------------------------------------------------------------------
+#ifndef _MAIN_HELPER_H_
+#define _MAIN_HELPER_H_
+
+#include "config.h"
+#include "vpuapifunc.h"
+#include "vpuapi.h"
+#include "vputypes.h"
+#ifdef PLATFORM_QNX
+    #include <sys/stat.h>
+#endif
+
+#ifdef SUPPORT_ENCODE_CUSTOM_HEADER
+#include "./misc/header_struct.h"
+#endif
+
+#define MATCH_OR_MISMATCH(_expected, _value, _ret)        ((_ret=(_expected == _value)) ? "MATCH" : "MISMATCH")
+
+#if defined(WIN32) || defined(WIN64)
+/*
+ ( _MSC_VER => 1200 )     6.0     vs6
+ ( _MSC_VER => 1310 )     7.1     vs2003
+ ( _MSC_VER => 1400 )     8.0     vs2005
+ ( _MSC_VER => 1500 )     9.0     vs2008
+ ( _MSC_VER => 1600 )    10.0     vs2010
+ */
+#if (_MSC_VER == 1200)
+#define strcasecmp          stricmp
+#define strncasecmp         strnicmp
+#else
+#define strcasecmp          _stricmp
+#define strncasecmp         _strnicmp
+#endif
+#define inline              _inline
+#if (_MSC_VER == 1600)
+#define strdup              _strdup
+#endif
+#endif
+
+#define MAX_GETOPT_OPTIONS 100
+//extension of option struct in getopt
+struct OptionExt
+{
+    const char *name;
+    int has_arg;
+    int *flag;
+    int val;
+    const char *help;
+};
+
+#define MAX_FILE_PATH               256
+#define MAX_PIC_SKIP_NUM            5
+#ifdef SUPPORT_SRC_BUF_CONTROL
+#define ENC_SRC_BUF_NUM             2000
+#else
+#define ENC_SRC_BUF_NUM             16          //!< case of GOPsize = 8 (IBBBBBBBP), max src buffer num  = 13
+#endif
+
+
+#define EXTRA_SRC_BUFFER_NUM        0
+#define VPU_WAIT_TIME_OUT               10  //should be less than normal decoding time to give a chance to fill stream. if this value happens some problem. we should fix VPU_WaitInterrupt function
+#define VPU_WAIT_TIME_OUT_CQ            1
+#define PARALLEL_VPU_WAIT_TIME_OUT      1 	//the value of timeout is 1 means we want to keep a waiting time to give a chance of an interrupt of the next core.
+
+extern char* productNameList[];
+
+typedef union {
+    struct {
+        Uint32  ctu_force_mode  :  2; //[ 1: 0]
+        Uint32  ctu_coeff_drop  :  1; //[    2]
+        Uint32  reserved        :  5; //[ 7: 3]
+        Uint32  sub_ctu_qp_0    :  6; //[13: 8]
+        Uint32  sub_ctu_qp_1    :  6; //[19:14]
+        Uint32  sub_ctu_qp_2    :  6; //[25:20]
+        Uint32  sub_ctu_qp_3    :  6; //[31:26]
+
+        Uint32  lambda_sad_0    :  8; //[39:32]
+        Uint32  lambda_sad_1    :  8; //[47:40]
+        Uint32  lambda_sad_2    :  8; //[55:48]
+        Uint32  lambda_sad_3    :  8; //[63:56]
+    } field;
+} EncCustomMap; // for wave520 custom map (1 CTU = 64bits)
+
+typedef enum {
+    MODE_YUV_LOAD = 0,
+    MODE_COMP_JYUV,
+    MODE_SAVE_JYUV,
+
+    MODE_COMP_CONV_YUV,
+    MODE_SAVE_CONV_YUV,
+
+    MODE_SAVE_LOAD_YUV,
+
+    MODE_COMP_RECON,
+    MODE_SAVE_RECON,
+
+    MODE_COMP_ENCODED,
+    MODE_SAVE_ENCODED
+} CompSaveMode;
+
+typedef struct {
+    int picX;               
+    int picY;
+    int internalBitDepth;
+    int losslessEnable;        
+    int constIntraPredFlag;
+    int gopSize;
+    int numTemporalLayers;
+    int decodingRefreshType;
+    int intraQP;
+    int intraPeriod;
+    int frameRate;
+
+    int confWinTop;
+    int confWinBot;
+    int confWinLeft;
+    int confWinRight;
+
+    int independSliceMode;
+    int independSliceModeArg;
+    int dependSliceMode;
+    int dependSliceModeArg;
+    int intraRefreshMode;
+    int intraRefreshArg;
+
+    int useRecommendEncParam;
+    int scalingListEnable;
+    int cuSizeMode;
+    int tmvpEnable;
+    int wppenable;
+    int maxNumMerge;
+    int dynamicMerge8x8Enable;
+    int dynamicMerge16x16Enable;
+    int dynamicMerge32x32Enable;
+    int disableDeblk;
+    int lfCrossSliceBoundaryEnable;
+    int betaOffsetDiv2;
+    int tcOffsetDiv2;
+    int skipIntraTrans;
+    int saoEnable;
+    int intraInInterSliceEnable;
+    int intraNxNEnable;
+    int rcEnable;
+
+    int bitRate;
+    int intraQpOffset;
+    int initBufLevelx8;
+    int bitAllocMode;                   
+    int fixedBitRatio[MAX_GOP_NUM];
+    int cuLevelRCEnable;
+    int hvsQPEnable;
+
+    int hvsQpScaleEnable;
+    int hvsQpScale;
+    int minQp;
+    int maxQp;
+    int maxDeltaQp;
+
+    int initDelay;
+
+    int transRate;
+    int gopPresetIdx;
+    // CUSTOM_GOP
+    CustomGopParam gopParam;
+
+    // ROI / CTU mode
+    HevcCtuOptParam ctuOptParam;
+    char roiFileName[MAX_FILE_PATH];
+    char ctuQpFileName[MAX_FILE_PATH];
+
+    // VUI
+    HevcVuiParam vuiParam;
+    Uint32 numUnitsInTick;
+    Uint32 timeScale;
+    Uint32 numTicksPocDiffOne;
+
+    int encAUD;
+    int encEOS;
+    int encEOB;
+
+    int chromaCbQpOffset;
+    int chromaCrQpOffset;
+
+    Uint32 initialRcQp;
+
+    Uint32  nrYEnable;
+    Uint32  nrCbEnable;
+    Uint32  nrCrEnable;
+    Uint32  nrNoiseEstEnable;
+    Uint32  nrNoiseSigmaY;
+    Uint32  nrNoiseSigmaCb;
+    Uint32  nrNoiseSigmaCr;
+
+    Uint32  nrIntraWeightY;
+    Uint32  nrIntraWeightCb;
+    Uint32  nrIntraWeightCr;
+
+    Uint32  nrInterWeightY;
+    Uint32  nrInterWeightCb;
+    Uint32  nrInterWeightCr;
+
+    Uint32 intraMinQp;
+    Uint32 intraMaxQp;
+
+    Uint32 useAsLongtermPeriod;
+    Uint32 refLongtermPeriod;
+    Uint32 vuiDataEnable;
+    Uint32 vuiDataSize;
+    char   vuiDataFileName[MAX_FILE_PATH];
+    Uint32 hrdInVPS;
+    Uint32 hrdInVUI;
+    Uint32 hrdDataSize;
+    char   hrdDataFileName[MAX_FILE_PATH];
+    Uint32 prefixSeiEnable;
+    Uint32 prefixSeiDataSize;
+    Uint32 prefixSeiTimingFlag;
+    char   prefixSeiDataFileName[MAX_FILE_PATH];
+    Uint32 suffixSeiEnable;
+    Uint32 suffixSeiDataSize;
+    Uint32 suffixSeiTimingFlag;
+    char   suffixSeiDataFileName[MAX_FILE_PATH];
+    int    forcedIdrHeaderEnable;
+    
+    // newly added for WAVE520
+} HEVC_ENC_CFG;
+
+typedef struct {
+    char SrcFileName[MAX_FILE_PATH];
+    char BitStreamFileName[MAX_FILE_PATH];
+    BOOL srcCbCrInterleave;
+    int NumFrame;
+    int PicX;
+    int PicY;
+    int FrameRate;
+
+    // MPEG4 ONLY
+    int VerId;
+    int DataPartEn;
+    int RevVlcEn;
+    int ShortVideoHeader;
+    int AnnexI;
+    int AnnexJ;
+    int AnnexK;
+    int AnnexT;
+    int IntraDcVlcThr;
+    int VopQuant;
+
+    int frameCroppingFlag;
+    int frameCropLeft;
+    int frameCropRight;
+    int frameCropTop;
+    int frameCropBottom;
+
+    // H.264 ONLY
+    int ConstIntraPredFlag;
+    int DisableDeblk;
+    int DeblkOffsetA;
+    int DeblkOffsetB;
+    int ChromaQpOffset;
+    int PicQpY;
+    // H.264 VUI information
+    int VuiPresFlag;
+    int VideoSignalTypePresFlag;
+    char VideoFormat;
+    char VideoFullRangeFlag;
+    int ColourDescripPresFlag;
+    char ColourPrimaries;
+    char TransferCharacteristics;
+    char MatrixCoeff;
+    int NumReorderFrame;
+    int MaxDecBuffering;
+    int aud_en;
+    int level;
+    // COMMON
+    int GopPicNum;
+    int SliceMode;
+    int SliceSizeMode;
+    int SliceSizeNum;
+    // COMMON - RC
+    int RcEnable;
+    int RcBitRate;
+    int RcInitDelay;
+    int RcBufSize;
+    int IntraRefreshNum;
+    int ConscIntraRefreshEnable;
+    int frameSkipDisable;
+    int ConstantIntraQPEnable;
+    int MaxQpSetEnable;
+    int MaxQp;
+    //H.264 only
+    int MaxDeltaQpSetEnable;
+    int MaxDeltaQp;
+    int MinQpSetEnable;
+    int MinQp;
+    int MinDeltaQpSetEnable;
+    int MinDeltaQp;
+    int intraCostWeight;
+
+    //MP4 Only
+    int RCIntraQP;
+    int HecEnable;
+
+    int GammaSetEnable;
+    int Gamma;
+
+    // NEW RC Scheme
+    int rcIntervalMode;
+    int RcMBInterval;
+    int skipPicNums[MAX_PIC_SKIP_NUM];
+    int SearchRange;	// for coda960
+
+    int MeUseZeroPmv;	// will be removed. must be 264 = 0, mpeg4 = 1 263 = 0
+    int MeBlkModeEnable; // only api option
+    int IDRInterval;
+    int SrcBitDepth;
+
+    HEVC_ENC_CFG hevcCfg;
+#ifdef AUTO_FRM_SKIP_DROP
+    int enAutoFrmSkip;
+    int enAutoFrmDrop;
+    int vbvThreshold;
+    int qpThreshold;
+    int maxContinuosFrameSkipNum;
+    int maxContinuosFrameDropNum;
+#endif
+    int rcWeightFactor;
+} ENC_CFG;
+
+
+
+extern Uint32 randomSeed;
+
+/* yuv & md5 */
+#define NO_COMPARE         0
+#define YUV_COMPARE        1
+#define MD5_COMPARE        2
+#define STREAM_COMPARE     3
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/* Performance report */
+typedef void*   PFCtx;
+
+PFCtx PFMonitorSetup(
+    Uint32  coreIndex,
+    Uint32  instanceIndex,
+    Uint32  referenceClkInMHz,
+    Uint32  fps,
+    char*   strLogDir
+    );
+
+void PFMonitorRelease(
+    PFCtx   context
+    );
+
+void PFMonitorUpdate(
+    PFCtx   context,
+    Uint32  cycles
+    );
+
+void PrepareDecoderTest(
+    DecHandle decHandle
+    );
+
+void PreparationWorkForDecTest(
+    DecHandle decHandle
+    );
+
+void byte_swap(
+    unsigned char* data, 
+    int len
+    );
+
+Int32   LoadFirmware(
+    Int32       productId, 
+    Uint8**   retFirmware, 
+    Uint32*   retSizeInWord, 
+    const char* path
+    );
+
+void PrintDecSeqWarningMessages(
+    Uint32          productId, 
+    DecInitialInfo* seqInfo
+    );
+
+void 
+DisplayEncodedInformation(
+    EncHandle      handle, 
+    CodStd         codec, 
+    Uint32         frameNo, 
+    EncOutputInfo* encodedInfo,
+    ...
+    );
+
+void PrintEncSppStatus(
+    Uint32 coreIdx,
+    Uint32 productId
+    );
+
+void WriteRegVCE(
+    Uint32   core_idx,
+    Uint32   vce_core_idx,
+    Uint32   vce_addr,
+    Uint32   udata
+    );
+
+Uint32 ReadRegVCE(
+    Uint32 core_idx,
+    Uint32 vce_core_idx,
+    Uint32 vce_addr
+    );
+
+/*
+ * VPU Helper functions
+ */
+/************************************************************************/
+/* Video                                                                */
+/************************************************************************/
+
+#define PUT_BYTE(_p, _b) \
+    *_p++ = (unsigned char)_b; 
+
+#define PUT_BUFFER(_p, _buf, _len) \
+    osal_memcpy(_p, _buf, _len); \
+    _p += _len;
+
+#define PUT_LE32(_p, _var) \
+    *_p++ = (unsigned char)((_var)>>0);  \
+    *_p++ = (unsigned char)((_var)>>8);  \
+    *_p++ = (unsigned char)((_var)>>16); \
+    *_p++ = (unsigned char)((_var)>>24); 
+
+#define PUT_BE32(_p, _var) \
+    *_p++ = (unsigned char)((_var)>>24);  \
+    *_p++ = (unsigned char)((_var)>>16);  \
+    *_p++ = (unsigned char)((_var)>>8); \
+    *_p++ = (unsigned char)((_var)>>0); 
+
+#define PUT_LE16(_p, _var) \
+    *_p++ = (unsigned char)((_var)>>0);  \
+    *_p++ = (unsigned char)((_var)>>8);  
+
+#define PUT_BE16(_p, _var) \
+    *_p++ = (unsigned char)((_var)>>8);  \
+    *_p++ = (unsigned char)((_var)>>0);  
+
+Int32 ConvFOURCCToMp4Class(
+    Int32   fourcc
+    );
+
+Int32 ConvFOURCCToCodStd(
+    Uint32 fourcc
+    );
+
+Int32 ConvCodecIdToMp4Class(
+    Uint32 codecId
+    );
+
+Int32 ConvCodecIdToCodStd(
+    Int32   codecId
+    );
+
+Int32 ConvCodecIdToFourcc(
+    Int32   codecId
+    );
+
+/*!
+ * \brief       wrapper function of StoreYuvImageBurstFormat()
+ */
+Uint8* GetYUVFromFrameBuffer(
+    DecHandle       decHandle,
+    FrameBuffer*    fb,
+    VpuRect         rcFrame,
+	Uint32*       retWidth,
+    Uint32*       retHeight,
+    Uint32*       retBpp,
+	size_t*		retSize
+    );
+
+/************************************************************************/
+/* VpuMutex                                                                */
+/************************************************************************/
+typedef void*   VpuMutex;
+
+VpuMutex VpuMutex_Create(
+    void
+    );
+
+void VpuMutex_Destroy(
+    VpuMutex   handle
+    );
+
+BOOL VpuMutex_Lock(
+    VpuMutex   handle
+    );
+
+BOOL VpuMutex_Unlock(
+    VpuMutex   handle
+    );
+
+/************************************************************************/
+/* Queue                                                                */
+/************************************************************************/
+typedef struct {
+    void*   data;
+} QueueData;
+typedef struct {
+    Uint8*      buffer;
+    Uint32    size;
+    Uint32    itemSize;
+    Uint32    count;
+    Uint32    front;
+    Uint32    rear;
+    VpuMutex    lock;
+} Queue;
+
+Queue* Queue_Create(
+    Uint32    itemCount,
+    Uint32    itemSize
+    );
+
+Queue* Queue_Create_With_Lock(
+    Uint32    itemCount,
+    Uint32    itemSize
+    );
+
+void Queue_Destroy(
+    Queue*      queue
+    );
+
+/**
+ * \brief       Enqueue with deep copy
+ */
+BOOL Queue_Enqueue(
+    Queue*      queue, 
+    void*       data
+    );
+
+/**
+ * \brief       Caller has responsibility for releasing the returned data
+ */
+void* Queue_Dequeue(
+    Queue*      queue
+    );
+
+void Queue_Flush(
+    Queue*      queue
+    );
+
+void* Queue_Peek(
+    Queue*      queue
+    );
+
+Uint32 Queue_Get_Cnt(
+    Queue*      queue
+    );
+
+/**
+ * \brief       @dstQ is NULL, it allocates Queue structure and then copy from @srcQ.
+ */
+Queue* Queue_Copy(
+    Queue*  dstQ,
+    Queue*  srcQ
+    );
+
+/************************************************************************/
+/* VpuThread                                                               */
+/************************************************************************/
+typedef void*   VpuThread;
+typedef void(*VpuThreadRunner)(void*);
+
+VpuThread
+VpuThread_Create( 
+    VpuThreadRunner    func, 
+    void*           arg 
+    );
+
+BOOL
+VpuThread_Join( 
+    VpuThread thread 
+    );
+
+/*!
+ * \brief           millisecond sleep
+ */
+void
+MSleep(
+    Uint32    ms          //!<< millisecond
+    );
+
+/************************************************************************/
+/* ETC                                                                  */
+/************************************************************************/
+Uint32 GetRandom(
+    Uint32 start,
+    Uint32 end
+    );
+
+#ifdef PLATFORM_WIN32
+struct timezone {
+    Int32 tz_minuteswest; /* minutes W of Greenwich */
+    BOOL  tz_dsttime;     /* type of dst correction */
+};
+
+Int32 gettimeofday(
+    struct timeval*  tv, 
+    struct timezone* tz
+    );
+#endif
+/************************************************************************/
+/* MD5                                                                  */
+/************************************************************************/
+
+typedef struct MD5state_st {
+    Uint32 A,B,C,D;
+    Uint32 Nl,Nh;
+    Uint32 data[16];
+    Uint32 num;
+} MD5_CTX;
+
+Int32 MD5_Init(
+    MD5_CTX *c
+    );
+
+Int32 MD5_Update(
+    MD5_CTX*    c, 
+    const void* data, 
+    size_t      len);
+
+Int32 MD5_Final(
+    Uint8*      md, 
+    MD5_CTX*    c
+    );
+
+Uint8* MD5(
+    const Uint8*  d, 
+    size_t        n, 
+    Uint8*        md
+    );
+void plane_md5(MD5_CTX *md5_ctx, 
+    Uint8  *src,
+    int    src_x, 
+    int    src_y,
+    int    out_x, 
+    int    out_y,
+    int    stride, 
+    int    bpp, 
+    Uint16 zero
+);
+
+
+/************************************************************************/
+/* Comparator                                                           */
+/************************************************************************/
+#define COMPARATOR_SKIP 0xF0F0F0F0
+typedef enum {
+    COMPARATOR_CONF_SET_GOLDEN_DATA_SIZE,
+    COMPARATOR_CONF_SKIP_GOLDEN_DATA,       /*!<< 2nd parameter pointer of Queue 
+                                                  containing skip command */
+    COMPARATOR_CONF_SET_PICINFO,            //!<< This command is followed by YUVInfo structure.
+} ComparatorConfType;
+
+typedef void*   Comparator;
+typedef struct ComparatorImpl {
+    void*       context;
+    char*       filename;
+    Uint32      curIndex;
+    Uint32      numOfFrames;
+    BOOL        (*Create)(struct ComparatorImpl* impl, char* path);
+    BOOL        (*Destroy)(struct ComparatorImpl* impl);
+    BOOL        (*Compare)(struct ComparatorImpl* impl, void* data, Uint32 size);
+    BOOL        (*Configure)(struct ComparatorImpl* impl, ComparatorConfType type, void* val);
+    BOOL        (*Rewind)(struct ComparatorImpl* impl);
+    BOOL        eof;
+    BOOL        enableScanMode;
+    BOOL        usePrevDataOneTime;
+} ComparatorImpl;
+
+typedef struct {
+    Uint32          totalFrames;
+    ComparatorImpl* impl;
+} AbstractComparator;
+
+// YUV Comparator 
+typedef struct {
+    Uint32            width;
+    Uint32            height;
+    FrameBufferFormat   format;
+    BOOL                cbcrInterleave;
+    BOOL                isVp9;
+} PictureInfo;
+
+Comparator Comparator_Create(
+    Uint32    type,               //!<<   1: yuv
+    char* goldenPath,
+    ...
+    );
+
+BOOL Comparator_Destroy(
+    Comparator  comp
+    );
+
+BOOL Comparator_Act(
+    Comparator  comp,
+    void*       data,
+    Uint32    size
+    );
+
+BOOL Comparator_CheckFrameCount(
+    Comparator  comp
+    );
+
+BOOL Comparator_SetScanMode(
+    Comparator  comp,
+    BOOL        enable
+    );
+
+BOOL Comparator_Rewind(
+    Comparator  comp
+    );
+
+BOOL Comparator_CheckEOF(
+    Comparator  comp
+    );
+
+Queue* Comprator_MakeSkipData(
+    Comparator  comp,
+    const char* skipCmd
+    );
+
+BOOL IsEndOfFile(
+    FILE* fp
+    );
+
+/************************************************************************/
+/* Bitstream Feeder                                                     */
+/************************************************************************/
+typedef enum {
+    FEEDING_METHOD_FIXED_SIZE,
+    FEEDING_METHOD_FRAME_SIZE,
+    FEEDING_METHOD_SIZE_PLUS_ES,
+    FEEDING_METHOD_MAX
+} FeedingMethod;
+
+typedef struct {
+    void*       data;
+    Uint32    size;
+    BOOL        eos;        //!<< End of stream
+} BSChunk;
+
+typedef void* BSFeeder;
+
+typedef void (*BSFeederHook)(BSFeeder feeder, void* data, Uint32 size, void* arg);
+
+/**
+ * \brief           BitstreamFeeder consumes bitstream and updates information of bitstream buffer of VPU.
+ * \param handle    handle of decoder
+ * \param path      bitstream path
+ * \param method    feeding method. see FeedingMethod.
+ * \param loopCount If @loopCount is greater than 1 then BistreamFeeder reads the start of bitstream again
+ *                  when it encounters the end of stream @loopCount times.
+ * \param ...       FEEDING_METHOD_FIXED_SIZE:
+ *                      This value of parameter is size of chunk at a time.
+ *                      If the size of chunk is equal to zero than the BitstreamFeeder reads bistream in random size.(1Byte ~ 4MB)
+ * \return          It returns the pointer of handle containing the context of the BitstreamFeeder.
+ */
+void* BitstreamFeeder_Create(
+    const char*     path,
+    FeedingMethod   method,
+    PhysicalAddress base,
+    Uint32          size,
+    ...
+    );
+
+/**
+ * \brief           This is helper function set to simplify the flow that update bit-stream
+ *                  to the VPU.
+ */
+Uint32 BitstreamFeeder_Act(
+    DecHandle       decHandle,
+    BSFeeder        feeder,
+    EndianMode      endian,
+    vpu_buffer_t*   buffer
+    );
+
+/**
+ * \brief           Set filling bitstream as ringbuffer mode or linebuffer mode. 
+ * \param   mode    0 : auto 
+ *                  1 : ringbuffer
+ *                  2 : linebuffer.
+ */
+#define BSF_FILLING_AUTO                    0
+#define BSF_FILLING_RINGBUFFER              1
+#define BSF_FILLING_LINEBUFFER              2
+/* BSF_FILLING_RINBGUFFER_WITH_ENDFLAG:
+ * Scenario: 
+ * - Application writes 1 ~ 10 frames into bitstream buffer.
+ * - Set stream end flag by using VPU_DecUpdateBitstreamBuffer(handle, 0).
+ * - Application clears stream end flag by using VPU_DecUpdateBitstreamBuffer(handle, -1).
+ *   when indexFrameDisplay is equal to -1.
+ * NOTE:
+ * - Last frame cannot be a complete frame.
+ */
+#define BSF_FILLING_RINGBUFFER_WITH_ENDFLAG 3
+void BitstreamFeeder_SetFillMode(
+    BSFeeder    feeder,
+    Uint32      mode
+    );
+
+BOOL BitstreamFeeder_IsEos(
+    BSFeeder    feeder
+    );
+
+BOOL BitstreamFeeder_Destroy(
+    BSFeeder    feeder
+    );
+
+BOOL BitstreamFeeder_Rewind(
+    BSFeeder feeder
+    );
+
+BOOL BitstreamFeeder_SetHook(
+    BSFeeder        feeder,
+    BSFeederHook    hookFunc,
+    void*           arg
+    );
+
+BOOL BitstreamFeeder_SetAutoUpdate(
+    BSFeeder        feeder,
+    BOOL            onoff
+    );
+
+/************************************************************************/
+/* YUV Feeder                                                           */
+/************************************************************************/
+#define SOURCE_YUV                  0
+#define SOURCE_YUV_WITH_LOADER      2
+
+#define JPEG_CREATE      0x01        //!<< This command is followed by yuvInfo structure.
+typedef struct {
+    Uint32   cbcrInterleave;
+    Uint32   nv21;
+    Uint32   packedFormat;
+    Uint32   srcFormat;
+    Uint32   srcPlanar;
+    Uint32   srcStride;
+    Uint32   srcHeight;
+} YuvInfo;
+
+typedef void*  YuvFeeder;
+typedef struct YuvFeederImpl {
+    void*     context;
+    BOOL      (*Create)(struct YuvFeederImpl* impl, const char* path, Uint32 packed, Uint32 fbStride, Uint32 fbHeight);
+    BOOL      (*Feed)(struct YuvFeederImpl* impl, Int32   coreIdx, FrameBuffer *fb, size_t picWidth, size_t picHeight, void* arg);
+    BOOL      (*Destroy)(struct YuvFeederImpl* impl);
+    BOOL      (*Configure)(struct YuvFeederImpl* impl, Uint32 cmd, YuvInfo yuv);
+} YuvFeederImpl;
+
+typedef struct {
+    YuvFeederImpl* impl;
+    Uint8          pYuv;
+} AbstractYuvFeeder;
+
+typedef struct {
+    osal_file_t*    fp;
+    Uint8*          pYuv;
+    size_t          fbStride;
+    size_t          cbcrInterleave;
+    BOOL            srcPlanar;
+} yuvContext;
+
+YuvFeeder YuvFeeder_Create(
+    Uint32        type,
+    const char*   srcFilePath,
+    YuvInfo       yuvInfo
+    );
+
+BOOL YuvFeeder_Feed(
+    YuvFeeder       feeder,
+    Uint32          coreIdx,
+    FrameBuffer*    fb,
+    size_t          picWidth,
+    size_t          picHeight,
+    void*           arg
+    );
+
+BOOL YuvFeeder_Destroy(
+    YuvFeeder feeder
+    );
+
+
+/************************************************************************/
+/* CNM video helper                                                    */
+/************************************************************************/
+/**
+ *  \param  convertCbcrIntl     If this value is TRUE, it stores YUV as NV12 or NV21 to @fb
+ */
+BOOL LoadYuvImageBurstFormat(
+    Uint32      coreIdx, 
+    Uint8*      src, 
+    size_t      picWidth, 
+    size_t      picHeight,
+    FrameBuffer *fb,
+    BOOL        convertCbcrIntl
+    );
+
+
+
+void PreparationWorkForEncTest(
+    EncHandle   handle 
+    );
+
+int ProcessEncodedBitstreamBurst(
+    Uint32 core_idx, 
+    osal_file_t fp, 
+    int targetAddr,
+    PhysicalAddress bsBufStartAddr, 
+    PhysicalAddress bsBufEndAddr,
+    int size, 
+    int endian,
+    Comparator comparator
+    );
+
+BOOL LoadTiledImageYuvBurst(
+    Uint32          coreIdx,
+    BYTE*           pYuv, 
+    size_t          picWidth, 
+    size_t          picHeight, 
+    FrameBuffer*    fb, 
+    TiledMapConfig  mapCfg
+    );
+
+Uint32 StoreYuvImageBurstFormat(
+    Uint32          coreIndex, 
+    FrameBuffer*    fbSrc, 
+    TiledMapConfig  mapCfg, 
+    Uint8*          pDst, 
+    VpuRect         cropRect, 
+    BOOL            enableCrop
+    );
+
+/************************************************************************/
+/* Bit Reader                                                           */
+/************************************************************************/
+#define BS_RESET_BUF 0
+#define BS_RING_BUF 1
+#define BUFFER_MODE_TYPE_LINEBUFFER     0
+#define BUFFER_MODE_TYPE_RINGBUFFER     1
+typedef void*   BitstreamReader;
+typedef struct BitstreamReaderImpl {
+    void*       context;
+    BOOL      (*Create)(struct BitstreamReaderImpl* impl, const char* path);
+    Uint32  (*Act)(struct BitstreamReaderImpl* impl, Int32   coreIdx, PhysicalAddress bitstreamBuffer, Uint32 bitstreamBufferSize, int endian, Comparator comparator);
+    BOOL      (*Destroy)(struct BitstreamReaderImpl* impl);
+    BOOL      (*Configure)(struct BitstreamReaderImpl* impl, Uint32 cmd, void* val);
+} BitstreamReaderImpl;
+
+/*!
+ * \param   type                0: Linebuffer, 1: Ringbuffer
+ * \param   path                output filepath.
+ * \param   endian              Endianness of bitstream buffer
+ * \param   handle              Pointer of encoder handle
+ */
+BitstreamReader BitstreamReader_Create(
+    Uint32    type,
+    char*       path,
+    EndianMode  endian,
+    EncHandle*  handle
+    );
+
+/*!
+ * \param   bitstreamBuffer     base address of bitstream buffer
+ * \param   bitstreamBufferSize size of bitstream buffer
+ */
+BOOL BitstreamReader_Act(
+    BitstreamReader reader,
+    PhysicalAddress bitstreamBuffer,
+    Uint32        bitstreamBufferSize,
+    Uint32        defaultsize,
+    Comparator      comparator
+    );
+
+BOOL BitstreamReader_Destroy(
+    BitstreamReader reader
+    );
+
+/************************************************************************/
+/* Binary Reader                                                           */
+/************************************************************************/
+
+/************************************************************************/
+/* Simple Renderer                                                      */
+/************************************************************************/
+typedef void*       Renderer;
+
+typedef enum {
+    RENDER_DEVICE_NULL,
+    RENDER_DEVICE_FBDEV,
+    RENDER_DEVICE_HDMI,
+    RENDER_DEVICE_MAX
+} RenderDeviceType;
+
+typedef struct RenderDevice {
+    void*       context;
+    DecHandle   decHandle;
+    BOOL (*Open)(struct RenderDevice* device);
+    void (*Render)(struct RenderDevice* device, DecOutputInfo* fbInfo, Uint8* yuv, Uint32 width, Uint32 height);
+    BOOL (*Close)(struct RenderDevice* device);
+} RenderDevice;
+
+Renderer SimpleRenderer_Create(
+    DecHandle           decHandle,
+    RenderDeviceType    deviceType,
+    const char*         yuvPath            //!<< path to store yuv iamge. 
+    );
+
+Uint32 SimpleRenderer_Act(
+    Renderer        renderer,
+    DecOutputInfo*  fbInfo,
+    Uint8*          pYuv,
+    Uint32        width,
+    Uint32        height
+    );
+
+void* SimpleRenderer_GetFreeFrameInfo(
+    Renderer        renderer
+    );
+
+/* \brief       Flush display queues and clear display indexes 
+ */
+void SimpleRenderer_Flush(
+    Renderer        renderer
+    );
+
+BOOL SimpleRenderer_Destroy(
+    Renderer    renderer
+    );
+
+BOOL SimpleRenderer_SetFrameRate(
+    Renderer        renderer,
+    Uint32          fps
+    );
+
+
+/************************************************************************/
+/* Etc                                                                  */
+/************************************************************************/
+typedef struct {
+    DecOutputInfo*  buffer;
+    int             size;
+    int             count;
+    int             front;
+    int             rear;
+} frame_queue_item_t;
+
+frame_queue_item_t* frame_queue_init(
+    Int32   count
+    );
+
+void frame_queue_deinit(
+    frame_queue_item_t* queue
+    );
+
+Int32 frame_queue_enqueue(
+    frame_queue_item_t* queue, 
+    DecOutputInfo data
+    );
+
+Int32 frame_queue_dequeue(
+    frame_queue_item_t* queue, 
+    DecOutputInfo*      data
+    );
+
+Int32 frame_queue_dequeue_all(
+    frame_queue_item_t* queue
+    );
+
+Int32 frame_queue_peekqueue(
+    frame_queue_item_t* queue, 
+    DecOutputInfo*      data
+    );
+
+Int32 frame_queue_count(
+    frame_queue_item_t* queue
+    );
+
+Int32 frame_queue_check_in_queue(
+    frame_queue_item_t* queue, 
+    Int32               index
+    );
+
+/*******************************************************************************
+ * DATATYPES AND FUNCTIONS RELATED TO REPORT
+ *******************************************************************************/
+typedef struct 
+{
+    osal_file_t     fpPicDispInfoLogfile;
+    osal_file_t     fpPicTypeLogfile;
+    osal_file_t     fpSeqDispInfoLogfile;
+    osal_file_t     fpUserDataLogfile;
+    osal_file_t     fpSeqUserDataLogfile;
+
+    // encoder report file
+    osal_file_t     fpEncSliceBndInfo;
+    osal_file_t     fpEncQpInfo;
+    osal_file_t     fpEncmvInfo;
+    osal_file_t     fpEncsliceInfo;
+
+    // Report Information
+    BOOL            reportOpened;
+    Int32           decIndex;
+    vpu_buffer_t    vb_rpt;
+    BOOL            userDataEnable;
+    BOOL            userDataReportMode;
+
+    Int32           profile;
+    Int32           level;
+} vpu_rpt_info_t;
+
+typedef struct VpuReportConfig_t {
+    PhysicalAddress userDataBufAddr;
+    BOOL            userDataEnable;
+    Int32           userDataReportMode; // (0 : Int32errupt mode, 1 Int32errupt disable mode)
+    Int32           userDataBufSize;
+
+} VpuReportConfig_t;
+
+void OpenDecReport(
+    Uint32              core_idx, 
+    VpuReportConfig_t*  cfg
+    );
+
+void CloseDecReport(
+    Uint32 core_idx
+    );
+
+void ConfigDecReport(
+    Uint32      core_idx, 
+    DecHandle   handle, 
+    CodStd      bitstreamFormat
+    );
+
+void SaveDecReport(
+    Uint32          core_idx, 
+    DecHandle       handle, 
+    DecOutputInfo*  pDecInfo, 
+    CodStd          bitstreamFormat, 
+    Uint32          mbNumX, 
+    Uint32          mbNumY
+    );
+
+void CheckUserDataInterrupt(
+    Uint32      core_idx, 
+    DecHandle   handle, 
+    Int32       decodeIdx, 
+    CodStd      bitstreamFormat, 
+    Int32       int_reason
+    );
+
+#define MAX_CFG                 (217)
+#define MAX_ROI_LEVEL           (8)
+#define LOG2_CTB_SIZE           (6)
+#define CTB_SIZE                (1<<LOG2_CTB_SIZE)
+#define LAMBDA_SCALE_FACTOR     (100000)
+#define FLOATING_POINT_LAMBDA   (1)
+#define TEMP_SCALABLE_RC        (1)
+#define UI16_MAX                (0xFFFF)
+#ifndef INT_MAX
+#define INT_MAX                 (2147483647)
+#endif
+
+typedef enum {
+    INPUT_FILE = 0,
+    SOURCE_WIDTH,
+    SOURCE_HEIGHT,
+    INPUT_BIT_DEPTH,
+    FRAME_RATE,                   // 5
+    FRAME_SKIP,
+    FRAMES_TO_BE_ENCODED,
+    INTRA_PERIOD,
+    DECODING_REFRESH_TYPE,
+    DERIVE_LAMBDA_WEIGHT,         // 10
+    GOP_SIZE,
+    EN_INTRA_IN_INTER_SLICE,
+    INTRA_NXN,
+    EN_CU_8X8,
+    EN_CU_16X16,                  // 15
+    EN_CU_32X32,
+    INTRA_TRANS_SKIP,
+    CONSTRAINED_INTRA_PRED,
+    INTRA_CTU_REFRESH_MODE,
+    INTRA_CTU_REFRESH_ARG,        // 20
+    MAX_NUM_MERGE,
+    EN_DYN_MERGE,
+    EN_TEMPORAL_MVP,
+    SCALING_LIST,                 
+    INDE_SLICE_MODE,              // 25
+    INDE_SLICE_ARG,
+    DE_SLICE_MODE,
+    DE_SLICE_ARG,
+    EN_DBK,                       
+    EN_SAO,                       // 30
+    LF_CROSS_SLICE_BOUNDARY_FLAG,
+    BETA_OFFSET_DIV2,
+    TC_OFFSET_DIV2,
+    WAVE_FRONT_SYNCHRO,           
+    LOSSLESS_CODING,              // 35
+    USE_PRESENT_ENC_TOOLS,
+    NUM_TEMPORAL_LAYERS,
+    GOP_PRESET,
+    RATE_CONTROL,                 
+    ENC_BITRATE,                  // 40
+    TRANS_BITRATE,
+    INITIAL_DELAY,
+    EN_HVS_QP,
+    CU_LEVEL_RATE_CONTROL,        
+    CONF_WIND_SIZE_TOP,           // 45
+    CONF_WIND_SIZE_BOT,
+    CONF_WIND_SIZE_RIGHT,
+    CONF_WIND_SIZE_LEFT,
+    HVS_QP_SCALE_DIV2,
+    MIN_QP,                       // 50
+    MAX_QP,
+    MAX_DELTA_QP,
+    NUM_ROI,
+    INTRA_QP,
+    ROI_DELTA_QP,                 // 55
+    INTRA_QP_OFFSET,
+    INIT_BUF_LEVELx8,
+    BIT_ALLOC_MODE,
+    FIXED_BIT_RATIO,
+    INTERNAL_BITDEPTH,            // 60
+    EN_USER_DATA,
+    USER_DATA_ENC_ORDER,
+    USER_DATA_SIZE,
+    USER_DATA_SUFFIX_FLAG,
+    ROI_ENABLE,                   // 65            
+    VUI_PARAM_FLAG,
+    VUI_ASPECT_RATIO_IDC,
+    VUI_SAR_SIZE,
+    VUI_OVERSCAN_APPROPRIATE,
+    VIDEO_SIGNAL,                 // 70
+    VUI_CHROMA_SAMPLE_LOC,        
+    VUI_DISP_WIN_LEFT_RIGHT,
+    VUI_DISP_WIN_TOP_BOTTOM,
+    NUM_UNITS_IN_TICK,
+    TIME_SCALE,                   // 75
+    NUM_TICKS_POC_DIFF_ONE,       
+    ENC_AUD,
+    ENC_EOS,
+    ENC_EOB,
+    CB_QP_OFFSET,                // 80
+    CR_QP_OFFSET,
+    RC_INIT_QP, 
+    EN_NR_Y,
+    EN_NR_CB,
+    EN_NR_CR,                   // 85
+    EN_NOISE_EST,
+    NOISE_SIGMA_Y,
+    NOISE_SIGMA_CB,
+    NOISE_SIGMA_CR,
+    INTRA_NOISE_WEIGHT_Y,       // 90
+    INTRA_NOISE_WEIGHT_CB,
+    INTRA_NOISE_WEIGHT_CR,
+    INTER_NOISE_WEIGHT_Y,
+    INTER_NOISE_WEIGHT_CB,
+    INTER_NOISE_WEIGHT_CR,      // 95
+    INTRA_MIN_QP,
+    INTRA_MAX_QP,
+    MDFLAG0,   
+    MDFLAG1,   
+    MDFLAG2,        // 100 
+    EN_SMART_BG,
+    THRPIXELNUMCNT,
+    THRMEAN0,      
+    THRMEAN1,      
+    THRMEAN2,      // 105
+    THRMEAN3,      
+    MDQPY,          
+    MDQPC,         
+    THRDCY0,       
+    THRDCC0,       // 110
+    THRDCY1,       
+    THRDCC1,       
+    THRDCY2,       
+    THRDCC2,       
+    THRACNUMY0,    // 115 
+    THRACNUMC0,    
+    THRACNUMY1,     
+    THRACNUMC1,    
+    THRACNUMY2,      
+    THRACNUMC2,    // 120
+    USE_LONGTERM_PRRIOD,    
+    REF_LONGTERM_PERIOD,
+    EN_CTU_MODE,
+    EN_CTU_QP,
+    CROP_X_POS,     // 125
+    CROP_Y_POS,             
+    CROP_X_SIZE,
+    CROP_Y_SIZE,
+    EN_VUI_DATA,
+    VUI_DATA_SIZE,            // 130
+    EN_HRD_IN_VPS,
+    EN_HRD_IN_VUI,
+    HRD_DATA_SIZE,
+    EN_PREFIX_SEI_DATA,
+    PREFIX_SEI_DATA_SIZE,   // 135
+    PREFIX_SEI_TIMING_FLAG,
+    EN_SUFFIX_SEI_DATA,    
+    SUFFIX_SEI_DATA_SIZE,
+    SUFFIX_SEI_TIMING_FLAG,
+    EN_REPORT_MV_COL,     // 140
+    EN_REPORT_DIST_MAP,
+    EN_REPORT_BIT_INFO,
+    EN_REPORT_FRAME_DIST,
+    EN_REPORT_QP_HISTO,
+    BITSTREAM_FILE,                  // 145
+    EN_CUSTOM_VPS,
+    EN_CUSTOM_SPS,
+    EN_CUSTOM_PPS,
+    CUSTOM_VPS_PSID,
+    CUSTOM_SPS_PSID,                // 150
+    CUSTOM_SPS_ACTIVE_VPSID,
+    CUSTOM_PPS_ACTIVE_SPSID,
+    CUSTOM_VPS_INTFLAG,
+    CUSTOM_VPS_AVAILFLAG,
+    CUSTOM_VPS_MAXLAYER_MINUS1,     // 155
+    CUSTOM_VPS_MAXSUBLAYER_MINUS1,
+    CUSTOM_VPS_TEMPID_NESTFLAG,
+    CUSTOM_VPS_MAXLAYER_ID,
+    CUSTOM_VPS_NUMLAYER_SETMINUS1,  
+    CUSTOM_VPS_EXTFLAG,             // 160
+    CUSTOM_VPS_EXTDATAFLAG,
+    CUSTOM_VPS_SUBORDER_INFOFLAG,
+    CUSTOM_SPS_SUBORDER_INFOFLAG,
+    CUSTOM_VPS_LAYERID_0,
+    CUSTOM_VPS_LAYERID_1,           // 165
+    CUSTOM_SPS_LOG2_MAXPOC_MINUS4,
+    EN_FORCED_IDR_HEADER,
+    // newly added for WAVE520
+    EN_MONOCHROME,
+    EN_STRONG_INTRA_SMOOTH,
+    ROI_AVGQP,                     // 170
+    EN_WEIGHTED_PRED,
+    EN_BG_DETECT,
+    BG_TH_DIFF,
+    BG_TH_MEAN_DIFF,
+    BG_LAMBDA_QP,                   // 175
+    BG_DELTA_QP,
+    TILE_NUM_COLUMNS,
+    TILE_NUM_ROWS,
+    TILE_UNIFORM_SPACE,
+    EN_LAMBDA_MAP,                  // 180
+    EN_CUSTOM_LAMBDA,
+    EN_CUSTOM_MD,
+    PU04_DELTA_RATE,
+    PU08_DELTA_RATE,
+    PU16_DELTA_RATE,                // 185
+    PU32_DELTA_RATE,
+    PU04_INTRA_PLANAR_DELTA_RATE,
+    PU04_INTRA_DC_DELTA_RATE,
+    PU04_INTRA_ANGLE_DELTA_RATE,
+    PU08_INTRA_PLANAR_DELTA_RATE,   // 190
+    PU08_INTRA_DC_DELTA_RATE,
+    PU08_INTRA_ANGLE_DELTA_RATE,
+    PU16_INTRA_PLANAR_DELTA_RATE,
+    PU16_INTRA_DC_DELTA_RATE,
+    PU16_INTRA_ANGLE_DELTA_RATE,    // 195
+    PU32_INTRA_PLANAR_DELTA_RATE,
+    PU32_INTRA_DC_DELTA_RATE,
+    PU32_INTRA_ANGLE_DELTA_RATE,
+    CU08_INTRA_DELTA_RATE,
+    CU08_INTER_DELTA_RATE,          // 200
+    CU08_MERGE_DELTA_RATE,
+    CU16_INTRA_DELTA_RATE,
+    CU16_INTER_DELTA_RATE,
+    CU16_MERGE_DELTA_RATE,
+    CU32_INTRA_DELTA_RATE,          // 205
+    CU32_INTER_DELTA_RATE,
+    CU32_MERGE_DELTA_RATE,
+    DISABLE_COEF_CLEAR,
+    EN_CUSTOM_MODE_MAP,
+    EN_TEMPORAL_LAYER_QP,
+    TID_0_QP,
+    TID_1_QP,
+    TID_2_QP,
+    TID_0_PERIOD,
+} HevcCfgName;
+
+typedef struct {
+    char  *name;
+    int    min;
+    int    max;
+    int    def;
+} HevcCfgInfo;
+
+Int32 GetEncOpenParamChange(
+    EncOpenParam*   pEncOP, 
+    char*           cfgFileName, 
+    ENC_CFG*        pEncCfg,
+    EncHandle       handle
+    );
+
+void PrintVpuVersionInfo(
+    Uint32 coreIdx
+    );
+
+void ChangePathStyle(
+    char *str
+    );
+
+BOOL CalcYuvSize(
+    Int32   format,
+    Int32   picWidth,
+    Int32   picHeight,
+    Int32   cbcrInterleave,
+    size_t  *lumaSize,
+    size_t  *chromaSize,
+    size_t  *frameSize,
+    Int32   *bitDepth,
+    Int32   *packedFormat,
+    Int32   *yuv3p4b
+    );
+
+
+int GetPackedFormat (
+    int srcBitDepth, 
+    int packedType,
+    int p10bits,
+    int msb
+    );
+
+char* GetDirname(
+    const char* path
+    );
+
+char* GetBasename(
+    const char* pathname
+    );
+
+char* GetFileExtension(
+    const char* filename 
+    );
+
+int parseAvcCfgFile(
+    ENC_CFG*    pEncCfg, 
+    char*       filename 
+    );
+
+int parseMp4CfgFile(
+    ENC_CFG*    pEncCfg, 
+    char*       filename 
+    );
+
+int parseHevcCfgFile(
+    ENC_CFG*    pEncCfg, 
+    char*       FileName
+    );
+
+int parseRoiCtuModeParam(
+    char* lineStr,
+    VpuRect* roiRegion,
+    int* roiLevel,
+    int picX,
+    int picY
+    );
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+typedef struct ObserverStruct {
+    void*   ctx;
+    void (*construct)(struct ObserverStruct*, void*);
+    BOOL (*update)(struct ObserverStruct* ctx, void* data);
+    void (*destruct)(struct ObserverStruct*);
+} Listener;
+
+#define MAX_OBSERVERS           100
+typedef struct TestMachine_struct {
+    Uint32          coreIdx;
+    Uint32          testEnvOptions;             /*!<< See debug.h */
+    BOOL            reset;
+    Listener        observers[MAX_OBSERVERS];
+    Uint32          numObservers;
+} TestMachine;
+
+/************************************************************************/
+/* Structure                                                            */
+/************************************************************************/
+typedef struct TestDecConfig_struct {
+    Uint32              magicNumber;
+    char                outputPath[MAX_FILE_PATH];
+    char                inputPath[MAX_FILE_PATH];
+    Int32               forceOutNum;
+    Int32               bitFormat;
+    Int32               reorder;
+    TiledMapType        mapType;
+    Int32               bitstreamMode;
+    FeedingMethod       feedingMode;
+    BOOL                enableWTL;
+    FrameFlag           wtlMode;	
+    FrameBufferFormat   wtlFormat;
+    Int32               coreIdx;
+    Int32               instIdx;
+    BOOL                enableCrop;                 //!<< option for saving yuv 
+    Uint32              loopCount;                  
+    BOOL                cbcrInterleave;             //!<< 0: None, 1: NV12, 2: NV21 
+    BOOL                nv21;                       //!<< FALSE: NV12, TRUE: NV21, 
+                                                    //!<< This variable is valid when cbcrInterleave is TRUE 
+    EndianMode          streamEndian;
+    EndianMode          frameEndian;
+    Int32               secondaryAXI;
+    Int32               compareType;
+    char                md5Path[MAX_FILE_PATH];
+    char                fwPath[MAX_FILE_PATH];
+    char                refYuvPath[MAX_FILE_PATH];
+    RenderDeviceType    renderType;
+    BOOL                thumbnailMode;
+    Int32               skipMode;
+    size_t              bsSize;
+    struct {
+        BOOL        enableMvc;                      //!<< H.264 MVC
+        BOOL        enableSvc;
+        BOOL        enableTiled2Linear;
+        FrameFlag   tiled2LinearMode;
+        BOOL        enableBWB;
+        Uint32      rotate;                         //!<< 0, 90, 180, 270
+        Uint32      mirror;
+        BOOL        enableDering;                   //!<< MPEG-2/4
+        BOOL        enableDeblock;                  //!<< MPEG-2/4
+        Uint32      mp4class;                       //!<< MPEG_4
+        Uint32      frameCacheBypass;
+        Uint32      frameCacheBurst;
+        Uint32      frameCacheMerge;
+        Uint32      frameCacheWayShape;
+        LowDelayInfo    lowDelay;                   //!<< H.264
+    } coda9;
+    struct {
+        Uint32    numVCores;                      //!<< This numVCores is valid on PRODUCT_ID_4102 multi-core version 
+        Uint32    fbcMode;
+        BOOL        bwOptimization;                 //!<< On/Off bandwidth optimization function
+        BOOL        craAsBla;
+        BOOL        dualDisplay;
+    } wave4;
+    BOOL            enableUserData;
+    Uint32          testEnvOptions;             /*!<< See debug.h */
+    TestMachine*    testMachine;
+    Uint32          tid;                        /*!<< Target temporal id for AVC and HEVC */
+} TestDecConfig;
+
+extern Listener decOutputInformation;
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+BOOL TestMachineSetup(
+    TestMachine* machine
+    );
+
+void TestMachineCleanUp(
+    TestMachine* machine
+    );
+
+struct option* ConvertOptions(
+    struct OptionExt*   cnmOpt,
+    Uint32              nItems
+    );
+
+void ReleaseVideoMemory(
+    Uint32        coreIndex,
+    vpu_buffer_t*   memoryArr,
+    Uint32        count
+    );
+
+BOOL AllocateDecFrameBuffer(
+    DecHandle       decHandle,
+    TestDecConfig*  config,
+    Uint32        tiledFbCount,
+    Uint32        linearFbCount,
+    FrameBuffer*    retFbArray,
+    vpu_buffer_t*   retFbAddrs,
+    Uint32*       retStride
+    );
+
+#define OUTPUT_FP_NUMBER 4
+BOOL OpenDisplayBufferFile(
+    char *outputPath, 
+    VpuRect rcDisplay, 
+    TiledMapType mapType,
+    FILE *fp[]
+    );
+
+void CloseDisplayBufferFile(
+    FILE *fp[]
+    );
+
+void SaveDisplayBufferToFile(
+    DecHandle handle, 
+    FrameBuffer dispFrame, 
+    VpuRect rcDisplay, 
+    FILE *fp[]
+    );
+
+
+
+#ifdef SUPPORT_SAVE_PIC_INFO_TO_XML
+FILE * CreatePicInfoXmlFile(
+    const char *yuvPath
+    );
+
+    void ClosePicInfoXMLFile(
+    FILE*   fpXML
+    );
+
+void SavePicInfoToXml(
+    FILE*           fpXml, 
+    DecOutputInfo*  fbInfo
+    );
+#endif /* SUPPORT_SAVE_PIC_INFO_TO_XML */
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+typedef struct TestEncConfig_struct {
+    Uint32  magicNumber;
+    char    yuvSourceBaseDir[MAX_FILE_PATH];
+    char    yuvFileName[MAX_FILE_PATH];
+    char    cmdFileName[MAX_FILE_PATH];
+    char    bitstreamFileName[MAX_FILE_PATH];
+    char    huffFileName[MAX_FILE_PATH];
+    char    cInfoFileName[MAX_FILE_PATH];
+    char    qMatFileName[MAX_FILE_PATH];
+    char    qpFileName[MAX_FILE_PATH];
+    char    cfgFileName[MAX_FILE_PATH];
+    CodStd  stdMode;
+    int     picWidth;
+    int     picHeight;
+    int     kbps;
+    int     rotAngle;
+    int     mirDir;
+    int     useRot;
+    int     qpReport;
+    int     ringBufferEnable;
+    int     rcIntraQp;
+    int     outNum;
+    int     skipPicNums[MAX_PIC_SKIP_NUM];
+    int     instNum;
+    int     coreIdx;
+    int     mapType;
+    // 2D cache option
+
+    int lineBufIntEn;
+    int en_container;                   //enable container
+    int container_frame_rate;           //framerate for container
+    int picQpY;
+
+    int cbcrInterleave;
+    int nv21;
+    BOOL needSourceConvert;         //!<< If the format of YUV file is YUV planar mode and EncOpenParam::cbcrInterleave or EncOpenParam::nv21 is true
+                                    //!<< the value of needSourceConvert should be true.
+    int packedFormat;
+    int srcFormat;
+    int srcFormat3p4b;
+    int bitdepth;
+    int secondary_axi;
+    int stream_endian;
+    int frame_endian;
+    int source_endian;
+
+    int compare_type;
+#define YUV_MODE_YUV 0 
+#define YUV_MODE_JYUV_CONV 1 
+#define YUV_MODE_YUV_LOADER 2 
+    int yuv_mode;
+    char ref_stream_path[MAX_FILE_PATH];
+    int loopCount;
+    char ref_recon_md5_path[MAX_FILE_PATH];
+#if defined(SUPPORT_W5ENC_BW_REPORT) || defined(CNM_FPGA_PLATFORM)
+    BOOL    performance;
+#endif
+    char roi_file_name[MAX_FILE_PATH];
+    FILE *roi_file;
+    int roi_enable;
+    int roi_delta_qp;
+    char ctuqp_file_name[MAX_FILE_PATH];
+    FILE *ctuqp_file;
+    int ctu_qp_enable;
+    int ctuQp[MAX_ROI_NUMBER];
+
+    //char user_data_file_name[MAX_FILE_PATH];
+    //FILE *user_data_fp;
+    HevcSEIDataEnc seiDataEnc;
+
+    char hrd_rbsp_file_name[MAX_FILE_PATH];
+    FILE *hrd_rbsp_fp;
+
+    char vui_rbsp_file_name[MAX_FILE_PATH];
+    FILE *vui_rbsp_fp;
+
+    char prefix_sei_nal_file_name[MAX_FILE_PATH];
+    FILE *prefix_sei_nal_fp;
+
+    char suffix_sei_nal_file_name[MAX_FILE_PATH];
+    FILE *suffix_sei_nal_fp;
+
+    int encAUD;
+    int encEOS;
+    int encEOB;
+    struct {
+        BOOL        enableSvc;
+        BOOL        enableLinear2Tiled;
+        FrameFlag   linear2TiledMode;
+    } coda9;
+    VpuRect region[MAX_ROI_NUMBER];        /**< The size of the ROI region for H.265 (start X/Y in CTU, end X/Y int CTU)  */
+    int roiLevel[MAX_ROI_NUMBER];       /**< An importance level for the given ROI region for H.265. The higher an ROI level is, the more important the region is with a lower QP.  */
+
+    int useAsLongtermPeriod;
+    int refLongtermPeriod;
+    Uint32          testEnvOptions;             /*!<< See debug.h */
+    // newly added for WAVE520
+} TestEncConfig;
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+Int32   GetEncOpenParam(
+    EncOpenParam*   pEncOP, 
+    TestEncConfig*  pEncConfig, 
+    ENC_CFG*        pEncCfg
+    );
+
+Int32 GetEncOpenParamDefault(
+    EncOpenParam*   pEncOP, 
+    TestEncConfig*  pEncConfig
+    );
+
+void GenRegionToMap(
+    VpuRect *region,        /**< The size of the ROI region for H.265 (start X/Y in CTU, end X/Y in CTU)  */
+    int *roiLevel,
+    int num,
+    Uint32 mapWidth,
+    Uint32 mapHeight,
+    Uint8 *roiCtuMap
+    );
+
+int setRoiMap(
+    int coreIdx, 
+    TestEncConfig *encConfig, 
+    EncOpenParam encOP, 
+    PhysicalAddress addrRoiMap,
+    Uint8 *roiMapBuf, 
+    int srcFrameWidth, 
+    int srcFrameHeight, 
+    EncParam *encParam, 
+    int maxCtuNum
+    );
+
+#define VUI_HRD_RBSP_BUF_SIZE           0x4000
+#define SEI_NAL_DATA_BUF_SIZE           0x4000
+Int32 writeVuiRbsp(
+    int coreIdx,
+    TestEncConfig *encConfig, 
+    EncOpenParam *encOP, 
+    vpu_buffer_t *vbVuiRbsp
+    );
+Int32 writeHrdRbsp(
+    int coreIdx, 
+    TestEncConfig *encConfig, 
+    EncOpenParam *encOP, 
+    vpu_buffer_t *vbHrdRbsp
+    );
+
+#ifdef TEST_ENCODE_CUSTOM_HEADER
+Int32 writeCustomHeader(
+    int coreIdx, 
+    EncOpenParam *encOP, 
+    vpu_buffer_t *vbVuiRbsp, 
+    hrd_t *hrd
+    );
+Int32 allocateSeiNalDataBuf(
+    int coreIdx, 
+    vpu_buffer_t *vbSeiNal, 
+    int srcFbNum
+    );
+Int32 writeSeiNalData(
+    EncHandle handle, 
+    int streamEndian, 
+    PhysicalAddress prefixSeiNalAddr,
+    hrd_t *hrd
+    );
+#endif
+void setEncBgMode(
+    EncParam *encParam, 
+    TestEncConfig encConfig
+    );
+
+void GenRegionToQpMap(
+    VpuRect *region,        /**< The size of the ROI region for H.265 (start X/Y in CTU, end X/Y int CTU)  */
+    int *roiLevel,
+    int num,
+    int initQp,
+    Uint32 mapWidth,
+    Uint32 mapHeight,
+    Uint8 *roiCtuMap
+    );
+
+int checkParamRestriction(
+    Uint32 productId,
+    TestEncConfig *encConfig
+    );
+int openRoiMapFile(
+    TestEncConfig *encConfig
+    );
+int allocateRoiMapBuf(
+    int coreIdx, 
+    TestEncConfig encConfig, 
+    vpu_buffer_t *vbROi, 
+    int srcFbNum, 
+    int ctuNum
+    );
+
+int openCtuQpMapFile(
+    TestEncConfig *encConfig
+    );
+
+int allocateCtuQpMapBuf(
+    int coreIdx, 
+    TestEncConfig encConfig,
+    vpu_buffer_t *vbCtuQp,
+    int srcfbNum,
+    int ctuNum
+    );
+int setCtuQpMap(
+    int coreIdx, 
+    TestEncConfig *encConfig, 
+    EncOpenParam encOP, 
+    PhysicalAddress addrCtuQpMap,
+    Uint8 *ctuQpMapBuf, 
+    int srcFrameWidth, 
+    int srcFrameHeight, 
+    EncParam *encParam, 
+    int maxCtuNum
+    );
+
+
+/************************************************************************/
+/* User Parameters (WAVE520)                                            */
+/************************************************************************/
+// user scaling list
+#define SL_NUM_MATRIX (6)
+
+typedef struct 
+{ 
+    Uint8 s4[SL_NUM_MATRIX][16]; // [INTRA_Y/U/V,INTER_Y/U/V][NUM_COEFF]
+    Uint8 s8[SL_NUM_MATRIX][64];
+    Uint8 s16[SL_NUM_MATRIX][64];
+    Uint8 s32[SL_NUM_MATRIX][64];
+}UserScalingList;
+
+enum ScalingListSize
+{
+    SCALING_LIST_4x4 = 0,
+    SCALING_LIST_8x8,
+    SCALING_LIST_16x16,
+    SCALING_LIST_32x32,
+    SCALING_LIST_SIZE_NUM
+};
+
+int parse_user_scaling_list(UserScalingList* sl, FILE* fp_sl);
+
+void dpb_pic_init( EncInfo *pAvcInfo);
+// custom lambda
+#define NUM_CUSTOM_LAMBDA   (2*52)
+int parse_custom_lambda(Uint32 buf[NUM_CUSTOM_LAMBDA], FILE* fp);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif	/* _MAIN_HELPER_H_ */
+ 

+ 1681 - 0
wave420l/code/sample/helper/misc/cfgParser.c

@@ -0,0 +1,1681 @@
+//------------------------------------------------------------------------------
+// File: Mixer.c
+//
+// Copyright (c) 2006, Chips & Media.  All rights reserved.
+//------------------------------------------------------------------------------
+
+#include <stdio.h>
+#include <errno.h>
+#include "vpuapi.h"
+#include "vpuapifunc.h"
+#include "main_helper.h"
+
+#include <string.h>
+
+const HevcCfgInfo hevcCfgInfo[MAX_CFG] = {
+    //name                          min            max              default
+    {"InputFile",                   0,              0,                      0},
+    {"SourceWidth",                 0,              W4_MAX_ENC_PIC_WIDTH,   0},
+    {"SourceHeight",                0,              W4_MAX_ENC_PIC_WIDTH,   0},
+    {"InputBitDepth",               8,              10,                     8},
+    {"FrameRate",                   0,              240,                    0}, // 5
+    {"FrameSkip",                   0,              INT_MAX,                0},
+    {"FramesToBeEncoded",           0,              INT_MAX,                0},
+    {"IntraPeriod",                 0,              UI16_MAX,               0},
+    {"DecodingRefreshType",         0,              2,                      1},
+    {"DeriveLambdaWeight",          0,              1,                      0}, // 10
+    {"GOPSize",                     1,              MAX_GOP_NUM,            1},
+    {"EnIntraInInterSlice",         0,              1,                      1},
+    {"IntraNxN",                    0,              1,                      1},
+    {"EnCu8x8",                     0,              1,                      1},
+    {"EnCu16x16",                   0,              1,                      1}, // 15
+    {"EnCu32x32",                   0,              1,                      1},
+    {"IntraTransSkip",              0,              2,                      1},
+    {"ConstrainedIntraPred",        0,              1,                      0},
+    {"IntraCtuRefreshMode",         0,              4,                      0},
+    {"IntraCtuRefreshArg",          0,              UI16_MAX,               0}, // 20
+    {"MaxNumMerge",                 0,              2,                      2},
+    {"EnDynMerge",                  0,              1,                      1},
+    {"EnTemporalMVP",               0,              1,                      1},
+    {"ScalingList",                 0,              1,                      0}, 
+    {"IndeSliceMode",               0,              1,                      0}, // 25
+    {"IndeSliceArg",                0,              UI16_MAX,               0},
+    {"DeSliceMode",                 0,              2,                      0},
+    {"DeSliceArg",                  0,              UI16_MAX,               0},
+    {"EnDBK",                       0,              1,                      1}, 
+    {"EnSAO",                       0,              1,                      1}, // 30
+    {"LFCrossSliceBoundaryFlag",    0,              1,                      1},
+    {"BetaOffsetDiv2",             -6,              6,                      0},
+    {"TcOffsetDiv2",               -6,              6,                      0},
+    {"WaveFrontSynchro",            0,              1,                      0}, 
+    {"LosslessCoding",              0,              1,                      0}, // 35
+    {"UsePresetEncTools",           0,              3,                      0},
+    {"NumTemporalLayers",           0,              7,                      1},
+    {"GopPreset",                   0,             20,                      0},
+    {"RateControl",                 0,              1,                      0}, 
+    {"EncBitrate",                  0,              700000000,              0}, // 40
+    {"TransBitrate",                0,              700000000,              0},
+    {"InitialDelay",                10,             3000,                   3000},
+    {"EnHvsQp",                     0,              1,                      1},
+    {"CULevelRateControl",          0,              1,                      1}, 
+    {"ConfWindSizeTop",             0,              W4_MAX_ENC_PIC_HEIGHT,  0}, // 45
+    {"ConfWindSizeBot",             0,              W4_MAX_ENC_PIC_HEIGHT,  0},
+    {"ConfWindSizeRight",           0,              W4_MAX_ENC_PIC_WIDTH,   0},
+    {"ConfWindSizeLeft",            0,              W4_MAX_ENC_PIC_WIDTH,   0},
+    {"HvsQpScaleDiv2",              0,              4,                      2},
+    {"MinQp",                       0,              51,                     8}, // 50
+    {"MaxQp",                       0,              51,                     51},
+    {"MaxDeltaQp",                  0,              51,                     10},
+    {"NumRoi",                      0,              MAX_ROI_NUMBER,         0},
+    {"QP",                          0,              51,                     30},
+    {"RoiDeltaQP",                  1,              51,                     3}, // 55
+    {"IntraQpOffset",              -10,             10,                     0}, 
+    {"InitBufLevelx8",              0,              8,                      1},
+    {"BitAllocMode",                0,              2,                      0},
+    {"FixedBitRatio%d",             1,              255,                    1},
+    {"InternalBitDepth",            0,              10,                     0}, // 60
+    {"EnUserDataSei",               0,              1,                      0},  
+    {"UserDataEncTiming",           0,              1,                      0},
+    {"UserDataSize",                0,              (1<<24) - 1,            1},
+    {"UserDataPos",                 0,              1,                      0},
+    {"EnRoi",                       0,              1,                      0}, // 65
+    {"VuiParamFlags",               0,              INT_MAX,                0},  
+    {"VuiAspectRatioIdc",           0,              255,                    0},  
+    {"VuiSarSize",                  0,              INT_MAX,                0},  
+    {"VuiOverScanAppropriate",      0,              1,                      0},  
+    {"VideoSignal",                 0,              INT_MAX,                0}, // 70
+    {"VuiChromaSampleLoc",          0,              INT_MAX,                0},  
+    {"VuiDispWinLeftRight",         0,              INT_MAX,                0},  
+    {"VuiDispWinTopBottom",         0,              INT_MAX,                0},  
+    {"NumUnitsInTick",              0,              INT_MAX,                0},  
+    {"TimeScale",                   0,              INT_MAX,                0}, // 75 
+    {"NumTicksPocDiffOne",          0,              INT_MAX,                0},  
+    {"EncAUD",                      0,              1,                      0},  
+    {"EncEOS",                      0,              1,                      0},  
+    {"EncEOB",                      0,              1,                      0},  
+    {"CbQpOffset",                  -10,            10,                     0}, // 80
+    {"CrQpOffset",                  -10,            10,                     0},  
+    {"RcInitialQp",                 -1,              63,                     63},  
+    {"EnNoiseReductionY",           0,              1,                      0},  
+    {"EnNoiseReductionCb",          0,              1,                      0},  
+    {"EnNoiseReductionCr",          0,              1,                      0}, // 85 
+    {"EnNoiseEst",                  0,              1,                      1},  
+    {"NoiseSigmaY",                 0,              255,                    0},  
+    {"NoiseSigmaCb",                0,              255,                    0},  
+    {"NoiseSigmaCr",                0,              255,                    0},  
+    {"IntraNoiseWeightY",           0,              31,                     7}, // 90 
+    {"IntraNoiseWeightCb",          0,              31,                     7},  
+    {"IntraNoiseWeightCr",          0,              31,                     7},  
+    {"InterNoiseWeightY",           0,              31,                     4},  
+    {"InterNoiseWeightCb",          0,              31,                     4},  
+    {"InterNoiseWeightCr",          0,              31,                     4}, // 95 
+    {"IntraMinQp",                  0,              51,                     8},  
+    {"IntraMaxQp",                  0,              51,                     51}, 
+    {"MdFlag0",                     0,              1,                      0},  
+    {"MdFlag1",                     0,              1,                      0}, 
+    {"MdFlag2",                     0,              1,                      0}, // 100 
+    {"EnSmartBackground",           0,              1,                      0},
+    {"ThrPixelNumCnt",              0,              63,                     0}, 
+    {"ThrMean0",                    0,              255,                    5},  
+    {"ThrMean1",                    0,              255,                    5}, 
+    {"ThrMean2",                    0,              255,                    5}, // 105 
+    {"ThrMean3",                    0,              255,                    5}, 
+    {"MdQpY",                       0,              51,                     30},  
+    {"MdQpC",                       0,              51,                     30}, 
+    {"ThrDcY0",                     0,              UI16_MAX,               2},  
+    {"ThrDcC0",                     0,              UI16_MAX,               2}, // 110
+    {"ThrDcY1",                     0,              UI16_MAX,               2}, 
+    {"ThrDcC1",                     0,              UI16_MAX,               2}, 
+    {"ThrDcY2",                     0,              UI16_MAX,               2},  
+    {"ThrDcC2",                     0,              UI16_MAX,               2}, 
+    {"ThrAcNumY0",                  0,              63,                     12},// 115  
+    {"ThrAcNumC0",                  0,              15,                     3}, 
+    {"ThrAcNumY1",                  0,              255,                    51},  
+    {"ThrAcNumC1",                  0,              63,                     12}, 
+    {"ThrAcNumY2",                  0,              1023,                   204},  
+    {"ThrAcNumC2",                  0,              255,                    51},// 120 
+    {"UseAsLongTermRefPeriod",      0,              INT_MAX,                0}, 
+    {"RefLongTermPeriod",           0,              INT_MAX,                0}, 
+    {"EnCtuMode",                   0,              1,                      0}, 
+    {"EnCtuQp",                     0,              1,                      0}, 
+    {"CropXPos",                    0,              W4_MAX_ENC_PIC_WIDTH,   0}, // 125
+    {"CropYPos",                    0,              W4_MAX_ENC_PIC_HEIGHT,  0}, 
+    {"CropXSize",                   0,              W4_MAX_ENC_PIC_WIDTH,   0}, 
+    {"CropYSize",                   0,              W4_MAX_ENC_PIC_HEIGHT,  0}, 
+    {"EncodeRbspVui",               0,              1,                      0}, 
+    {"RbspVuiSize",                 0,              INT_MAX,                0}, // 130
+    {"EncodeRbspHrdInVps",          0,              1,                      0}, 
+    {"EncodeRbspHrdInVui",          0,              1,                      0}, 
+    {"RbspHrdSize",                 0,              INT_MAX,                0}, 
+    {"EnPrefixSeiData",             0,              1,                      0}, 
+    {"PrefixSeiDataSize",           0,              UI16_MAX,               0}, // 135
+    {"PrefixSeiTimingFlag",         0,              1,                      0}, 
+    {"EnSuffixSeiData",             0,              1,                      0}, 
+    {"SuffixSeiDataSize",           0,              UI16_MAX,               0}, 
+    {"SuffixSeiTimingFlag",         0,              1,                      0}, 
+    {"EnReportMvCol",               0,              1,                      0}, // 140
+    {"EnReportDistMap",             0,              1,                      0}, 
+    {"EnReportBitInfo",             0,              1,                      0}, 
+    {"EnReportFrameDist",           0,              1,                      0}, 
+    {"EnReportQpHisto",             0,              1,                      0}, 
+    {"BitstreamFile",               0,              0,                      0}, // 145
+    {"EnCustomVpsHeader",           0,              1,                      0},
+    {"EnCustomSpsHeader",           0,              1,                      0},
+    {"EnCustomPpsHeader",           0,              1,                      0},
+    {"CustomVpsPsId",               0,              15,                     0},
+    {"CustomSpsPsId",               0,              15,                     0}, // 150
+    {"CustomSpsActiveVpsId",        0,              15,                     0},
+    {"CustomPpsActiveSpsId",        0,              15,                     0},
+    {"CustomVpsIntFlag",            0,              1,                      1},
+    {"CustomVpsAvailFlag",          0,              1,                      1},
+    {"CustomVpsMaxLayerMinus1",     0,              62,                     0}, // 155
+    {"CustomVpsMaxSubLayerMinus1",  0,              6,                      0},
+    {"CustomVpsTempIdNestFlag",     0,              1,                      0},
+    {"CustomVpsMaxLayerId",         0,              31,                     0},
+    {"CustomVpsNumLayerSetMinus1",  0,              2,                      0},
+    {"CustomVpsExtFlag",            0,              1,                      0}, // 160
+    {"CustomVpsExtDataFlag",        0,              1,                      0},
+    {"CustomVpsSubOrderInfoFlag",   0,              1,                      0},
+    {"CustomSpsSubOrderInfoFlag",   0,              1,                      0},
+    {"CustomVpsLayerId0",           0,              0xFFFFFFFF,             0},
+    {"CustomVpsLayerId1",           0,              0xFFFFFFFF,             0}, // 165
+    {"CustomSpsLog2MaxPocMinus4",   0,              12,                     4}, 
+    {"EnForcedIDRHeader",           0,              1,                      0}, 
+
+// newly added for WAVE520
+    {"EncMonochrome",               0,              1,                      0}, 
+    {"StrongIntraSmoothing",        0,              1,                      1}, 
+    {"RoiAvgQP",                    0,              51,                     0}, // 170
+    {"WeightedPred",                0,              1,                      0}, 
+    {"EnBgDetect",                  0,              1,                      0}, 
+    {"BgThDiff",                    0,              255,                    8}, 
+    {"BgThMeanDiff",                0,              255,                    1}, 
+    {"BgLambdaQp",                  0,              51,                     32},// 175 
+    {"BgDeltaQp",                   -16,            15,                     3}, 
+    {"TileNumColumns",              1,              6,                      1}, 
+    {"TileNumRows",                 1,              6,                      1}, 
+    {"TileUniformSpace",            0,              1,                      1}, 
+    {"EnLambdaMap",                 0,              1,                      0}, // 180
+    {"EnCustomLambda",              0,              1,                      0}, 
+    {"EnCustomMD",                  0,              1,                      0}, 
+    {"PU04DeltaRate",               -128,           127,                    0}, 
+    {"PU08DeltaRate",               -128,           127,                    0}, 
+    {"PU16DeltaRate",               -128,           127,                    0}, // 185
+    {"PU32DeltaRate",               -128,           127,                    0}, 
+    {"PU04IntraPlanarDeltaRate",    -128,           127,                    0}, 
+    {"PU04IntraDcDeltaRate",        -128,           127,                    0}, 
+    {"PU04IntraAngleDeltaRate",     -128,           127,                    0}, 
+    {"PU08IntraPlanarDeltaRate",    -128,           127,                    0}, // 190
+    {"PU08IntraDcDeltaRate",        -128,           127,                    0}, 
+    {"PU08IntraAngleDeltaRate",     -128,           127,                    0}, 
+    {"PU16IntraPlanarDeltaRate",    -128,           127,                    0}, 
+    {"PU16IntraDcDeltaRate",        -128,           127,                    0},
+    {"PU16IntraAngleDeltaRate",     -128,           127,                    0}, // 195
+    {"PU32IntraPlanarDeltaRate",    -128,           127,                    0},
+    {"PU32IntraDcDeltaRate",        -128,           127,                    0},
+    {"PU32IntraAngleDeltaRate",     -128,           127,                    0}, 
+    {"CU08IntraDeltaRate",          -128,           127,                    0},
+    {"CU08InterDeltaRate",          -128,           127,                    0}, // 200
+    {"CU08MergeDeltaRate",          -128,           127,                    0},
+    {"CU16IntraDeltaRate",          -128,           127,                    0},
+    {"CU16InterDeltaRate",          -128,           127,                    0}, 
+    {"CU16MergeDeltaRate",          -128,           127,                    0},
+    {"CU32IntraDeltaRate",          -128,           127,                    0}, // 205
+    {"CU32InterDeltaRate",          -128,           127,                    0},
+    {"CU32MergeDeltaRate",          -128,           127,                    0}, 
+    {"DisableCoefClear",            0,              1,                      0}, 
+    {"EnModeMap",                   0,              3,                      0},
+    {"EnTemporalLayerQp",           0,              1,                      0},
+    {"TID_0_Qp",                    0,              51,                     30},
+    {"TID_1_Qp",                    0,              51,                     33},
+    {"TID_2_Qp",                    0,              51,                     36},
+    {"TID_0_Period",                2,              128,                    60},
+};
+
+//------------------------------------------------------------------------------
+// ENCODE PARAMETER PARSE FUNCSIONS
+//------------------------------------------------------------------------------
+// Parameter parsing helper
+static int GetValue(osal_file_t fp, char *para, char *value)
+{
+	char lineStr[256];
+	char paraStr[256];
+	osal_fseek(fp, 0, SEEK_SET);
+	
+	while (1) {
+		if (fgets(lineStr, 256, fp) == NULL)
+			return 0;
+		sscanf(lineStr, "%s %s", paraStr, value);
+		if (paraStr[0] != ';') {
+			if (strcmp(para, paraStr) == 0)
+				return 1;
+		}
+	}
+} 
+
+// Parse "string number number ..." at most "num" numbers
+// e.g. SKIP_PIC_NUM 1 3 4 5
+static int GetValues(osal_file_t fp, char *para, int *values, int num)
+{
+    char line[1024];
+
+    osal_fseek(fp, 0, SEEK_SET);
+
+    while (1)
+    {
+        int  i;
+        char *str;
+
+        if (fgets(line, sizeof(line)-1, fp) == NULL)
+            return 0;
+
+        // empty line
+        if ((str = strtok(line, " ")) == NULL)
+            continue;
+
+        if(strcmp(str, para) != 0)
+            continue;
+
+        for (i=0; i<num; i++)
+        {
+            if ((str = strtok(NULL, " ")) == NULL)
+                return 1;
+            if (!isdigit((Int32)str[0]))
+                return 1;
+            values[i] = atoi(str);
+        }
+        return 1;
+    }
+}
+
+int parseMp4CfgFile(ENC_CFG *pEncCfg, char *FileName)
+{
+	osal_file_t fp;
+    char sValue[1024];
+    int  ret = 0;
+
+    fp = osal_fopen(FileName, "rt");
+    if (fp == NULL) {
+        return ret;
+    }
+
+	if (GetValue(fp, "YUV_SRC_IMG", sValue) == 0)
+        goto __end_parseMp4CfgFile;
+    else
+		strcpy(pEncCfg->SrcFileName, sValue);
+	
+	if (GetValue(fp, "FRAME_NUMBER_ENCODED", sValue) == 0)
+        goto __end_parseMp4CfgFile;
+    pEncCfg->NumFrame = atoi(sValue);
+	if (GetValue(fp, "PICTURE_WIDTH", sValue) == 0)
+        goto __end_parseMp4CfgFile;
+	pEncCfg->PicX = atoi(sValue);
+	if (GetValue(fp, "PICTURE_HEIGHT", sValue) == 0)
+        goto __end_parseMp4CfgFile;
+	pEncCfg->PicY = atoi(sValue);
+	if (GetValue(fp, "FRAME_RATE", sValue) == 0)
+        goto __end_parseMp4CfgFile;
+	{
+		double frameRate;
+        int  timeRes, timeInc;
+#ifdef ANDROID
+		frameRate = atoi(sValue);
+#else
+		frameRate = atof(sValue);
+#endif
+        timeInc = 1;
+        while ((int)frameRate != frameRate) {
+            timeInc *= 10;
+            frameRate *= 10;
+        }
+        timeRes = (int) frameRate;
+        // divide 2 or 5
+        if (timeInc%2 == 0 && timeRes%2 == 0) {
+            timeInc /= 2; 
+            timeRes /= 2;
+        }
+        if (timeInc%5 == 0 && timeRes%5 == 0) {
+            timeInc /= 5;
+            timeRes /= 5;
+        }
+        if (timeRes == 2997 && timeInc == 100) {
+            timeRes = 30000;
+            timeInc = 1001;
+        }
+        pEncCfg->FrameRate = (timeInc - 1) << 16;
+        pEncCfg->FrameRate |= timeRes;
+    }
+	if (GetValue(fp, "VERSION_ID", sValue) == 0)
+        goto __end_parseMp4CfgFile;
+	pEncCfg->VerId = atoi(sValue);
+	if (GetValue(fp, "DATA_PART_ENABLE", sValue) == 0)
+        goto __end_parseMp4CfgFile;
+	pEncCfg->DataPartEn = atoi(sValue);
+	if (GetValue(fp, "REV_VLC_ENABLE", sValue) == 0)
+        goto __end_parseMp4CfgFile;
+	pEncCfg->RevVlcEn = atoi(sValue);
+
+	if (GetValue(fp, "INTRA_DC_VLC_THRES", sValue) == 0)
+        goto __end_parseMp4CfgFile;
+	pEncCfg->IntraDcVlcThr = atoi(sValue);
+	if (GetValue(fp, "SHORT_VIDEO", sValue) == 0)
+        goto __end_parseMp4CfgFile;
+	pEncCfg->ShortVideoHeader = atoi(sValue);
+	if (GetValue(fp, "ANNEX_I_ENABLE", sValue) == 0)
+        goto __end_parseMp4CfgFile;
+	pEncCfg->AnnexI = atoi(sValue);
+	if (GetValue(fp, "ANNEX_J_ENABLE", sValue) == 0)
+        goto __end_parseMp4CfgFile;
+	pEncCfg->AnnexJ = atoi(sValue);
+	if (GetValue(fp, "ANNEX_K_ENABLE", sValue) == 0)
+        goto __end_parseMp4CfgFile;
+	pEncCfg->AnnexK = atoi(sValue);
+	if (GetValue(fp, "ANNEX_T_ENABLE", sValue) == 0)
+        goto __end_parseMp4CfgFile;
+	pEncCfg->AnnexT = atoi(sValue);
+
+	if (GetValue(fp, "VOP_QUANT_SCALE", sValue) == 0)
+        goto __end_parseMp4CfgFile;
+	pEncCfg->VopQuant = atoi(sValue);
+	if (GetValue(fp, "GOP_PIC_NUMBER", sValue) == 0)
+        goto __end_parseMp4CfgFile;
+	pEncCfg->GopPicNum = atoi(sValue);
+	if (GetValue(fp, "SLICE_MODE", sValue) == 0)
+        goto __end_parseMp4CfgFile;
+	pEncCfg->SliceMode = atoi(sValue);
+	if (GetValue(fp, "SLICE_SIZE_MODE", sValue) == 0)
+        goto __end_parseMp4CfgFile;
+	pEncCfg->SliceSizeMode = atoi(sValue);
+	if (GetValue(fp, "SLICE_SIZE_NUMBER", sValue) == 0)
+        goto __end_parseMp4CfgFile;
+	pEncCfg->SliceSizeNum = atoi(sValue);	
+	
+	if (GetValue(fp, "RATE_CONTROL_ENABLE", sValue) == 0)
+        goto __end_parseMp4CfgFile;
+	pEncCfg->RcEnable = atoi(sValue);
+	if (GetValue(fp, "BIT_RATE_KBPS", sValue) == 0)
+        goto __end_parseMp4CfgFile;
+	pEncCfg->RcBitRate = atoi(sValue);
+	if (GetValue(fp, "DELAY_IN_MS", sValue) == 0)
+        goto __end_parseMp4CfgFile;
+	pEncCfg->RcInitDelay = atoi(sValue);
+	if (GetValue(fp, "VBV_BUFFER_SIZE", sValue) == 0)
+        goto __end_parseMp4CfgFile;
+	pEncCfg->RcBufSize = atoi(sValue);
+	if (GetValue(fp, "INTRA_MB_REFRESH", sValue) == 0)
+        goto __end_parseMp4CfgFile;
+	pEncCfg->IntraRefreshNum = atoi(sValue);
+
+    pEncCfg->ConscIntraRefreshEnable = 0;
+    if (pEncCfg->IntraRefreshNum > 0)
+    {
+        if (GetValue(fp, "CONSC_INTRA_REFRESH_EN", sValue) == 0)
+            pEncCfg->ConscIntraRefreshEnable = 0;
+        else
+            pEncCfg->ConscIntraRefreshEnable = atoi(sValue);
+    }
+	if (GetValue(fp, "CONST_INTRA_QP_EN", sValue) == 0)
+		pEncCfg->ConstantIntraQPEnable = 0;
+	else
+		pEncCfg->ConstantIntraQPEnable = atoi(sValue);
+	if (GetValue(fp, "CONST_INTRA_QP", sValue) == 0)
+        pEncCfg->RCIntraQP = 0;
+	else
+		pEncCfg->RCIntraQP = atoi(sValue);
+
+	if (GetValue(fp, "HEC_ENABLE", sValue) == 0)
+		pEncCfg->HecEnable = 0;
+	else
+		pEncCfg->HecEnable = atoi(sValue);
+
+	if (GetValue(fp, "SEARCH_RANGE", sValue) == 0)
+		pEncCfg->SearchRange = 0;
+	else
+		pEncCfg->SearchRange = atoi(sValue);
+	if (GetValue(fp, "ME_USE_ZERO_PMV", sValue) == 0)
+		pEncCfg->MeUseZeroPmv = 0;
+	else
+		pEncCfg->MeUseZeroPmv = atoi(sValue);
+	if (GetValue(fp, "WEIGHT_INTRA_COST", sValue) == 0)
+        pEncCfg->intraCostWeight = 0;
+	else
+		pEncCfg->intraCostWeight = atoi(sValue);
+
+	if (GetValue(fp, "MAX_QP_SET_ENABLE", sValue) == 0)
+		pEncCfg->MaxQpSetEnable= 0;
+	else
+		pEncCfg->MaxQpSetEnable = atoi(sValue);
+	if (GetValue(fp, "MAX_QP", sValue) == 0)
+        pEncCfg->MaxQp = 0;
+	else
+		pEncCfg->MaxQp = atoi(sValue);
+	if (GetValue(fp, "GAMMA_SET_ENABLE", sValue) == 0)
+        pEncCfg->GammaSetEnable = 0;
+	else
+		pEncCfg->GammaSetEnable = atoi(sValue);
+	if (GetValue(fp, "GAMMA", sValue) == 0)
+        pEncCfg->Gamma = 0;
+	else
+		pEncCfg->Gamma = atoi(sValue);
+
+	if (GetValue(fp, "RC_INTERVAL_MODE", sValue) == 0)
+        pEncCfg->rcIntervalMode = 0;
+	else
+		pEncCfg->rcIntervalMode = atoi(sValue);
+
+	if (GetValue(fp, "RC_MB_INTERVAL", sValue) == 0)
+        pEncCfg->RcMBInterval = 0;
+	else
+		pEncCfg->RcMBInterval = atoi(sValue);
+
+    ret = 1; /* Success */
+
+__end_parseMp4CfgFile:
+	osal_fclose(fp);
+	return ret;
+}
+
+
+
+
+
+int parseAvcCfgFile(ENC_CFG *pEncCfg, char *FileName)
+{
+    osal_file_t fp;
+    char sValue[1024];
+    int  ret = 0;
+
+    fp = osal_fopen(FileName, "r");
+    if (fp == NULL) {
+        return 0;
+    }
+
+    if (GetValue(fp, "YUV_SRC_IMG", sValue) == 0)
+        goto __end_parseAvcCfgFile;
+    else
+        strcpy(pEncCfg->SrcFileName, sValue);
+
+    if (GetValue(fp, "FRAME_NUMBER_ENCODED", sValue) == 0)
+        goto __end_parseAvcCfgFile;
+    pEncCfg->NumFrame = atoi(sValue);
+    if (GetValue(fp, "PICTURE_WIDTH", sValue) == 0)
+        goto __end_parseAvcCfgFile;
+    pEncCfg->PicX = atoi(sValue);
+    if (GetValue(fp, "PICTURE_HEIGHT", sValue) == 0)
+        goto __end_parseAvcCfgFile;
+    pEncCfg->PicY = atoi(sValue);
+    if (GetValue(fp, "FRAME_RATE", sValue) == 0)
+        goto __end_parseAvcCfgFile;
+    {
+        double frameRate;
+        int  timeRes, timeInc;
+
+#ifdef ANDROID
+        frameRate = atoi(sValue);
+#else
+        frameRate = atof(sValue);
+#endif
+
+        timeInc = 1;
+        while ((int)frameRate != frameRate) {
+            timeInc *= 10;
+            frameRate *= 10;
+        }
+        timeRes = (int) frameRate;
+        // divide 2 or 5
+        if (timeInc%2 == 0 && timeRes%2 == 0) {
+            timeInc /= 2; 
+            timeRes /= 2;
+        }
+        if (timeInc%5 == 0 && timeRes%5 == 0) {
+            timeInc /= 5; 
+            timeRes /= 5;
+        }
+
+        if (timeRes == 2997 && timeInc == 100) {
+            timeRes = 30000; 
+timeInc = 1001;
+        }
+        pEncCfg->FrameRate = (timeInc - 1) << 16;
+        pEncCfg->FrameRate |= timeRes;
+    }
+    if (GetValue(fp, "CONSTRAINED_INTRA", sValue) == 0)
+        goto __end_parseAvcCfgFile;
+    pEncCfg->ConstIntraPredFlag = atoi(sValue);
+    if (GetValue(fp, "DISABLE_DEBLK", sValue) == 0)
+        goto __end_parseAvcCfgFile;
+    pEncCfg->DisableDeblk = atoi(sValue);
+    if (GetValue(fp, "DEBLK_ALPHA", sValue) == 0)
+        goto __end_parseAvcCfgFile;
+    pEncCfg->DeblkOffsetA = atoi(sValue);
+    if (GetValue(fp, "DEBLK_BETA", sValue) == 0)
+        goto __end_parseAvcCfgFile;
+    pEncCfg->DeblkOffsetB = atoi(sValue);
+    if (GetValue(fp, "CHROMA_QP_OFFSET", sValue) == 0)
+        goto __end_parseAvcCfgFile;
+    pEncCfg->ChromaQpOffset = atoi(sValue);
+
+    if (GetValue(fp, "LEVEL", sValue) == 0)
+    {
+        pEncCfg->level = 0;//note : 0 means auto calculation.
+    }
+    else
+    {
+        pEncCfg->level = atoi(sValue);
+        if (pEncCfg->level<0 || pEncCfg->level>51)
+            goto __end_parseAvcCfgFile;
+    }
+
+    if (GetValue(fp, "PIC_QP_Y", sValue) == 0)
+        goto __end_parseAvcCfgFile;
+    pEncCfg->PicQpY = atoi(sValue);
+    if (GetValue(fp, "GOP_PIC_NUMBER", sValue) == 0)
+        goto __end_parseAvcCfgFile;
+    pEncCfg->GopPicNum = atoi(sValue);
+    if (GetValue(fp, "IDR_INTERVAL", sValue) == 0)
+        pEncCfg->IDRInterval = 0;
+    else
+        pEncCfg->IDRInterval = atoi(sValue);
+    if (GetValue(fp, "SLICE_MODE", sValue) == 0)
+        goto __end_parseAvcCfgFile;
+    pEncCfg->SliceMode = atoi(sValue);
+    if (GetValue(fp, "SLICE_SIZE_MODE", sValue) == 0)
+        goto __end_parseAvcCfgFile;
+    pEncCfg->SliceSizeMode = atoi(sValue);
+    if (GetValue(fp, "SLICE_SIZE_NUMBER", sValue) == 0)
+        goto __end_parseAvcCfgFile;
+    pEncCfg->SliceSizeNum = atoi(sValue);	
+    if (GetValue(fp, "AUD_ENABLE", sValue) == 0)
+        pEncCfg->aud_en = 0;
+    else
+        pEncCfg->aud_en = atoi(sValue);	
+
+    /**
+    * Error Resilience
+    */
+    // Intra Cost Weight : not mandatory. default zero
+    if (GetValue(fp, "WEIGHT_INTRA_COST", sValue) == 0)
+        pEncCfg->intraCostWeight = 0;
+    else
+        pEncCfg->intraCostWeight = atoi(sValue);
+
+    /**
+    * CROP information
+    */
+    if (GetValue(fp, "FRAME_CROP_LEFT", sValue) == 0)
+        pEncCfg->frameCropLeft = 0;
+    else
+        pEncCfg->frameCropLeft = atoi(sValue);
+
+    if (GetValue(fp, "FRAME_CROP_RIGHT", sValue) == 0)
+        pEncCfg->frameCropRight = 0;
+    else
+        pEncCfg->frameCropRight = atoi(sValue);
+
+    if (GetValue(fp, "FRAME_CROP_TOP", sValue) == 0)
+        pEncCfg->frameCropTop = 0;
+    else
+        pEncCfg->frameCropTop = atoi(sValue);
+
+    if (GetValue(fp, "FRAME_CROP_BOTTOM", sValue) == 0)
+        pEncCfg->frameCropBottom = 0;
+    else
+        pEncCfg->frameCropBottom = atoi(sValue);
+
+    /**
+    * ME Option
+    */
+
+    if (GetValue(fp, "ME_USE_ZERO_PMV", sValue) == 0)
+        pEncCfg->MeUseZeroPmv = 0;
+    else
+        pEncCfg->MeUseZeroPmv = atoi(sValue);
+
+    if (GetValue(fp, "ME_BLK_MODE_ENABLE", sValue) == 0)
+        pEncCfg->MeBlkModeEnable = 0;
+    else
+        pEncCfg->MeBlkModeEnable = atoi(sValue);
+
+    if (GetValue(fp, "RATE_CONTROL_ENABLE", sValue) == 0)
+        goto __end_parseAvcCfgFile;
+    pEncCfg->RcEnable = atoi(sValue);
+    if (GetValue(fp, "BIT_RATE_KBPS", sValue) == 0)
+        goto __end_parseAvcCfgFile;
+    pEncCfg->RcBitRate = atoi(sValue);
+    if (GetValue(fp, "DELAY_IN_MS", sValue) == 0)
+        goto __end_parseAvcCfgFile;
+    pEncCfg->RcInitDelay = atoi(sValue);
+
+    if (GetValue(fp, "VBV_BUFFER_SIZE", sValue) == 0)
+        goto __end_parseAvcCfgFile;
+    pEncCfg->RcBufSize = atoi(sValue);
+    if (GetValue(fp, "INTRA_MB_REFRESH", sValue) == 0)
+        goto __end_parseAvcCfgFile;
+    pEncCfg->IntraRefreshNum = atoi(sValue);
+
+    pEncCfg->ConscIntraRefreshEnable = 0;
+    if (pEncCfg->IntraRefreshNum > 0)
+    {
+        if (GetValue(fp, "CONSC_INTRA_REFRESH_EN", sValue) == 0)
+            pEncCfg->ConscIntraRefreshEnable = 0;
+        else
+            pEncCfg->ConscIntraRefreshEnable = atoi(sValue);
+    }
+
+    if (GetValue(fp, "FRAME_SKIP_DISABLE", sValue) == 0)
+        pEncCfg->frameSkipDisable = 0;
+    else
+        pEncCfg->frameSkipDisable = atoi(sValue);
+
+    if (GetValue(fp, "CONST_INTRAQP_ENABLE", sValue) == 0)
+        pEncCfg->ConstantIntraQPEnable = 0;
+    else
+        pEncCfg->ConstantIntraQPEnable = atoi(sValue);
+
+    if (GetValue(fp, "RC_INTRA_QP", sValue) == 0)
+        pEncCfg->RCIntraQP = 0;
+    else
+        pEncCfg->RCIntraQP = atoi(sValue);
+    if (GetValue(fp, "MAX_QP_SET_ENABLE", sValue) == 0)
+        pEncCfg->MaxQpSetEnable= 0;
+    else
+        pEncCfg->MaxQpSetEnable = atoi(sValue);
+
+    if (GetValue(fp, "MAX_QP", sValue) == 0)
+        pEncCfg->MaxQp = 0;
+    else
+        pEncCfg->MaxQp = atoi(sValue);
+
+    if (GetValue(fp, "MIN_QP_SET_ENABLE", sValue) == 0)
+        pEncCfg->MinQpSetEnable= 0;
+    else
+        pEncCfg->MinQpSetEnable = atoi(sValue);
+    if (GetValue(fp, "MIN_QP", sValue) == 0)
+        pEncCfg->MinQp = 0;
+    else
+        pEncCfg->MinQp = atoi(sValue);
+
+    if (GetValue(fp, "MAX_DELTA_QP_SET_ENABLE", sValue) == 0)
+        pEncCfg->MaxDeltaQpSetEnable= 0;
+    else
+        pEncCfg->MaxDeltaQpSetEnable = atoi(sValue);
+    if (GetValue(fp, "MAX_DELTA_QP", sValue) == 0)
+        pEncCfg->MaxDeltaQp = 0;
+    else
+        pEncCfg->MaxDeltaQp = atoi(sValue);
+
+    if (GetValue(fp, "MIN_DELTA_QP_SET_ENABLE", sValue) == 0)
+        pEncCfg->MinDeltaQpSetEnable= 0;
+    else
+        pEncCfg->MinDeltaQpSetEnable = atoi(sValue);
+    if (GetValue(fp, "MIN_DELTA_QP", sValue) == 0)
+        pEncCfg->MinDeltaQp = 0;
+    else
+        pEncCfg->MinDeltaQp = atoi(sValue);
+
+    if (GetValue(fp, "GAMMA_SET_ENABLE", sValue) == 0)
+        pEncCfg->GammaSetEnable = 0;
+    else
+        pEncCfg->GammaSetEnable = atoi(sValue);
+    if (GetValue(fp, "GAMMA", sValue) == 0)
+        pEncCfg->Gamma = 0;
+    else
+        pEncCfg->Gamma = atoi(sValue);
+    /* CODA960 features */
+    if (GetValue(fp, "RC_INTERVAL_MODE", sValue) == 0)
+        pEncCfg->rcIntervalMode = 0;
+    else
+        pEncCfg->rcIntervalMode = atoi(sValue);
+
+    if (GetValue(fp, "RC_MB_INTERVAL", sValue) == 0)
+        pEncCfg->RcMBInterval = 0;
+    else
+        pEncCfg->RcMBInterval = atoi(sValue);
+    /***************************************/
+    if (GetValue(fp, "RC_INTERVAL_MODE", sValue) == 0)
+        pEncCfg->rcIntervalMode = 0;
+    else
+        pEncCfg->rcIntervalMode = atoi(sValue);
+
+    if (GetValue(fp, "RC_MB_INTERVAL", sValue) == 0)
+        pEncCfg->RcMBInterval = 0;
+    else
+        pEncCfg->RcMBInterval = atoi(sValue);
+    if (GetValue(fp, "SEARCH_RANGE", sValue) == 0)
+        pEncCfg->SearchRange = 0;
+    else
+        pEncCfg->SearchRange = atoi(sValue);
+
+
+    osal_memset(pEncCfg->skipPicNums, 0, sizeof(pEncCfg->skipPicNums));
+    GetValues(fp, "SKIP_PIC_NUMS", pEncCfg->skipPicNums, sizeof(pEncCfg->skipPicNums));    
+
+
+    /**
+    * VUI Parameter
+    */
+    if (GetValue(fp, "VUI_PARAMETERS_PRESENT_FLAG", sValue) == 0)
+        pEncCfg->VuiPresFlag = 0;
+    else 
+        pEncCfg->VuiPresFlag = atoi(sValue);
+
+    if (pEncCfg->VuiPresFlag == 1) {
+
+        if (GetValue(fp, "VIDEO_SIGNAL_TYPE_PRESENT_FLAG", sValue) == 0)
+            pEncCfg->VideoSignalTypePresFlag = 0;
+        else
+            pEncCfg->VideoSignalTypePresFlag = atoi(sValue);
+
+        if (pEncCfg->VideoSignalTypePresFlag) {
+            if (GetValue(fp, "VIDEO_FORMAT", sValue) == 0)
+                pEncCfg->VideoFormat = 5;
+            else
+                pEncCfg->VideoFormat = atoi(sValue);
+
+            if (GetValue(fp, "VIDEO_FULL_RANGE_FLAG", sValue) == 0)
+                pEncCfg->VideoFullRangeFlag = 0;
+            else 
+                pEncCfg->VideoFullRangeFlag = atoi(sValue);
+
+            if (GetValue(fp, "COLOUR_DESCRIPTION_PRESENT_FLAG", sValue) == 0)
+                pEncCfg->ColourDescripPresFlag = 1;
+            else
+                pEncCfg->ColourDescripPresFlag = atoi(sValue);
+
+            if (pEncCfg->ColourDescripPresFlag) {
+                if (GetValue(fp, "COLOUR_PRIMARIES", sValue) == 0)
+                    pEncCfg->ColourPrimaries = 1;
+                else
+                    pEncCfg->ColourPrimaries = atoi(sValue);
+
+                if (GetValue(fp, "TRANSFER_CHARACTERISTICS", sValue) == 0)
+                    pEncCfg->TransferCharacteristics = 2;
+                else
+                    pEncCfg->TransferCharacteristics = atoi(sValue);
+
+                if (GetValue(fp, "MATRIX_COEFFICIENTS", sValue) == 0)
+                    pEncCfg->MatrixCoeff = 2;
+                else
+                    pEncCfg->MatrixCoeff = atoi(sValue);
+            }
+        }
+    }
+
+    ret = 1; /* Success */
+__end_parseAvcCfgFile:
+    osal_fclose(fp);
+    return ret;
+}
+
+static int HEVC_GetStringValue(
+    osal_file_t fp,
+    char* para,
+    char* value
+    )
+{
+    int pos = 0;
+    char* token = NULL;
+    char lineStr[256] = {0, };
+    char valueStr[256] = {0, };
+    osal_fseek(fp, 0, SEEK_SET);
+
+    while (1) {
+        if ( fgets(lineStr, 256, fp) == NULL ) {
+            return 0;
+        }
+
+        if( (lineStr[0] == '#') || (lineStr[0] == ';') || (lineStr[0] == ':') ) { // check comment
+            continue;
+        }
+
+        token = strtok(lineStr, ": "); // parameter name is separated by ' ' or ':'
+        if( token != NULL ) {
+            if ( strcasecmp(para, token) == 0) { // check parameter name
+                token = strtok(NULL, ":\r\n");
+                osal_memcpy( valueStr, token, strlen(token) );
+                while( valueStr[pos] == ' ' ) { // check space
+                    pos++;
+                }
+
+                strcpy(value, &valueStr[pos]);
+                return 1;
+            }
+            else {
+                continue;
+            }
+        }
+        else {
+            continue;
+        }
+    }
+}
+
+static int HEVC_GetValue(
+    osal_file_t fp,
+    HevcCfgName cfgName,
+    int* value
+    )
+{
+    int iValue;
+    char sValue[256] = {0, };
+    
+    if(HEVC_GetStringValue(fp, hevcCfgInfo[cfgName].name, sValue) == 1) {
+        iValue = atoi(sValue);
+        if( (iValue >= hevcCfgInfo[cfgName].min) && (iValue <= hevcCfgInfo[cfgName].max) ) { // Check min, max
+            *value = iValue;
+            return 1;
+        }
+        else {
+            VLOG(ERR, "CFG file error : %s value is not available. ( min = %d, max = %d)\n", hevcCfgInfo[cfgName].name, hevcCfgInfo[cfgName].min, hevcCfgInfo[cfgName].max);
+            return 0;
+        }
+    }
+    else {
+        *value = hevcCfgInfo[cfgName].def;
+        return 1;
+    }
+}
+
+
+static int HEVC_SetGOPInfo(
+    char* lineStr,
+    CustomGopPicParam* gopPicParam,
+    int* gopPicLambda,
+    int useDeriveLambdaWeight,
+    int intraQp
+    )
+{
+    int numParsed;
+    char sliceType;
+    double lambda;
+
+    osal_memset(gopPicParam, 0, sizeof(CustomGopPicParam));
+    *gopPicLambda = 0;
+
+    numParsed = sscanf(lineStr, "%c %d %d %lf %d %d %d", 
+        &sliceType, &gopPicParam->pocOffset, &gopPicParam->picQp, &lambda,
+        &gopPicParam->temporalId, &gopPicParam->refPocL0, &gopPicParam->refPocL1);
+
+#if FLOATING_POINT_LAMBDA == 0
+    lambda = (int)(lambda * 256); // * 2^10 
+#endif
+
+    if (sliceType=='I') {
+        gopPicParam->picType = PIC_TYPE_I;
+    }
+    else if (sliceType=='P') {
+        gopPicParam->picType = PIC_TYPE_P;
+        if (numParsed == 6)
+            gopPicParam->numRefPicL0 = 2;
+        else
+            gopPicParam->numRefPicL0 = 1;
+    }
+    else if (sliceType=='B') {
+        gopPicParam->picType = PIC_TYPE_B;
+    }
+    else {
+        return 0;
+    }
+    if (sliceType=='P' && numParsed != 6) {
+        return 0;
+    }
+    if (sliceType=='B' && numParsed != 7) {
+        return 0;
+    }
+    if (gopPicParam->temporalId < 0) {
+        return 0;
+    }
+
+    gopPicParam->picQp = gopPicParam->picQp + intraQp;
+
+    if (useDeriveLambdaWeight == 0) {
+        *gopPicLambda = (int)(lambda * LAMBDA_SCALE_FACTOR);
+    }
+    else {
+        *gopPicLambda = 0;
+    }
+    
+    return 1;
+}
+
+int parseRoiCtuModeParam(
+    char* lineStr,
+    VpuRect* roiRegion,
+    int* roiLevel,
+    int picX,
+    int picY
+    )
+{
+    int numParsed;
+
+    osal_memset(roiRegion, 0, sizeof(VpuRect));
+    *roiLevel = 0;
+
+    numParsed = sscanf(lineStr, "%d %d %d %d %d", 
+        &roiRegion->left, &roiRegion->right, &roiRegion->top, &roiRegion->bottom,
+        roiLevel);
+
+    if (numParsed != 5) {
+        return 0;
+    }
+    if (*roiLevel > MAX_ROI_LEVEL) {
+        return 0;
+    }
+    if (roiRegion->left < 0 || roiRegion->top < 0) {
+        return 0;
+    }
+    if (roiRegion->left > (Uint32)((picX + CTB_SIZE - 1) >> LOG2_CTB_SIZE) || \
+        roiRegion->top > (Uint32)((picY + CTB_SIZE - 1) >> LOG2_CTB_SIZE)) {
+        return 0;
+    }
+    if (roiRegion->right > (Uint32)((picX + CTB_SIZE - 1) >> LOG2_CTB_SIZE) || \
+        roiRegion->bottom > (Uint32)((picY + CTB_SIZE - 1) >> LOG2_CTB_SIZE)) {
+        return 0;
+    }
+    if (roiRegion->left > roiRegion->right) {
+        return 0;
+    }
+    if (roiRegion->top > roiRegion->bottom) {
+        return 0;
+    }
+
+    return 1;
+}
+
+int parseHevcCfgFile(
+    ENC_CFG *pEncCfg, 
+    char *FileName
+    )
+
+{
+    osal_file_t fp;
+    char sValue[256] = {0, };
+    char tempStr[256] = {0, };
+    int iValue = 0, ret = 0, i = 0;
+    int intra8=0, intra16=0, intra32=0, frameSkip=0, dynamicMergeEnable; // temp value
+    UNREFERENCED_PARAMETER(frameSkip);
+    
+    fp = osal_fopen(FileName, "r");
+    if (fp == NULL) {
+        VLOG(ERR, "file open err : %s, errno(%d)", FileName, errno);
+        return ret;
+    }
+
+    if (HEVC_GetStringValue(fp, hevcCfgInfo[BITSTREAM_FILE].name, sValue) != 0)
+        strcpy(pEncCfg->BitStreamFileName, sValue);
+
+    if (HEVC_GetStringValue(fp, hevcCfgInfo[INPUT_FILE].name, sValue) == 0)
+        goto __end_parse;
+    else
+        strcpy(pEncCfg->SrcFileName, sValue);
+
+    if (HEVC_GetValue(fp, SOURCE_WIDTH, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.picX = iValue;
+    if (HEVC_GetValue(fp, SOURCE_HEIGHT, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.picY = iValue;
+    if (HEVC_GetValue(fp, FRAMES_TO_BE_ENCODED, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->NumFrame = iValue;
+    if (HEVC_GetValue(fp, INPUT_BIT_DEPTH, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->SrcBitDepth = iValue; // BitDepth == 8 ? HEVC_PROFILE_MAIN : HEVC_PROFILE_MAIN10
+
+    if (HEVC_GetValue(fp, INTERNAL_BITDEPTH, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.internalBitDepth   = iValue;
+
+    if (HEVC_GetValue(fp, LOSSLESS_CODING, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.losslessEnable = iValue;
+    if (HEVC_GetValue(fp, CONSTRAINED_INTRA_PRED, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.constIntraPredFlag = iValue;
+    if (HEVC_GetValue(fp, DECODING_REFRESH_TYPE, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.decodingRefreshType = iValue;
+
+    // RoiDetaQp
+    if (HEVC_GetValue(fp, ROI_DELTA_QP, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.ctuOptParam.roiDeltaQp = iValue;
+
+    // IntraQpOffset
+    if (HEVC_GetValue(fp, INTRA_QP_OFFSET, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.intraQpOffset = iValue;
+
+    // Initial Buf level x 8
+    if (HEVC_GetValue(fp, INIT_BUF_LEVELx8, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.initBufLevelx8 = iValue;
+
+    // BitAllocMode
+    if (HEVC_GetValue(fp, BIT_ALLOC_MODE, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.bitAllocMode = iValue;
+
+    // FixedBitRatio 0 ~ 7
+    for (i=0; i<MAX_GOP_NUM; i++) {
+        sprintf(tempStr, "FixedBitRatio%d", i);
+        if (HEVC_GetStringValue(fp, tempStr, sValue) != 0) {
+            iValue = atoi(sValue);
+            if ( iValue >= hevcCfgInfo[FIXED_BIT_RATIO].min && iValue <= hevcCfgInfo[FIXED_BIT_RATIO].max )
+                pEncCfg->hevcCfg.fixedBitRatio[i] = iValue;
+            else
+                pEncCfg->hevcCfg.fixedBitRatio[i] = hevcCfgInfo[FIXED_BIT_RATIO].def;
+        }
+		else
+			pEncCfg->hevcCfg.fixedBitRatio[i] = hevcCfgInfo[FIXED_BIT_RATIO].def;
+
+    }
+
+    // IntraQp
+    if (HEVC_GetValue(fp, INTRA_QP, &iValue) == 0)
+        goto __end_parse;
+    else 
+        pEncCfg->hevcCfg.intraQP = iValue;
+
+    if (pEncCfg->hevcCfg.losslessEnable)
+        pEncCfg->hevcCfg.intraQP = 4;
+
+    if (HEVC_GetValue(fp, INTRA_PERIOD, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.intraPeriod = iValue;
+
+    if (HEVC_GetValue(fp, CONF_WIND_SIZE_TOP, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.confWinTop = iValue;
+
+    if (HEVC_GetValue(fp, CONF_WIND_SIZE_BOT, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.confWinBot = iValue;
+
+    if (HEVC_GetValue(fp, CONF_WIND_SIZE_RIGHT, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.confWinRight = iValue;
+
+    if (HEVC_GetValue(fp, CONF_WIND_SIZE_LEFT, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.confWinLeft = iValue;
+
+    if (HEVC_GetValue(fp, FRAME_RATE, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.frameRate = iValue;
+
+    if (HEVC_GetValue(fp, INDE_SLICE_MODE, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.independSliceMode = iValue;
+
+    if (HEVC_GetValue(fp, INDE_SLICE_ARG, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.independSliceModeArg = iValue;
+
+    if (HEVC_GetValue(fp, DE_SLICE_MODE, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.dependSliceMode = iValue;
+
+    if (HEVC_GetValue(fp, DE_SLICE_ARG, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.dependSliceModeArg = iValue;
+
+    if (HEVC_GetValue(fp, EN_INTRA_IN_INTER_SLICE, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.intraInInterSliceEnable = iValue;
+
+    if (HEVC_GetValue(fp, INTRA_CTU_REFRESH_MODE, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.intraRefreshMode = iValue;
+
+    if(pEncCfg->hevcCfg.intraInInterSliceEnable == 0) {
+        pEncCfg->hevcCfg.intraRefreshMode = 0;
+    }
+
+    if (HEVC_GetValue(fp, INTRA_CTU_REFRESH_ARG, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.intraRefreshArg = iValue;
+
+    if (HEVC_GetValue(fp, USE_PRESENT_ENC_TOOLS, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.useRecommendEncParam = iValue;
+
+    if (HEVC_GetValue(fp, SCALING_LIST, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.scalingListEnable = iValue;
+
+    if (HEVC_GetValue(fp, EN_CU_8X8, &iValue) == 0)
+        goto __end_parse;
+    else
+        intra8 = iValue;
+
+    if (HEVC_GetValue(fp, EN_CU_16X16, &iValue) == 0)
+        goto __end_parse;
+    else
+        intra16 = iValue;
+
+    if (HEVC_GetValue(fp, EN_CU_32X32, &iValue) == 0)
+        goto __end_parse;
+    else
+        intra32 = iValue;
+
+    intra8 =  intra16 = intra32 = 1; // force enable all cu mode. [CEZ-1865]
+    pEncCfg->hevcCfg.cuSizeMode = (intra8&0x01) | (intra16&0x01)<<1 | (intra32&0x01)<<2;
+
+    if (HEVC_GetValue(fp, EN_TEMPORAL_MVP, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.tmvpEnable = iValue;
+
+    if (HEVC_GetValue(fp, WAVE_FRONT_SYNCHRO, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.wppenable = iValue;
+
+    if (HEVC_GetValue(fp, MAX_NUM_MERGE, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.maxNumMerge = iValue;
+
+    if (HEVC_GetValue(fp, EN_DYN_MERGE, &iValue) == 0)
+        goto __end_parse;
+    else
+        dynamicMergeEnable = iValue;
+
+    pEncCfg->hevcCfg.dynamicMerge8x8Enable   = dynamicMergeEnable;  // [FIXME]
+    pEncCfg->hevcCfg.dynamicMerge16x16Enable = dynamicMergeEnable;  // [FIXME]
+    pEncCfg->hevcCfg.dynamicMerge32x32Enable = dynamicMergeEnable;  // [FIXME]
+
+    if (HEVC_GetValue(fp, EN_DBK, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.disableDeblk = !(iValue);
+
+    if (HEVC_GetValue(fp, LF_CROSS_SLICE_BOUNDARY_FLAG, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.lfCrossSliceBoundaryEnable = iValue;
+
+    if (HEVC_GetValue(fp, BETA_OFFSET_DIV2, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.betaOffsetDiv2 = iValue;
+
+    if (HEVC_GetValue(fp, TC_OFFSET_DIV2, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.tcOffsetDiv2 = iValue;
+
+    if (HEVC_GetValue(fp, INTRA_TRANS_SKIP, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.skipIntraTrans = iValue;
+
+    if (HEVC_GetValue(fp, EN_SAO, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.saoEnable = iValue;
+
+    if (HEVC_GetValue(fp, INTRA_NXN, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.intraNxNEnable = iValue;
+
+    if (HEVC_GetValue(fp, RATE_CONTROL, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->RcEnable = iValue;
+
+    if (HEVC_GetValue(fp, ENC_BITRATE, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->RcBitRate = iValue;
+
+    if (HEVC_GetValue(fp, TRANS_BITRATE, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.transRate = iValue;
+
+    if (HEVC_GetValue(fp, CU_LEVEL_RATE_CONTROL, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.cuLevelRCEnable = iValue;
+
+    if (HEVC_GetValue(fp, EN_HVS_QP, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.hvsQPEnable = iValue;
+
+    if (HEVC_GetValue(fp, HVS_QP_SCALE_DIV2, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.hvsQpScale = iValue;
+
+    pEncCfg->hevcCfg.hvsQpScaleEnable = (iValue > 0) ? 1: 0;
+    
+    if (HEVC_GetValue(fp, INITIAL_DELAY, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->RcInitDelay = iValue;
+
+    if (HEVC_GetValue(fp, MIN_QP, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.minQp = iValue;
+
+    if (HEVC_GetValue(fp, MAX_QP, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.maxQp = iValue;
+
+    if (HEVC_GetValue(fp, MAX_DELTA_QP, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.maxDeltaQp = iValue;
+
+    if (HEVC_GetValue(fp, GOP_SIZE, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.gopParam.customGopSize = iValue;
+
+    if (HEVC_GetValue(fp, DERIVE_LAMBDA_WEIGHT, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.gopParam.useDeriveLambdaWeight = iValue;
+
+    if (HEVC_GetValue(fp, ROI_ENABLE, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.ctuOptParam.roiEnable = iValue;
+
+    if (HEVC_GetValue(fp, GOP_PRESET, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.gopPresetIdx = iValue;
+    if (HEVC_GetValue(fp, EN_TEMPORAL_LAYER_QP, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.gopParam.enTemporalLayerQp = iValue;
+    if (HEVC_GetValue(fp, TID_0_QP, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.gopParam.tidQp0 = iValue;
+    if (HEVC_GetValue(fp, TID_1_QP, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.gopParam.tidQp1 = iValue;
+    if (HEVC_GetValue(fp, TID_2_QP, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.gopParam.tidQp2 = iValue;
+    if (HEVC_GetValue(fp, TID_0_PERIOD, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.gopParam.tidPeriod0 = iValue;
+    if (HEVC_GetValue(fp, FRAME_SKIP, &iValue) == 0)
+        goto __end_parse;
+    else
+        frameSkip = iValue;
+
+    // VUI encoding
+    if (HEVC_GetValue(fp, VUI_PARAM_FLAG, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.vuiParam.vuiParamFlags = iValue;
+
+    if (HEVC_GetValue(fp, VUI_ASPECT_RATIO_IDC, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.vuiParam.vuiAspectRatioIdc = iValue;
+
+    if (HEVC_GetValue(fp, VUI_SAR_SIZE, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.vuiParam.vuiSarSize = iValue;
+
+    if (HEVC_GetValue(fp, VUI_OVERSCAN_APPROPRIATE, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.vuiParam.vuiOverScanAppropriate = iValue;
+
+    if (HEVC_GetValue(fp, VIDEO_SIGNAL, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.vuiParam.videoSignal = iValue;
+
+    if (HEVC_GetValue(fp, VUI_CHROMA_SAMPLE_LOC, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.vuiParam.vuiChromaSampleLoc = iValue;
+
+    if (HEVC_GetValue(fp, VUI_DISP_WIN_LEFT_RIGHT, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.vuiParam.vuiDispWinLeftRight = iValue;
+
+    if (HEVC_GetValue(fp, VUI_DISP_WIN_TOP_BOTTOM, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.vuiParam.vuiDispWinTopBottom = iValue;
+
+    if (HEVC_GetValue(fp, NUM_UNITS_IN_TICK, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.numUnitsInTick = iValue;
+
+    if (HEVC_GetValue(fp, TIME_SCALE, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.timeScale = iValue;
+
+    if (HEVC_GetValue(fp, NUM_TICKS_POC_DIFF_ONE, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.numTicksPocDiffOne = iValue;
+
+    if (HEVC_GetValue(fp, ENC_AUD, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.encAUD = iValue;
+
+    if (HEVC_GetValue(fp, ENC_EOS, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.encEOS = iValue;
+
+    if (HEVC_GetValue(fp, ENC_EOB, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.encEOB = iValue;
+
+    if (HEVC_GetValue(fp, CB_QP_OFFSET, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.chromaCbQpOffset = iValue;
+
+    if (HEVC_GetValue(fp, CR_QP_OFFSET, &iValue) == 0)
+            goto __end_parse;
+    else
+        pEncCfg->hevcCfg.chromaCrQpOffset = iValue;
+
+    if (HEVC_GetValue(fp, RC_INIT_QP, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.initialRcQp = iValue;
+
+    if (HEVC_GetValue(fp, EN_NR_Y, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.nrYEnable = iValue;
+
+    if (HEVC_GetValue(fp, EN_NR_CB, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.nrCbEnable = iValue;
+
+    if (HEVC_GetValue(fp, EN_NR_CR, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.nrCrEnable = iValue;
+
+    if (HEVC_GetValue(fp, EN_NOISE_EST, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.nrNoiseEstEnable = iValue;
+
+    if (HEVC_GetValue(fp, NOISE_SIGMA_Y, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.nrNoiseSigmaY = iValue;
+
+    if (HEVC_GetValue(fp, NOISE_SIGMA_CB, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.nrNoiseSigmaCb = iValue;
+
+    if (HEVC_GetValue(fp, NOISE_SIGMA_CR, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.nrNoiseSigmaCr = iValue;
+
+    if (HEVC_GetValue(fp, INTRA_NOISE_WEIGHT_Y, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.nrIntraWeightY = iValue;
+
+    if (HEVC_GetValue(fp, INTRA_NOISE_WEIGHT_CB, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.nrIntraWeightCb= iValue;
+
+    if (HEVC_GetValue(fp, INTRA_NOISE_WEIGHT_CR, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.nrIntraWeightCr = iValue;
+
+    if (HEVC_GetValue(fp, INTER_NOISE_WEIGHT_Y, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.nrInterWeightY = iValue;
+
+    if (HEVC_GetValue(fp, INTER_NOISE_WEIGHT_CB, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.nrInterWeightCb = iValue;
+
+    if (HEVC_GetValue(fp, INTER_NOISE_WEIGHT_CR, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.nrInterWeightCr = iValue;
+
+    if (HEVC_GetValue(fp, INTRA_MIN_QP, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.intraMinQp = iValue;
+
+    if (HEVC_GetValue(fp, INTRA_MAX_QP, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.intraMaxQp = iValue;
+
+    if (HEVC_GetValue(fp, USE_LONGTERM_PRRIOD, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.useAsLongtermPeriod = iValue;
+
+    if (HEVC_GetValue(fp, REF_LONGTERM_PERIOD, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.refLongtermPeriod = iValue;
+
+
+    if (HEVC_GetValue(fp, EN_CTU_QP, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.ctuOptParam.ctuQpEnable = iValue;
+
+
+
+    if (HEVC_GetValue(fp, EN_VUI_DATA, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.vuiDataEnable = iValue;
+
+    if (HEVC_GetValue(fp, VUI_DATA_SIZE, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.vuiDataSize = iValue;
+
+    if (HEVC_GetValue(fp, EN_HRD_IN_VPS, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.hrdInVPS = iValue;
+
+    if (HEVC_GetValue(fp, EN_HRD_IN_VUI, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.hrdInVUI = iValue;
+
+    if (HEVC_GetValue(fp, HRD_DATA_SIZE, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.hrdDataSize = iValue;
+
+    if (HEVC_GetValue(fp, EN_PREFIX_SEI_DATA, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.prefixSeiEnable = iValue;
+
+    if (HEVC_GetValue(fp, PREFIX_SEI_DATA_SIZE, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.prefixSeiDataSize = iValue;
+
+    if (HEVC_GetValue(fp, PREFIX_SEI_TIMING_FLAG, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.prefixSeiTimingFlag = iValue;
+
+    if (HEVC_GetValue(fp, EN_SUFFIX_SEI_DATA, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.suffixSeiEnable = iValue;
+
+    if (HEVC_GetValue(fp, SUFFIX_SEI_DATA_SIZE, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.suffixSeiDataSize = iValue;
+
+    if (HEVC_GetValue(fp, SUFFIX_SEI_TIMING_FLAG, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.suffixSeiTimingFlag = iValue;
+
+    if (HEVC_GetValue(fp, EN_FORCED_IDR_HEADER, &iValue) == 0)
+        goto __end_parse;
+    else
+        pEncCfg->hevcCfg.forcedIdrHeaderEnable = iValue;
+
+
+    //GOP
+    if (pEncCfg->hevcCfg.intraPeriod == 1) {
+        pEncCfg->hevcCfg.gopParam.picParam[0].picType = PIC_TYPE_I;
+        pEncCfg->hevcCfg.gopParam.picParam[0].picQp = pEncCfg->hevcCfg.intraQP;
+        if (pEncCfg->hevcCfg.gopParam.customGopSize > 1) {
+            VLOG(ERR, "CFG file error : gop size should be smaller than 2 for all intra case\n");
+            goto __end_parse;
+        }
+    }
+    else {
+        for (i = 0; pEncCfg->hevcCfg.gopPresetIdx == PRESET_IDX_CUSTOM_GOP && i < pEncCfg->hevcCfg.gopParam.customGopSize; i++) {
+
+            sprintf(tempStr, "Frame%d", i+1);
+            if (HEVC_GetStringValue(fp, tempStr, sValue) == 0) {
+                VLOG(ERR, "CFG file error : %s value is not available. \n", tempStr);
+                goto __end_parse;
+            }
+
+            if ( HEVC_SetGOPInfo(sValue, &pEncCfg->hevcCfg.gopParam.picParam[i], 
+                &pEncCfg->hevcCfg.gopParam.gopPicLambda[i], pEncCfg->hevcCfg.gopParam.useDeriveLambdaWeight, 
+                pEncCfg->hevcCfg.intraQP) == 0) {
+                    VLOG(ERR, "CFG file error : %s value is not available. \n", tempStr);
+                    goto __end_parse;
+            }
+
+#if TEMP_SCALABLE_RC
+            if ( (pEncCfg->hevcCfg.gopParam.picParam[i].temporalId + 1) > MAX_NUM_TEMPORAL_LAYER) {
+                VLOG(ERR, "CFG file error : %s MaxTempLayer %d exceeds MAX_TEMP_LAYER(7). \n", tempStr, pEncCfg->hevcCfg.gopParam.picParam[i].temporalId + 1);
+                goto __end_parse;
+            }
+#endif
+        }
+    }
+
+    //ROI
+    if (pEncCfg->hevcCfg.ctuOptParam.roiEnable) {
+        sprintf(tempStr, "RoiFile");
+        if (HEVC_GetStringValue(fp, tempStr, sValue) != 0) {
+            sscanf(sValue, "%s\n", pEncCfg->hevcCfg.roiFileName);
+        }
+    }
+
+
+
+    if (pEncCfg->hevcCfg.ctuOptParam.ctuQpEnable) {
+        sprintf(tempStr, "CtuQpFile");
+        if (HEVC_GetStringValue(fp, tempStr, sValue) != 0) {
+            sscanf(sValue, "%s\n", pEncCfg->hevcCfg.ctuQpFileName);
+        }
+    }
+
+    if (pEncCfg->hevcCfg.prefixSeiEnable) {
+        sprintf(tempStr, "PrefixSeiDataFile");
+        if (HEVC_GetStringValue(fp, tempStr, sValue) != 0) {
+            sscanf(sValue, "%s\n", pEncCfg->hevcCfg.prefixSeiDataFileName);
+        }
+    }
+
+    if (pEncCfg->hevcCfg.suffixSeiEnable) {
+        sprintf(tempStr, "SuffixSeiDataFile");
+        if (HEVC_GetStringValue(fp, tempStr, sValue) != 0) {
+            sscanf(sValue, "%s\n", pEncCfg->hevcCfg.suffixSeiDataFileName);
+        }
+    }
+
+    if (pEncCfg->hevcCfg.hrdInVPS || pEncCfg->hevcCfg.hrdInVUI) {
+        sprintf(tempStr, "RbspHrdFile");
+        if (HEVC_GetStringValue(fp, tempStr, sValue) != 0) {
+            sscanf(sValue, "%s\n", pEncCfg->hevcCfg.hrdDataFileName);
+        }
+    }
+
+    if (pEncCfg->hevcCfg.vuiDataEnable) {
+        sprintf(tempStr, "RbspVuiFile");
+        if (HEVC_GetStringValue(fp, tempStr, sValue) != 0) {
+            sscanf(sValue, "%s\n", pEncCfg->hevcCfg.vuiDataFileName);
+        }
+    }
+
+    if (pEncCfg->hevcCfg.losslessEnable) {
+        pEncCfg->hevcCfg.disableDeblk = 1;
+        pEncCfg->hevcCfg.saoEnable = 0;
+        pEncCfg->RcEnable = 0;
+    }
+
+
+
+    ret = 1; /* Success */
+
+__end_parse:
+    osal_fclose(fp);
+    return ret;
+}
+
+ 

+ 17 - 0
wave420l/code/sample/helper/misc/cnm_fpga.c

@@ -0,0 +1,17 @@
+//--=========================================================================--
+//  This file is a part of VPU Reference API project
+//-----------------------------------------------------------------------------
+//
+//       This confidential and proprietary software may be used only
+//     as authorized by a licensing agreement from Chips&Media Inc.
+//     In the event of publication, the following notice is applicable:
+//
+//            (C) COPYRIGHT CHIPS&MEDIA INC.
+//                      ALL RIGHTS RESERVED
+//
+//       The entire notice above must be reproduced on all authorized
+//       copies.
+//
+//--=========================================================================--
+
+ 

+ 2002 - 0
wave420l/code/sample/helper/misc/cnm_video_helper.c

@@ -0,0 +1,2002 @@
+//--=========================================================================--
+//  This file is a part of QC Tool project
+//-----------------------------------------------------------------------------
+//
+//       This confidential and proprietary software may be used only
+//     as authorized by a licensing agreement from Chips&Media Inc.
+//     In the event of publication, the following notice is applicable:
+//
+//            (C) COPYRIGHT 2004 - 2011   CHIPS&MEDIA INC.
+//                      ALL RIGHTS RESERVED
+//
+//       The entire notice above must be reproduced on all authorized
+//       copies.
+//
+//--=========================================================================--
+
+#include "main_helper.h"
+#include <libavformat/avformat.h>
+#ifdef SUPPORT_ENCODE_CUSTOM_HEADER
+#include "header_struct.h"
+#include "pbu.h"
+#endif
+
+// include in the ffmpeg header
+typedef struct {
+    CodStd      codStd;
+    Uint32      mp4Class;
+    Uint32      codecId;
+    Uint32      fourcc;
+} CodStdTab;
+
+#ifndef MKTAG
+#define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24))
+#endif
+
+static const CodStdTab codstd_tab[] = {
+    { STD_AVC,          0, AV_CODEC_ID_H264,            MKTAG('H', '2', '6', '4') },
+    { STD_AVC,          0, AV_CODEC_ID_H264,            MKTAG('X', '2', '6', '4') },
+    { STD_AVC,          0, AV_CODEC_ID_H264,            MKTAG('A', 'V', 'C', '1') },
+    { STD_AVC,          0, AV_CODEC_ID_H264,            MKTAG('V', 'S', 'S', 'H') },
+    { STD_H263,         0, AV_CODEC_ID_H263,            MKTAG('H', '2', '6', '3') },
+    { STD_H263,         0, AV_CODEC_ID_H263,            MKTAG('X', '2', '6', '3') },
+    { STD_H263,         0, AV_CODEC_ID_H263,            MKTAG('T', '2', '6', '3') },
+    { STD_H263,         0, AV_CODEC_ID_H263,            MKTAG('L', '2', '6', '3') },
+    { STD_H263,         0, AV_CODEC_ID_H263,            MKTAG('V', 'X', '1', 'K') },
+    { STD_H263,         0, AV_CODEC_ID_H263,            MKTAG('Z', 'y', 'G', 'o') },
+    { STD_H263,         0, AV_CODEC_ID_H263,            MKTAG('H', '2', '6', '3') },
+    { STD_H263,         0, AV_CODEC_ID_H263,            MKTAG('I', '2', '6', '3') },    /* intel h263 */
+    { STD_H263,         0, AV_CODEC_ID_H263,            MKTAG('H', '2', '6', '1') },
+    { STD_H263,         0, AV_CODEC_ID_H263,            MKTAG('U', '2', '6', '3') },
+    { STD_H263,         0, AV_CODEC_ID_H263,            MKTAG('V', 'I', 'V', '1') },
+    { STD_MPEG4,        0, AV_CODEC_ID_MPEG4,           MKTAG('F', 'M', 'P', '4') },
+    { STD_MPEG4,        5, AV_CODEC_ID_MPEG4,           MKTAG('D', 'I', 'V', 'X') },    // DivX 4
+    { STD_MPEG4,        1, AV_CODEC_ID_MPEG4,           MKTAG('D', 'X', '5', '0') },
+    { STD_MPEG4,        2, AV_CODEC_ID_MPEG4,           MKTAG('X', 'V', 'I', 'D') },
+    { STD_MPEG4,        0, AV_CODEC_ID_MPEG4,           MKTAG('M', 'P', '4', 'S') },
+    { STD_MPEG4,        0, AV_CODEC_ID_MPEG4,           MKTAG('M', '4', 'S', '2') },    //MPEG-4 version 2 simple profile
+    { STD_MPEG4,        0, AV_CODEC_ID_MPEG4,           MKTAG( 4 ,  0 ,  0 ,  0 ) },    /* some broken avi use this */
+    { STD_MPEG4,        0, AV_CODEC_ID_MPEG4,           MKTAG('D', 'I', 'V', '1') },
+    { STD_MPEG4,        0, AV_CODEC_ID_MPEG4,           MKTAG('B', 'L', 'Z', '0') },
+    { STD_MPEG4,        0, AV_CODEC_ID_MPEG4,           MKTAG('M', 'P', '4', 'V') },
+    { STD_MPEG4,        0, AV_CODEC_ID_MPEG4,           MKTAG('U', 'M', 'P', '4') },
+    { STD_MPEG4,        0, AV_CODEC_ID_MPEG4,           MKTAG('W', 'V', '1', 'F') },
+    { STD_MPEG4,        0, AV_CODEC_ID_MPEG4,           MKTAG('S', 'E', 'D', 'G') },
+    { STD_MPEG4,        0, AV_CODEC_ID_MPEG4,           MKTAG('R', 'M', 'P', '4') },
+    { STD_MPEG4,        0, AV_CODEC_ID_MPEG4,           MKTAG('3', 'I', 'V', '2') },
+    { STD_MPEG4,        0, AV_CODEC_ID_MPEG4,           MKTAG('F', 'F', 'D', 'S') },
+    { STD_MPEG4,        0, AV_CODEC_ID_MPEG4,           MKTAG('F', 'V', 'F', 'W') },
+    { STD_MPEG4,        0, AV_CODEC_ID_MPEG4,           MKTAG('D', 'C', 'O', 'D') },
+    { STD_MPEG4,        0, AV_CODEC_ID_MPEG4,           MKTAG('M', 'V', 'X', 'M') },
+    { STD_MPEG4,        0, AV_CODEC_ID_MPEG4,           MKTAG('P', 'M', '4', 'V') },
+    { STD_MPEG4,        0, AV_CODEC_ID_MPEG4,           MKTAG('S', 'M', 'P', '4') },
+    { STD_MPEG4,        0, AV_CODEC_ID_MPEG4,           MKTAG('D', 'X', 'G', 'M') },
+    { STD_MPEG4,        0, AV_CODEC_ID_MPEG4,           MKTAG('V', 'I', 'D', 'M') },
+    { STD_MPEG4,        0, AV_CODEC_ID_MPEG4,           MKTAG('M', '4', 'T', '3') },
+    { STD_MPEG4,        0, AV_CODEC_ID_MPEG4,           MKTAG('G', 'E', 'O', 'X') },
+    { STD_MPEG4,        0, AV_CODEC_ID_MPEG4,           MKTAG('H', 'D', 'X', '4') }, /* flipped video */
+    { STD_MPEG4,        0, AV_CODEC_ID_MPEG4,           MKTAG('D', 'M', 'K', '2') },
+    { STD_MPEG4,        0, AV_CODEC_ID_MPEG4,           MKTAG('D', 'I', 'G', 'I') },
+    { STD_MPEG4,        0, AV_CODEC_ID_MPEG4,           MKTAG('I', 'N', 'M', 'C') },
+    { STD_MPEG4,        0, AV_CODEC_ID_MPEG4,           MKTAG('E', 'P', 'H', 'V') }, /* Ephv MPEG-4 */
+    { STD_MPEG4,        0, AV_CODEC_ID_MPEG4,           MKTAG('E', 'M', '4', 'A') },
+    { STD_MPEG4,        0, AV_CODEC_ID_MPEG4,           MKTAG('M', '4', 'C', 'C') }, /* Divio MPEG-4 */
+    { STD_MPEG4,        0, AV_CODEC_ID_MPEG4,           MKTAG('S', 'N', '4', '0') },
+    { STD_MPEG4,        0, AV_CODEC_ID_MPEG4,           MKTAG('V', 'S', 'P', 'X') },
+    { STD_MPEG4,        0, AV_CODEC_ID_MPEG4,           MKTAG('U', 'L', 'D', 'X') },
+    { STD_MPEG4,        0, AV_CODEC_ID_MPEG4,           MKTAG('G', 'E', 'O', 'V') },
+    { STD_MPEG4,        0, AV_CODEC_ID_MPEG4,           MKTAG('S', 'I', 'P', 'P') }, /* Samsung SHR-6040 */
+    { STD_DIV3,         0, AV_CODEC_ID_MSMPEG4V3,       MKTAG('D', 'I', 'V', '3') }, /* default signature when using MSMPEG4 */
+    { STD_DIV3,         0, AV_CODEC_ID_MSMPEG4V3,       MKTAG('M', 'P', '4', '3') },
+    { STD_DIV3,         0, AV_CODEC_ID_MSMPEG4V3,       MKTAG('M', 'P', 'G', '3') },
+    { STD_MPEG4,        1, AV_CODEC_ID_MSMPEG4V3,       MKTAG('D', 'I', 'V', '5') },
+    { STD_MPEG4,        1, AV_CODEC_ID_MSMPEG4V3,       MKTAG('D', 'I', 'V', '6') },
+    { STD_MPEG4,        5, AV_CODEC_ID_MSMPEG4V3,       MKTAG('D', 'I', 'V', '4') },
+    { STD_DIV3,         0, AV_CODEC_ID_MSMPEG4V3,       MKTAG('D', 'V', 'X', '3') },
+    { STD_DIV3,         0, AV_CODEC_ID_MSMPEG4V3,       MKTAG('A', 'P', '4', '1') },    //Another hacked version of Microsoft's MP43 codec. 
+    { STD_MPEG4,        0, AV_CODEC_ID_MSMPEG4V3,       MKTAG('C', 'O', 'L', '1') },
+    { STD_MPEG4,        0, AV_CODEC_ID_MSMPEG4V3,       MKTAG('C', 'O', 'L', '0') },    // not support ms mpeg4 v1, 2    
+    { STD_MPEG4,      256, AV_CODEC_ID_FLV1,            MKTAG('F', 'L', 'V', '1') }, /* Sorenson spark */
+    { STD_VC1,          0, AV_CODEC_ID_WMV1,            MKTAG('W', 'M', 'V', '1') },
+    { STD_VC1,          0, AV_CODEC_ID_WMV2,            MKTAG('W', 'M', 'V', '2') },
+    { STD_MPEG2,        0, AV_CODEC_ID_MPEG1VIDEO,      MKTAG('M', 'P', 'G', '1') },
+    { STD_MPEG2,        0, AV_CODEC_ID_MPEG1VIDEO,      MKTAG('M', 'P', 'G', '2') },
+    { STD_MPEG2,        0, AV_CODEC_ID_MPEG2VIDEO,      MKTAG('M', 'P', 'G', '2') },
+    { STD_MPEG2,        0, AV_CODEC_ID_MPEG2VIDEO,      MKTAG('M', 'P', 'E', 'G') },
+    { STD_MPEG2,        0, AV_CODEC_ID_MPEG1VIDEO,      MKTAG('M', 'P', '2', 'V') },
+    { STD_MPEG2,        0, AV_CODEC_ID_MPEG1VIDEO,      MKTAG('P', 'I', 'M', '1') },
+    { STD_MPEG2,        0, AV_CODEC_ID_MPEG2VIDEO,      MKTAG('P', 'I', 'M', '2') },
+    { STD_MPEG2,        0, AV_CODEC_ID_MPEG1VIDEO,      MKTAG('V', 'C', 'R', '2') },
+    { STD_MPEG2,        0, AV_CODEC_ID_MPEG1VIDEO,      MKTAG( 1 ,  0 ,  0 ,  16) },
+    { STD_MPEG2,        0, AV_CODEC_ID_MPEG2VIDEO,      MKTAG( 2 ,  0 ,  0 ,  16) },
+    { STD_MPEG4,        0, AV_CODEC_ID_MPEG4,           MKTAG( 4 ,  0 ,  0 ,  16) },
+    { STD_MPEG2,        0, AV_CODEC_ID_MPEG2VIDEO,      MKTAG('D', 'V', 'R', ' ') },
+    { STD_MPEG2,        0, AV_CODEC_ID_MPEG2VIDEO,      MKTAG('M', 'M', 'E', 'S') },
+    { STD_MPEG2,        0, AV_CODEC_ID_MPEG2VIDEO,      MKTAG('L', 'M', 'P', '2') }, /* Lead MPEG2 in avi */
+    { STD_MPEG2,        0, AV_CODEC_ID_MPEG2VIDEO,      MKTAG('S', 'L', 'I', 'F') },
+    { STD_MPEG2,        0, AV_CODEC_ID_MPEG2VIDEO,      MKTAG('E', 'M', '2', 'V') },
+    { STD_VC1,          0, AV_CODEC_ID_WMV3,            MKTAG('W', 'M', 'V', '3') },
+    { STD_VC1,          0, AV_CODEC_ID_VC1,             MKTAG('W', 'V', 'C', '1') },
+    { STD_VC1,          0, AV_CODEC_ID_VC1,             MKTAG('W', 'M', 'V', 'A') },
+
+    { STD_RV,           0, AV_CODEC_ID_RV30,            MKTAG('R','V','3','0') },
+    { STD_RV,           0, AV_CODEC_ID_RV40,            MKTAG('R','V','4','0') },
+
+    { STD_AVS,          0, AV_CODEC_ID_CAVS,            MKTAG('C','A','V','S') },
+    { STD_AVS,          0, AV_CODEC_ID_AVS,             MKTAG('A','V','S','2') },
+    { STD_VP3,          0, AV_CODEC_ID_VP3,             MKTAG('V', 'P', '3', '0') },
+    { STD_VP3,          0, AV_CODEC_ID_VP3,             MKTAG('V', 'P', '3', '1') },
+    { STD_THO,          0, AV_CODEC_ID_THEORA,          MKTAG('T', 'H', 'E', 'O') },
+    { STD_VP8,          0, AV_CODEC_ID_VP8,             MKTAG('V', 'P', '8', '0') },
+    { STD_VP9,          0, AV_CODEC_ID_VP9,             MKTAG('V', 'P', '9', '0') },
+    //  { STD_VP6,              0, AV_CODEC_ID_VP6,             MKTAG('V', 'P', '6', '0') },
+    //  { STD_VP6,              0, AV_CODEC_ID_VP6,             MKTAG('V', 'P', '6', '1') },
+    //  { STD_VP6,              0, AV_CODEC_ID_VP6,             MKTAG('V', 'P', '6', '2') },
+    //  { STD_VP6,              0, AV_CODEC_ID_VP6F,            MKTAG('V', 'P', '6', 'F') },
+    //  { STD_VP6,              0, AV_CODEC_ID_VP6F,            MKTAG('F', 'L', 'V', '4') },
+    { STD_HEVC,         0, AV_CODEC_ID_HEVC,            MKTAG('H', 'E', 'V', 'C') },
+    { STD_HEVC,         0, AV_CODEC_ID_HEVC,            MKTAG('H', 'E', 'V', '1') },
+    { STD_HEVC,         0, AV_CODEC_ID_HEVC,            MKTAG('H', 'V', 'C', '1') },
+    { STD_HEVC,         0, AV_CODEC_ID_HEVC,            MKTAG('h', 'e', 'v', 'c') },
+    { STD_HEVC,         0, AV_CODEC_ID_HEVC,            MKTAG('h', 'e', 'v', '1') },
+    { STD_HEVC,         0, AV_CODEC_ID_HEVC,            MKTAG('h', 'v', 'c', '1') }
+};
+
+
+Int32 ConvFOURCCToMp4Class(
+    Int32   fourcc
+    )
+{
+    Int32   i;
+    Int32   mp4Class = -1;
+    unsigned char str[5];
+
+    str[0] = toupper((Int32)fourcc);
+    str[1] = toupper((Int32)(fourcc>>8));
+    str[2] = toupper((Int32)(fourcc>>16));
+    str[3] = toupper((Int32)(fourcc>>24));
+    str[4] = '\0';
+
+    for(i=0; i<sizeof(codstd_tab)/sizeof(codstd_tab[0]); i++) {
+        if (codstd_tab[i].fourcc == (Int32)MKTAG(str[0], str[1], str[2], str[3]) ) {
+            mp4Class = codstd_tab[i].mp4Class;
+            break;
+        }
+    }
+
+    return mp4Class;
+}
+
+Int32 ConvFOURCCToCodStd(
+    Uint32   fourcc
+    )
+{
+    Int32   codStd = -1;
+    Int32   i;
+
+    char str[5];
+
+    str[0] = toupper((Int32)fourcc);
+    str[1] = toupper((Int32)(fourcc>>8));
+    str[2] = toupper((Int32)(fourcc>>16));
+    str[3] = toupper((Int32)(fourcc>>24));
+    str[4] = '\0';
+
+    for(i=0; i<sizeof(codstd_tab)/sizeof(codstd_tab[0]); i++) {
+        if (codstd_tab[i].fourcc == (Uint32)MKTAG(str[0], str[1], str[2], str[3])) {
+            codStd = codstd_tab[i].codStd;
+            break;
+        }
+    }
+
+    return codStd;
+}
+
+Int32 ConvCodecIdToMp4Class(
+    Uint32   codecId
+    )
+{
+    Int32   mp4Class = -1;
+    Int32   i;
+
+    for(i=0; i<sizeof(codstd_tab)/sizeof(codstd_tab[0]); i++) {
+        if (codstd_tab[i].codecId == codecId) {
+            mp4Class = codstd_tab[i].mp4Class;
+            break;
+        }
+    }
+
+    return mp4Class;
+}
+
+Int32 ConvCodecIdToCodStd(
+    Int32   codecId
+    )
+{
+    Int32   codStd = -1;
+    Int32   i;
+
+    for(i=0; i<sizeof(codstd_tab)/sizeof(codstd_tab[0]); i++) {
+        if (codstd_tab[i].codecId == codecId) {
+            codStd = codstd_tab[i].codStd;
+            break;
+        }
+    }
+
+    return codStd;
+}
+
+Int32 ConvCodecIdToFourcc(
+    Int32   codecId
+    )
+{
+    Int32   fourcc = 0;
+    Int32   i;
+
+    for(i=0; i<sizeof(codstd_tab)/sizeof(codstd_tab[0]); i++) {
+        if (codstd_tab[i].codecId == codecId) {
+            fourcc = codstd_tab[i].fourcc;
+            break;
+        }
+    }
+    return fourcc;
+}
+
+
+//////////////////// DRAM Read/Write helper Function ////////////////////////////
+BOOL LoadYuvImageBurstFormat(
+    Uint32      coreIdx, 
+    Uint8*      src, 
+    size_t      picWidth, 
+    size_t      picHeight,
+    FrameBuffer* fb,
+    BOOL        convertCbcrIntl
+    )
+{
+    Int32               y, nY, nCb, nCr;
+    Int32               addr;
+    size_t              lumaSize, chromaSize=0, chromaStride, chromaWidth=0;
+    Uint8*              puc;
+    size_t              stride      = fb->stride;
+    EndianMode          endian      = (EndianMode)fb->endian;
+    FrameBufferFormat   format      = fb->format;
+    BOOL                interLeave  = fb->cbcrInterleave;
+    int                 twice       = 1 << interLeave;
+
+    switch (format) {
+    case FORMAT_420:
+        nY = picHeight;
+        nCb = nCr = picHeight / 2;
+        chromaSize = picWidth * picHeight / 4;
+        chromaStride = stride / 2;
+        chromaWidth = picWidth / 2;
+        break;
+    case FORMAT_224:
+        nY = picHeight;
+        nCb = nCr = picHeight / 2;
+        chromaSize = picWidth * picHeight / 2;
+        chromaStride = stride;
+        chromaWidth = picWidth;
+        break;
+    case FORMAT_422:
+        nY = picHeight;
+        nCb = nCr = picHeight;
+        chromaSize = picWidth * picHeight / 2;
+        chromaStride = stride / 2;
+        chromaWidth = picWidth / 2;
+        break;
+    case FORMAT_444:
+        nY = picHeight;
+        nCb = nCr = picHeight;
+        chromaSize = picWidth * picHeight;
+        chromaStride = stride;
+        chromaWidth = picWidth;
+        break;
+    case FORMAT_400:
+        nY = picHeight;
+        nCb = nCr = 0;
+        chromaSize = picWidth * picHeight / 4;
+        chromaStride = stride / 2;
+        chromaWidth = picWidth / 2;
+        break;
+    case FORMAT_YUYV:
+    case FORMAT_YVYU:
+    case FORMAT_UYVY:
+    case FORMAT_VYUY:
+    case FORMAT_YUYV_P10_16BIT_MSB:
+    case FORMAT_YUYV_P10_16BIT_LSB:
+    case FORMAT_YUYV_P10_32BIT_MSB:
+    case FORMAT_YUYV_P10_32BIT_LSB:
+    case FORMAT_YVYU_P10_16BIT_MSB:
+    case FORMAT_YVYU_P10_16BIT_LSB:
+    case FORMAT_YVYU_P10_32BIT_MSB:
+    case FORMAT_YVYU_P10_32BIT_LSB:
+    case FORMAT_UYVY_P10_16BIT_MSB:
+    case FORMAT_UYVY_P10_16BIT_LSB:
+    case FORMAT_UYVY_P10_32BIT_MSB:
+    case FORMAT_UYVY_P10_32BIT_LSB:
+    case FORMAT_VYUY_P10_16BIT_MSB:
+    case FORMAT_VYUY_P10_16BIT_LSB:
+    case FORMAT_VYUY_P10_32BIT_MSB:
+    case FORMAT_VYUY_P10_32BIT_LSB:
+        nY = picHeight;
+        nCb = nCr = 0;
+        break;
+    case FORMAT_420_P10_16BIT_LSB:
+    case FORMAT_420_P10_16BIT_MSB:
+        nY = picHeight;
+        nCb = nCr = picHeight/2;
+        chromaSize = picWidth * picHeight/2;
+        chromaStride = stride / 2;
+        chromaWidth = picWidth;
+        picWidth *= 2;
+        break;
+    case FORMAT_420_P10_32BIT_LSB:
+    case FORMAT_420_P10_32BIT_MSB:
+        nY = picHeight;
+        nCb = nCr = picHeight/2;
+        picWidth = VPU_ALIGN32(picWidth);
+        chromaWidth = ((VPU_ALIGN16(picWidth/2*twice)+2)/3*4);
+        chromaStride = VPU_ALIGN16(stride/2)*twice;
+        if ( interLeave == 1)
+            chromaStride = stride;
+        chromaSize = chromaWidth * picHeight/2;
+        picWidth   = ((VPU_ALIGN16(picWidth)+2)/3)*4;
+        break;
+    default:
+        nY = picHeight;
+        nCb = nCr = picHeight / 2;
+        chromaSize = picWidth * picHeight / 4;
+        chromaStride = stride / 2;
+        chromaWidth = picWidth / 2;
+        break;
+    }
+
+    puc = src;
+    addr = fb->bufY;
+    lumaSize = picWidth * picHeight;
+
+    if( picWidth == stride) { // for fast write
+        vdi_write_memory(coreIdx, addr, (Uint8 *)( puc ), lumaSize, endian);
+
+        if( format == FORMAT_400)
+            return FALSE;
+        if (format >= FORMAT_YUYV && format <= FORMAT_VYUY_P10_32BIT_LSB)
+            return FALSE;
+
+        if (interLeave == TRUE) {
+            UNREFERENCED_PARAMETER(convertCbcrIntl);
+            puc = src + lumaSize;
+            addr = fb->bufCb;
+            vdi_write_memory(coreIdx, addr, (Uint8 *)puc, chromaSize*2, endian);
+        }
+        else {
+            if ( chromaWidth == chromaStride )
+            {
+                puc = src + lumaSize;
+                addr = fb->bufCb;
+                vdi_write_memory(coreIdx, addr, (Uint8 *)puc, chromaSize, endian);
+
+                puc = src + lumaSize + chromaSize;
+                addr = fb->bufCr;
+                vdi_write_memory(coreIdx, addr, (Uint8 *)puc, chromaSize, endian);
+            }
+            else
+            {
+                puc = src + lumaSize;
+                addr = fb->bufCb;
+                for (y = 0; y < nCb; ++y) {
+                    vdi_write_memory(coreIdx, addr + chromaStride * y, (Uint8 *)(puc + y * chromaWidth), chromaWidth, endian);
+                }
+
+                puc = src + lumaSize + chromaSize;
+                addr = fb->bufCr;
+                for (y = 0; y < nCr; ++y) {
+                    vdi_write_memory(coreIdx, addr + chromaStride * y, (Uint8 *)(puc + y * chromaWidth), chromaWidth, endian);
+                }
+            }
+        }
+    }
+    else {
+        for (y = 0; y < nY; ++y) {
+            vdi_write_memory(coreIdx, addr + stride * y, (Uint8 *)(puc + y * picWidth), picWidth, endian);
+        }
+
+        if (format == FORMAT_400) {
+            return FALSE;
+        }
+        if (format >= FORMAT_YUYV && format <= FORMAT_VYUY_P10_32BIT_LSB) {
+            return FALSE;
+        }
+
+        if (interLeave == TRUE) {
+            UNREFERENCED_PARAMETER(convertCbcrIntl);
+            puc = src + lumaSize;
+            addr = fb->bufCb;
+            for (y = 0; y < nCb; ++y) {
+                vdi_write_memory(coreIdx, addr + stride * y, (Uint8 *)(puc + y * picWidth), picWidth, endian);
+            }
+        }
+        else {
+            puc = src + lumaSize;
+            addr = fb->bufCb;
+            for (y = 0; y < nCb; ++y) {
+                vdi_write_memory(coreIdx, addr + chromaStride * y, (Uint8 *)(puc + y * chromaWidth), chromaWidth, endian);
+            }
+
+            puc = src + lumaSize + chromaSize;
+            addr = fb->bufCr;
+            for (y = 0; y < nCr; ++y) {
+                vdi_write_memory(coreIdx, addr + chromaStride * y, (Uint8 *)(puc + y * chromaWidth), chromaWidth, endian);
+            }
+        }
+    }
+
+    return TRUE;
+}
+
+BOOL LoadTiledImageYuvBurst(
+    Uint32          coreIdx, 
+    BYTE*           pYuv, 
+    size_t          picWidth, 
+    size_t          picHeight, 
+    FrameBuffer*    fb, 
+    TiledMapConfig  mapCfg
+    )
+{   
+    BYTE *pSrc;
+    size_t              divX, divY;
+    size_t              pix_addr;
+    size_t              rrow, ccol;
+    size_t              offsetX,offsetY;
+    size_t              stride_c;
+    size_t              stride      = fb->stride;
+    EndianMode          endian      = (EndianMode)fb->endian;
+    FrameBufferFormat   format      = fb->format;
+    BOOL                interLeave  = fb->cbcrInterleave;
+    Int32               productId;
+    Int32               dramBusWidth = 8;
+
+    productId = VPU_GetProductId(coreIdx);
+    if (PRODUCT_ID_W_SERIES(productId)) {
+        dramBusWidth = 16;
+    }
+
+    offsetX = offsetY    = 0;
+
+    divX = format == FORMAT_420 || format == FORMAT_422 ? 2 : 1;
+    divY = format == FORMAT_420 || format == FORMAT_224 ? 2 : 1;
+
+    switch (format) {
+    case FORMAT_400:
+        stride_c = 0;
+        break;
+    case FORMAT_420:
+    case FORMAT_422:
+        stride_c = stride / 2;
+        break;
+    case FORMAT_224:
+    case FORMAT_444:
+        stride_c = stride;
+        break;
+    default:
+        stride_c = stride / 2;
+        break;
+    }
+
+    // Y
+    pSrc    = pYuv;
+
+    // no opt code
+    for (rrow=0; rrow <picHeight; rrow=rrow+1) 
+    {
+        for (ccol=0; ccol<picWidth; ccol=ccol+dramBusWidth)
+        {    
+            pix_addr = GetXY2AXIAddr(&mapCfg, 0/*luma*/, rrow +offsetY, ccol + offsetX, stride, fb);
+            vdi_write_memory(coreIdx, pix_addr, pSrc+rrow*picWidth+ccol, 8, endian);
+        }
+    }
+
+    if (format == FORMAT_400) {
+        return 1;
+    }
+
+    if (interLeave == FALSE) { 
+        // CB
+        pSrc = pYuv + picWidth*picHeight;
+
+        for (rrow=0; rrow <(picHeight/divY) ; rrow=rrow+1) {
+            for (ccol=0; ccol<(picWidth/divX); ccol=ccol+dramBusWidth) {
+                pix_addr = GetXY2AXIAddr(&mapCfg, 2, rrow + offsetY, ccol +offsetX, stride_c, fb);
+                vdi_write_memory(coreIdx, pix_addr, pSrc+rrow*picWidth/divX+ccol, 8, endian);
+            }
+        }
+        // CR
+
+        pSrc = pYuv + picWidth*picHeight+ (picWidth/divX)*(picHeight/divY);
+
+        for (rrow=0; rrow <picHeight/divY ; rrow=rrow+1) {
+            for (ccol=0; ccol<picWidth/divX; ccol=ccol+dramBusWidth) {
+                pix_addr = GetXY2AXIAddr(&mapCfg, 3, rrow  + offsetY ,ccol +offsetX, stride_c, fb);
+                vdi_write_memory(coreIdx, pix_addr, pSrc+rrow*picWidth/divX+ccol, 8, endian);
+            }
+        }
+    }
+    else {
+
+        BYTE * pTemp;
+        BYTE * srcAddrCb;
+        BYTE * srcAddrCr;
+
+        size_t  cbcr_x;
+
+        switch( format) {
+        case FORMAT_444 : 
+            cbcr_x = picWidth*2;
+            break; 
+        case FORMAT_420 : 
+            cbcr_x = picWidth  ; 
+            break;
+        case FORMAT_422 : 
+            cbcr_x = picWidth  ;
+            break;
+        case FORMAT_224 : 
+            cbcr_x = picWidth*2;
+            break;
+        default: 
+            cbcr_x = picWidth  ; 
+            break;
+        }
+
+        stride = stride_c * 2;
+
+        srcAddrCb = pYuv + picWidth*picHeight;
+        srcAddrCr = pYuv + picWidth*picHeight + picWidth/divX*picHeight/divY;
+
+
+        pTemp = (BYTE*)osal_malloc(sizeof(char)*8);
+        if (!pTemp) {
+            return FALSE;
+        }
+
+        for (rrow=0; rrow <picHeight/divY; rrow=rrow+1) {
+            for (ccol=0; ccol<cbcr_x ; ccol=ccol+dramBusWidth) {     
+
+                pTemp[0  ] = *srcAddrCb++;
+                pTemp[0+2] = *srcAddrCb++;
+                pTemp[0+4] = *srcAddrCb++;
+                pTemp[0+6] = *srcAddrCb++;
+                pTemp[0+1] = *srcAddrCr++;
+                pTemp[0+3] = *srcAddrCr++;
+                pTemp[0+5] = *srcAddrCr++;
+                pTemp[0+7] = *srcAddrCr++;
+
+                pix_addr = GetXY2AXIAddr(&mapCfg, 2, rrow + offsetY ,ccol + (offsetX*2), stride, fb);  
+                vdi_write_memory(coreIdx, pix_addr, (unsigned char *)pTemp, 8, endian);
+            }
+        }
+        osal_free(pTemp);
+    }
+
+    return TRUE;
+}
+
+
+static void SwapDword(unsigned char* data, int len)
+{
+    Uint32  temp;
+    Uint32* ptr = (Uint32*)data;
+    Int32   i, size = len/sizeof(Uint32);
+
+    for (i=0; i<size; i+=2) {
+        temp      = ptr[i];
+        ptr[i]   = ptr[i+1];
+        ptr[i+1] = temp;
+    }
+}
+
+static void SwapLword(unsigned char* data, int len)
+{
+    Uint64  temp;
+    Uint64* ptr = (Uint64*)data;
+    Int32   i, size = len/sizeof(Uint64);
+
+    for (i=0; i<size; i+=2) {
+        temp      = ptr[i];
+        ptr[i]   = ptr[i+1];
+        ptr[i+1] = temp;
+    }
+}
+
+static void SwapPixelOrder(
+    Uint8*      data
+    )
+{
+    Uint32*     temp;
+    Uint32      temp2[4]={0,};
+    Int32       i,j;
+
+    for (i=0, j=3 ; i < 16 ; i+=4, j--) {
+        temp = (Uint32*)(data+i);
+        temp2[j] =  (*temp & 0xffc00000)>>20;
+        temp2[j] |= (*temp & 0x003ff000);
+        temp2[j] |= (*temp & 0x00000ffc)<<20;
+    }
+
+    osal_memcpy(data, temp2, 16);
+
+//for matching with Ref-C
+    SwapDword(data, 16);
+    SwapLword(data, 16);
+}
+
+Uint32 StoreYuvImageBurstLinear(
+    Uint32      coreIdx, 
+    FrameBuffer *fbSrc, 
+    TiledMapConfig  mapCfg, 
+    Uint8       *pDst, 
+    VpuRect     cropRect, 
+    BOOL        enableCrop,
+    BOOL        isVP9
+    )
+{
+    Uint32          y, x;
+    Uint32          pix_addr, div_x, div_y, chroma_stride;
+    Uint8*          puc;
+    Uint8*          rowBufferY, *rowBufferCb, *rowBufferCr;
+    Uint32          stride      = fbSrc->stride;
+    Uint32          height      = fbSrc->height;
+    int             interLeave  = fbSrc->cbcrInterleave;
+    BOOL            nv21        = fbSrc->nv21;
+    EndianMode      endian      = (EndianMode)fbSrc->endian;
+    FrameBufferFormat format    = (FrameBufferFormat)fbSrc->format;
+    Uint32          width;
+    Uint32          dstWidth, dstHeight;
+    Uint32          offsetX, offsetY;
+    Uint32          dstChromaHeight;
+    Uint32          dstChromaWidth;
+    Uint32          chromaHeight;
+    Uint32          bpp=8;
+    Uint32          p10_32bit_interleave = 0;
+    Int32           productId;
+    Int32           dramBusWidth = 8;
+    Uint32          totSize = 0;
+    BOOL            copyLumaOnly = FALSE;
+
+    //Int32           addr;
+    Int32           baseY;
+    Int32           baseCb;
+    Int32           baseCr;
+    Uint8           *pY;
+    Uint8           *pCbTemp;
+    Uint8           *pCb;
+    Uint8           *pCr;
+
+    productId = VPU_GetProductId(coreIdx);
+    if (PRODUCT_ID_W_SERIES(productId)) {
+        dramBusWidth = 16;
+    }
+    switch (fbSrc->format) {
+    case FORMAT_420:
+    case FORMAT_420_P10_16BIT_LSB:
+    case FORMAT_420_P10_16BIT_MSB:
+    case FORMAT_420_P10_32BIT_LSB:
+    case FORMAT_420_P10_32BIT_MSB:
+    case FORMAT_422:
+    case FORMAT_422_P10_16BIT_LSB:
+    case FORMAT_422_P10_16BIT_MSB:
+    case FORMAT_422_P10_32BIT_LSB:
+    case FORMAT_422_P10_32BIT_MSB:
+        div_x = 2;
+        break;
+    default:
+        div_x = 1;
+    }
+
+    switch (fbSrc->format) {
+    case FORMAT_420:
+    case FORMAT_420_P10_16BIT_LSB:
+    case FORMAT_420_P10_16BIT_MSB:
+    case FORMAT_420_P10_32BIT_LSB:
+    case FORMAT_420_P10_32BIT_MSB:
+    case FORMAT_224:
+        div_y = 2;
+        break;
+    default:
+        div_y = 1;
+    }
+
+    //for matching with Ref-C
+    width     = (enableCrop == TRUE ? cropRect.right - cropRect.left : stride);
+    dstHeight = (enableCrop == TRUE ? cropRect.bottom - cropRect.top : height);
+    offsetX   = (enableCrop == TRUE ? cropRect.left : 0);
+    offsetY   = (enableCrop == TRUE ? cropRect.top  : 0);
+
+    switch (fbSrc->format) {
+    case FORMAT_400:
+        copyLumaOnly = TRUE;
+        break;
+    case FORMAT_YUYV:
+    case FORMAT_YVYU:
+    case FORMAT_UYVY:
+    case FORMAT_VYUY:
+        copyLumaOnly    = TRUE;
+        dstWidth        = width * 2;
+        dstChromaHeight = 0;
+        chromaHeight    = 0;
+        break;
+    case FORMAT_YUYV_P10_16BIT_LSB:
+    case FORMAT_YUYV_P10_16BIT_MSB:
+    case FORMAT_YVYU_P10_16BIT_LSB:
+    case FORMAT_YVYU_P10_16BIT_MSB:
+    case FORMAT_UYVY_P10_16BIT_LSB:
+    case FORMAT_UYVY_P10_16BIT_MSB:
+    case FORMAT_VYUY_P10_16BIT_LSB:
+    case FORMAT_VYUY_P10_16BIT_MSB:
+        copyLumaOnly    = TRUE;
+        dstWidth        = (width * 2)*2;
+        dstChromaHeight = 0;
+        chromaHeight    = 0;
+        break;
+    case FORMAT_YUYV_P10_32BIT_LSB:
+    case FORMAT_YUYV_P10_32BIT_MSB:
+    case FORMAT_YVYU_P10_32BIT_LSB:
+    case FORMAT_YVYU_P10_32BIT_MSB:
+    case FORMAT_UYVY_P10_32BIT_LSB:
+    case FORMAT_UYVY_P10_32BIT_MSB:
+    case FORMAT_VYUY_P10_32BIT_LSB:
+    case FORMAT_VYUY_P10_32BIT_MSB:
+        copyLumaOnly    = TRUE;
+        dstWidth        = ((width+2)/3*4)*2;
+        dstChromaHeight = 0;
+        chromaHeight    = 0;
+        break;
+    case FORMAT_422_P10_16BIT_LSB: 
+    case FORMAT_422_P10_16BIT_MSB:
+        dstWidth = width * 2;
+        bpp = 16;
+        dstChromaWidth  = dstWidth / div_x;
+        dstChromaHeight = dstHeight / div_y;
+        chromaHeight    = height / div_y;
+        chroma_stride   = (stride / div_x);
+        break;
+    case FORMAT_420_P10_16BIT_LSB: 
+    case FORMAT_420_P10_16BIT_MSB:
+        dstWidth = width * 2;
+        bpp = 16;
+        dstChromaWidth  = dstWidth / div_x;
+        dstChromaHeight = dstHeight / div_y;
+        chromaHeight    = height / div_y;
+        chroma_stride = (stride / div_x);
+        break;
+    case FORMAT_420_P10_32BIT_LSB:
+    case FORMAT_420_P10_32BIT_MSB:
+#ifdef DUMP_YUV_WHOLE_DATA
+        if (interLeave)
+        {
+            dstChromaWidth = ((VPU_ALIGN16(width/div_x))*2+11)/12*16;
+            dstChromaWidth = VPU_ALIGN16(dstChromaWidth);
+            dstChromaHeight = dstHeight / div_y;
+
+            stride = stride;
+            chroma_stride = stride;
+            dstWidth = (VPU_ALIGN16(width)+11)/12*16;
+
+            interLeave = 0;
+        }
+        else
+        {
+            dstChromaWidth = ((VPU_ALIGN16(width/div_x))+11)/12*16;
+            dstChromaWidth = VPU_ALIGN16(dstChromaWidth);
+            dstChromaHeight = dstHeight / div_y;
+            chroma_stride = dstChromaWidth;
+            stride    = (VPU_ALIGN16(stride)+11)/12*16;
+            dstWidth = (VPU_ALIGN16(dstWidth)+11)/12*16;
+        }
+        break;
+#else
+        if (interLeave) {
+            dstChromaWidth = ((VPU_ALIGN16(width*2/div_x))+11)/12*16;
+            dstChromaWidth = VPU_ALIGN16(dstChromaWidth);
+            if(isVP9 == TRUE) {
+                dstChromaWidth = VPU_ALIGN32(dstChromaWidth);
+            }
+            chroma_stride = stride;
+
+            dstChromaWidth = (width/div_x+2)/3*4;
+
+            dstChromaHeight = dstHeight / div_y;
+            chromaHeight    = height / div_y;
+
+            dstWidth = (width+2)/3*4;
+
+            interLeave = 0;
+            p10_32bit_interleave = 1;
+        }
+        else {
+            //dstChromaWidth = ((VPU_ALIGN16(width/div_x))+11)/12*16;
+//          dstChromaWidth = VPU_ALIGN16(dstChromaWidth);
+            //chroma_stride = dstChromaWidth;
+            chroma_stride = stride / 2;
+
+            dstChromaWidth = (width/2+2)/3*4;
+
+            dstChromaHeight = dstHeight / div_y;
+            chromaHeight    = height / div_y;
+
+            dstWidth = (width+2)/3*4;
+        }
+        break;
+#endif
+    default:
+        dstWidth = width;
+        dstChromaWidth  = width / div_x;
+        dstChromaHeight = dstHeight / div_y;
+        chromaHeight    = height / div_y;
+        chroma_stride   = (stride / div_x);
+        break;
+    }
+
+    puc         = pDst;
+
+    pY = (Uint8*)osal_malloc(stride * height);
+    pCbTemp = (Uint8*)osal_malloc(stride*4 * chromaHeight);
+    pCb = (Uint8*)osal_malloc(stride*4 * chromaHeight);
+    pCr = (Uint8*)osal_malloc(stride*2 * chromaHeight);
+    baseY = fbSrc->bufY;
+    baseCb = fbSrc->bufCb;
+    baseCr = fbSrc->bufCr;
+
+    vdi_read_memory(coreIdx, fbSrc->bufY, pY, stride * height, endian);
+
+    for (y=0 ; y<dstHeight ; y+=1) {
+        pix_addr = GetXY2AXIAddr(&mapCfg, 0, y+offsetY, 0, stride, fbSrc);
+        rowBufferY = pY + (pix_addr - baseY);
+        // CHECK POINT
+        for (x=0; x<stride ; x+=dramBusWidth) {  
+            if ( fbSrc->format == FORMAT_420_P10_32BIT_MSB )
+                SwapPixelOrder(rowBufferY+x);
+        }
+        // CHECK POINT
+        osal_memcpy(puc+y*dstWidth, rowBufferY+offsetX, dstWidth);
+        totSize += dstWidth;
+    }
+
+    if (copyLumaOnly == TRUE) {
+        osal_free(pY);
+        osal_free(pCb);
+        osal_free(pCr);
+        osal_free(pCbTemp);
+        return totSize;
+    }
+
+    if (interLeave || p10_32bit_interleave) {
+        Int32    cbcr_per_2pix=1;
+
+        cbcr_per_2pix = (format==FORMAT_224||format==FORMAT_444) ? 2 : 1;
+        vdi_read_memory(coreIdx, fbSrc->bufCb, pCbTemp, stride*cbcr_per_2pix * chromaHeight, endian);
+    } else {
+        vdi_read_memory(coreIdx, fbSrc->bufCb, pCb, chroma_stride * chromaHeight, endian);
+        if ( (fbSrc->format == FORMAT_420_P10_32BIT_LSB || fbSrc->format == FORMAT_420_P10_32BIT_MSB) &&
+            p10_32bit_interleave == 1) {
+            // Nothing to do
+        }
+        else {
+            vdi_read_memory(coreIdx, fbSrc->bufCr, pCr, chroma_stride * chromaHeight, endian);
+        }
+    }
+        
+    if (interLeave == TRUE || p10_32bit_interleave == TRUE) {
+        //Uint8    pTemp[16];
+        Uint8*   pTemp;
+        Uint8*   dstAddrCb;
+        Uint8*   dstAddrCr;
+        Uint8*   ptrCb, *ptrCr;
+        Int32    cbcr_per_2pix=1, k;
+        Uint32*   pTempLeft32, *pTempRight32;
+        Uint32   temp_32;
+
+        dstAddrCb = pDst + dstWidth*dstHeight; 
+        dstAddrCr = dstAddrCb + dstChromaWidth*dstChromaHeight;
+
+        cbcr_per_2pix = (format==FORMAT_224||format==FORMAT_444) ? 2 : 1;
+
+        for ( y = 0 ; y < dstChromaHeight; ++y ) {
+            ptrCb = pCb;
+            ptrCr = pCr;
+            for ( x = 0 ; x < stride*cbcr_per_2pix ; x += dramBusWidth ) {
+                pix_addr = GetXY2AXIAddr(&mapCfg, 2, y+(offsetY/div_y), x, stride, fbSrc);
+                pTemp = pCbTemp + (pix_addr - baseCb);
+                // CHECK POINT
+                if ( fbSrc->format == FORMAT_420_P10_32BIT_MSB )
+                    SwapPixelOrder(pTemp);
+                // CHECK POINT
+
+                if (interLeave == TRUE) {
+                    for (k=0; k<dramBusWidth && (x+k) < stride; k+=(2*bpp/8)) {
+                        if (bpp == 8) {
+                            if (nv21) {
+                                *ptrCr++ = pTemp[k];
+                                *ptrCb++ = pTemp[k+1];
+                            }
+                            else {
+                                *ptrCb++ = pTemp[k];
+                                *ptrCr++ = pTemp[k+1];
+                            }
+                        } 
+                        else {
+                            if (nv21) {
+                                *ptrCr++ = pTemp[k];
+                                *ptrCr++ = pTemp[k+1];
+                                *ptrCb++ = pTemp[k+2];
+                                *ptrCb++ = pTemp[k+3];
+                            }
+                            else {
+                                *ptrCb++ = pTemp[k];
+                                *ptrCb++ = pTemp[k+1];
+                                *ptrCr++ = pTemp[k+2];
+                                *ptrCr++ = pTemp[k+3];
+                            }
+                        }
+                    }
+                }
+                else {
+                    for (k=0; k<dramBusWidth && (x+k) < stride; k+=8) {//(2*bpp/8)) {
+                        pTempLeft32 = (Uint32*)&pTemp[k];
+                        pTempRight32 = (Uint32*)&pTemp[k+4];
+
+                        if (format==FORMAT_420_P10_32BIT_MSB) {
+                            temp_32 = *pTempLeft32 & 0x003ff000;
+                            *pTempLeft32 = (*pTempLeft32 & 0xffc00000)
+                                | (*pTempLeft32 & 0x00000ffc) << 10
+                                | (*pTempRight32 & 0x003ff000) >> 10;
+                            *pTempRight32 = (temp_32) << 10
+                                | (*pTempRight32 & 0xffc00000) >> 10
+                                | (*pTempRight32 & 0x00000ffc);
+                        }
+                        else if (format==FORMAT_420_P10_32BIT_LSB) {
+                            temp_32 = *pTempLeft32 & 0x000ffc00;
+                            *pTempLeft32 = (*pTempLeft32 & 0x000003ff)
+                                | (*pTempLeft32 & 0x3ff00000) >> 10
+                                | (*pTempRight32 & 0x000ffc00) << 10;
+                            *pTempRight32 = (temp_32) >> 10
+                                | (*pTempRight32 & 0x000003ff) << 10
+                                | (*pTempRight32 & 0x3ff00000);
+                        }
+
+                        if (nv21) {
+                            *ptrCr++ = pTemp[k];
+                            *ptrCr++ = pTemp[k+1];
+                            *ptrCr++ = pTemp[k+2];
+                            *ptrCr++ = pTemp[k+3];
+                            *ptrCb++ = pTemp[k+4];
+                            *ptrCb++ = pTemp[k+5];
+                            *ptrCb++ = pTemp[k+6];
+                            *ptrCb++ = pTemp[k+7];
+                        }
+                        else {
+                            *ptrCb++ = pTemp[k];
+                            *ptrCb++ = pTemp[k+1];
+                            *ptrCb++ = pTemp[k+2];
+                            *ptrCb++ = pTemp[k+3];
+                            *ptrCr++ = pTemp[k+4];
+                            *ptrCr++ = pTemp[k+5];
+                            *ptrCr++ = pTemp[k+6];
+                            *ptrCr++ = pTemp[k+7];
+                        }
+                    }
+                }
+            }
+            osal_memcpy(dstAddrCb+y*dstChromaWidth, pCb+offsetX/div_x, dstChromaWidth);
+            totSize += dstChromaWidth;
+            osal_memcpy(dstAddrCr+y*dstChromaWidth, pCr+offsetX/div_x, dstChromaWidth);
+            totSize += dstChromaWidth;
+        }
+    }
+    else {      
+        puc = pDst + dstWidth*dstHeight; 
+
+        for (y = 0 ; y < dstChromaHeight; y += 1) {
+            x = 0;
+            pix_addr = GetXY2AXIAddr(&mapCfg, 2, y+(offsetY/div_y), x, chroma_stride, fbSrc);
+            rowBufferCb = pCb + (pix_addr - baseCb);
+            // CHECK POINT
+            for (x = 0 ; x < chroma_stride; x += dramBusWidth) {
+                if ( fbSrc->format == FORMAT_420_P10_32BIT_MSB )
+                    SwapPixelOrder(rowBufferCb+x);
+            }
+            // CHECK POINT
+            osal_memcpy(puc + (y*dstChromaWidth), rowBufferCb+offsetX/div_x, dstChromaWidth);
+            totSize += dstChromaWidth;
+        }
+
+        puc += dstChromaWidth * dstChromaHeight;
+        if ( (fbSrc->format == FORMAT_420_P10_32BIT_LSB || fbSrc->format == FORMAT_420_P10_32BIT_MSB) &&
+            p10_32bit_interleave == 1)
+        {
+        }
+        else
+        {
+            for (y = 0 ; y < dstChromaHeight; y += 1) {
+                x = 0;
+                pix_addr = GetXY2AXIAddr(&mapCfg, 3, y+(offsetY/div_y), x, chroma_stride, fbSrc);
+                //vdi_read_memory(coreIdx, pix_addr, rowBufferCr+x, dramBusWidth,  endian);
+                rowBufferCr = pCr + (pix_addr - baseCr);
+                // CHECK POINT
+                for ( x = 0 ; x < chroma_stride; x += dramBusWidth ) {
+                    if ( fbSrc->format == FORMAT_420_P10_32BIT_MSB )
+                        SwapPixelOrder(rowBufferCr+x);
+                }
+                // CHECK POINT
+                osal_memcpy(puc + (y*dstChromaWidth), rowBufferCr+offsetX/div_x, dstChromaWidth);
+                totSize += dstChromaWidth;
+            }
+        }
+    }
+
+    osal_free(pY);
+    osal_free(pCb);
+    osal_free(pCr);
+    osal_free(pCbTemp);
+
+    return totSize;
+}
+
+Uint32 StoreYuvImageBurstFormat(
+    Uint32          coreIdx, 
+    FrameBuffer*    fbSrc, 
+    TiledMapConfig  mapCfg, 
+    Uint8*          pDst, 
+    VpuRect         cropRect, 
+    BOOL            enableCrop
+    )
+{
+    Uint32          y, x;
+    Uint32          pix_addr, div_x, div_y, chroma_stride;
+    Uint8*          puc;
+    Uint8*          rowBufferY, *rowBufferCb, *rowBufferCr;
+    Uint32          stride      = fbSrc->stride;
+    Uint32          height      = fbSrc->height;
+    int             interLeave  = fbSrc->cbcrInterleave;
+    BOOL            nv21        = fbSrc->nv21;
+    EndianMode      endian      = (EndianMode)fbSrc->endian;
+    FrameBufferFormat format    = (FrameBufferFormat)fbSrc->format;
+    Uint32          width;
+    Uint32          dstWidth, dstHeight;
+    Uint32          offsetX, offsetY;
+    Uint32          dstChromaHeight;
+    Uint32          dstChromaWidth;
+    Uint32          bpp=8;
+    Uint32          p10_32bit_interleave = 0;
+    Int32           productId;
+    Int32           dramBusWidth = 8;
+        Uint32                  totSize = 0;
+
+    productId = VPU_GetProductId(coreIdx);
+    if (PRODUCT_ID_W_SERIES(productId)) {
+        dramBusWidth = 16;
+    }
+    switch (fbSrc->format) {
+    case FORMAT_420:
+    case FORMAT_420_P10_16BIT_LSB:
+    case FORMAT_420_P10_16BIT_MSB:
+    case FORMAT_420_P10_32BIT_LSB:
+    case FORMAT_420_P10_32BIT_MSB:
+    case FORMAT_422:
+    case FORMAT_422_P10_16BIT_LSB:
+    case FORMAT_422_P10_16BIT_MSB:
+    case FORMAT_422_P10_32BIT_LSB:
+    case FORMAT_422_P10_32BIT_MSB:
+        div_x = 2;
+        break;
+    default:
+        div_x = 1;
+    }
+
+    switch (fbSrc->format) {
+    case FORMAT_420:
+    case FORMAT_420_P10_16BIT_LSB:
+    case FORMAT_420_P10_16BIT_MSB:
+    case FORMAT_420_P10_32BIT_LSB:
+    case FORMAT_420_P10_32BIT_MSB:
+    case FORMAT_224:
+        div_y = 2;
+        break;
+    default:
+        div_y = 1;
+    }
+
+    width     = (enableCrop == TRUE ? cropRect.right - cropRect.left : stride);
+    dstHeight = (enableCrop == TRUE ? cropRect.bottom - cropRect.top : height);
+    offsetX   = (enableCrop == TRUE ? cropRect.left : 0);
+    offsetY   = (enableCrop == TRUE ? cropRect.top  : 0);
+
+    switch (fbSrc->format) {
+    case FORMAT_420_P10_16BIT_LSB: 
+    case FORMAT_420_P10_16BIT_MSB:
+        dstWidth = width * 2;
+        bpp = 16;
+        dstChromaWidth  = dstWidth / div_x;
+        dstChromaHeight = dstHeight / div_y;
+        chroma_stride   = (stride / div_x);
+        break;
+    case FORMAT_420_P10_32BIT_LSB:
+    case FORMAT_420_P10_32BIT_MSB:
+#ifdef DUMP_YUV_WHOLE_DATA
+        if (interLeave)
+        {
+            dstChromaWidth = ((VPU_ALIGN16(width/div_x))*2+11)/12*16;
+            dstChromaWidth = VPU_ALIGN16(dstChromaWidth);
+            dstChromaHeight = dstHeight / div_y;
+
+            stride = stride;
+            chroma_stride = stride;
+            dstWidth = (VPU_ALIGN16(width)+11)/12*16;
+
+            interLeave = 0;
+        }
+        else
+        {
+            dstChromaWidth = ((VPU_ALIGN16(width/div_x))+11)/12*16;
+            dstChromaWidth = VPU_ALIGN16(dstChromaWidth);
+            dstChromaHeight = dstHeight / div_y;
+            chroma_stride = dstChromaWidth;
+            stride    = (VPU_ALIGN16(stride)+11)/12*16;
+            dstWidth = (VPU_ALIGN16(dstWidth)+11)/12*16;
+        }
+        break;
+#else
+        if (interLeave)
+        {
+            dstChromaWidth = ((VPU_ALIGN16(width*2/div_x))+11)/12*16;
+            dstChromaWidth = VPU_ALIGN16(dstChromaWidth);
+            chroma_stride = stride;
+
+            dstChromaWidth = (width+2)/3*4;
+            dstChromaHeight = dstHeight / div_y;
+
+            dstWidth = (width+2)/3*4;
+
+            interLeave = 0;
+            p10_32bit_interleave = 1;
+        }
+        else
+        {
+            dstChromaWidth = ((VPU_ALIGN16(width/div_x))+11)/12*16;
+            dstChromaWidth = VPU_ALIGN16(dstChromaWidth);
+            chroma_stride = dstChromaWidth;
+
+            dstChromaWidth = (width/2+2)/3*4;
+            dstChromaHeight = dstHeight / div_y;
+
+            dstWidth = (width+2)/3*4;
+        }
+        break;
+#endif
+    case FORMAT_YUYV:
+    case FORMAT_YUYV_P10_16BIT_MSB:
+    case FORMAT_YUYV_P10_16BIT_LSB:
+    case FORMAT_YUYV_P10_32BIT_MSB:
+    case FORMAT_YUYV_P10_32BIT_LSB:
+    case FORMAT_YVYU:
+    case FORMAT_YVYU_P10_16BIT_MSB:
+    case FORMAT_YVYU_P10_16BIT_LSB:
+    case FORMAT_YVYU_P10_32BIT_MSB:
+    case FORMAT_YVYU_P10_32BIT_LSB:
+    case FORMAT_UYVY:
+    case FORMAT_UYVY_P10_16BIT_MSB:
+    case FORMAT_UYVY_P10_16BIT_LSB:
+    case FORMAT_UYVY_P10_32BIT_MSB:
+    case FORMAT_UYVY_P10_32BIT_LSB:
+    case FORMAT_VYUY:
+    case FORMAT_VYUY_P10_16BIT_MSB:
+    case FORMAT_VYUY_P10_16BIT_LSB:
+    case FORMAT_VYUY_P10_32BIT_MSB:
+    case FORMAT_VYUY_P10_32BIT_LSB:
+        dstWidth        = stride;
+        dstChromaWidth  = 0;
+        dstChromaHeight = 0;
+        chroma_stride   = 0;
+        break;
+    default:
+        dstWidth = width;
+        dstChromaWidth  = width / div_x;
+        dstChromaHeight = dstHeight / div_y;
+        chroma_stride = (stride / div_x);
+        break;
+    }
+
+    puc         = pDst;
+    rowBufferY  = (Uint8*)osal_malloc(stride);
+    rowBufferCb = (Uint8*)osal_malloc(stride*4);
+    rowBufferCr = (Uint8*)osal_malloc(stride*2);
+
+    for ( y=0 ; y<dstHeight ; y+=1 ) 
+    {
+        for ( x=0; x<stride ; x+=dramBusWidth )
+        {  
+            pix_addr = GetXY2AXIAddr(&mapCfg, 0, y+offsetY, x, stride, fbSrc);
+            vdi_read_memory(coreIdx, pix_addr, rowBufferY+x, dramBusWidth,  endian);
+        }
+        osal_memcpy(puc+y*dstWidth, rowBufferY+offsetX, dstWidth);
+                totSize += dstWidth;
+    }
+
+    if (format == FORMAT_400) {
+        osal_free(rowBufferY);
+        osal_free(rowBufferCb);
+        osal_free(rowBufferCr);
+        return totSize;
+    }
+
+    if (interLeave == TRUE) {
+        Uint8    pTemp[16];
+        Uint8*   dstAddrCb;
+        Uint8*   dstAddrCr;
+        Uint8*   ptrCb, *ptrCr;
+        Int32    cbcr_per_2pix=1, k;
+
+        dstAddrCb = pDst + dstWidth*dstHeight; 
+        dstAddrCr = dstAddrCb + dstChromaWidth*dstChromaHeight;
+
+        cbcr_per_2pix = (format==FORMAT_224||format==FORMAT_444) ? 2 : 1;
+
+        for ( y = 0 ; y < dstChromaHeight; ++y ) {
+            ptrCb = rowBufferCb;
+            ptrCr = rowBufferCr;
+            for ( x = 0 ; x < stride*cbcr_per_2pix ; x += dramBusWidth ) {
+                pix_addr = GetXY2AXIAddr(&mapCfg, 2, y+(offsetY/div_y), x, stride, fbSrc);
+                vdi_read_memory(coreIdx, pix_addr,  pTemp, dramBusWidth,  endian); 
+                // CHECK POINT
+                if ( fbSrc->format == FORMAT_420_P10_32BIT_MSB )
+                    SwapPixelOrder(pTemp);
+                // CHECK POINT
+                for (k=0; k<dramBusWidth && (x+k) < stride; k+=(2*bpp/8)) {
+                    if (bpp == 8) {
+                        if (nv21) {
+                            *ptrCr++ = pTemp[k];
+                            *ptrCb++ = pTemp[k+1];
+                        }
+                        else {
+                            *ptrCb++ = pTemp[k];
+                            *ptrCr++ = pTemp[k+1];
+                        }
+                    } 
+                    else {
+                        if (nv21) {
+                            *ptrCr++ = pTemp[k];
+                            *ptrCr++ = pTemp[k+1];
+                            *ptrCb++ = pTemp[k+2];
+                            *ptrCb++ = pTemp[k+3];
+                        }
+                        else {
+                            *ptrCb++ = pTemp[k];
+                            *ptrCb++ = pTemp[k+1];
+                            *ptrCr++ = pTemp[k+2];
+                            *ptrCr++ = pTemp[k+3];
+                        }
+                    }
+                }
+            }
+            osal_memcpy(dstAddrCb+y*dstChromaWidth, rowBufferCb+offsetX/div_x, dstChromaWidth);
+                        totSize += dstChromaWidth;
+            osal_memcpy(dstAddrCr+y*dstChromaWidth, rowBufferCr+offsetX/div_x, dstChromaWidth);
+                        totSize += dstChromaWidth;
+        }
+    }
+    else {      
+        puc = pDst + dstWidth*dstHeight; 
+
+        for (y = 0 ; y < dstChromaHeight; y += 1) {
+            for (x = 0 ; x < chroma_stride; x += dramBusWidth) {
+                pix_addr = GetXY2AXIAddr(&mapCfg, 2, y+(offsetY/div_y), x, chroma_stride, fbSrc);
+                vdi_read_memory(coreIdx, pix_addr, rowBufferCb+x, dramBusWidth,  endian);
+            }
+            osal_memcpy(puc + (y*dstChromaWidth), rowBufferCb+offsetX/div_x, dstChromaWidth);
+                        totSize += dstChromaWidth;
+        }
+
+        puc += dstChromaWidth * dstChromaHeight;
+        if ( (fbSrc->format == FORMAT_420_P10_32BIT_LSB || fbSrc->format == FORMAT_420_P10_32BIT_MSB) &&
+            p10_32bit_interleave == 1)
+        {
+        }
+        else
+        {
+            for (y = 0 ; y < dstChromaHeight; y += 1) {
+                for ( x = 0 ; x < chroma_stride; x += dramBusWidth ) {
+                    pix_addr = GetXY2AXIAddr(&mapCfg, 3, y+(offsetY/div_y), x, chroma_stride, fbSrc);
+                    vdi_read_memory(coreIdx, pix_addr, rowBufferCr+x, dramBusWidth,  endian);
+                }
+                osal_memcpy(puc + (y*dstChromaWidth), rowBufferCr+offsetX/div_x, dstChromaWidth);
+                                totSize += dstChromaWidth;
+            }
+        }
+    }
+
+    osal_free(rowBufferY);
+    osal_free(rowBufferCb);
+    osal_free(rowBufferCr);
+
+    return totSize;
+}
+
+Uint8* GetYUVFromFrameBuffer(
+    DecHandle       decHandle,
+    FrameBuffer*    fb,
+    VpuRect         rcFrame,
+    Uint32*         retWidth,
+    Uint32*         retHeight,
+    Uint32*         retBpp,
+    size_t*         retSize
+    )
+{
+    Uint32          coreIdx = VPU_HANDLE_CORE_INDEX(decHandle);
+    size_t          frameSizeY;                                         // the size of luma
+    size_t          frameSizeC;                                         // the size of chroma
+    size_t          frameSize;                                          // the size of frame
+    Uint32          Bpp = 1;                                            //!<< Byte per pixel
+    Uint32          picWidth, picHeight;
+    Uint8*          pYuv;
+    TiledMapConfig  mapCfg;
+
+    picWidth  = rcFrame.right - rcFrame.left;
+    picHeight = rcFrame.bottom - rcFrame.top;
+
+
+    CalcYuvSize(fb->format, picWidth, fb->height, fb->cbcrInterleave, &frameSizeY, &frameSizeC, &frameSize, NULL, NULL, NULL);
+
+    switch (fb->format) {
+    case FORMAT_422_P10_16BIT_MSB:
+    case FORMAT_422_P10_16BIT_LSB:
+    case FORMAT_420_P10_16BIT_LSB:
+    case FORMAT_420_P10_16BIT_MSB:
+        Bpp = 2;
+        break;
+    case FORMAT_420_P10_32BIT_LSB:
+    case FORMAT_420_P10_32BIT_MSB:
+        picWidth = (picWidth/3)*4 + ((picWidth%3) ? 4 : 0);
+        Bpp = 1;
+        break;
+    case FORMAT_422:
+    case FORMAT_422_P10_32BIT_MSB:
+    case FORMAT_422_P10_32BIT_LSB:
+        break;
+    default:
+        Bpp = 1;
+        break;
+    }
+    {
+        Int32   temp_picWidth;
+        Int32   chromaWidth;
+
+        switch (fb->format) {
+        case FORMAT_420_P10_32BIT_LSB:
+        case FORMAT_420_P10_32BIT_MSB:
+            temp_picWidth = VPU_ALIGN32(picWidth);
+            chromaWidth = ((VPU_ALIGN16(temp_picWidth / 2*(1 << 1)) + 2) / 3 * 4);
+            frameSizeY = (temp_picWidth + 2) / 3 * 4 * picHeight;
+            frameSizeC = chromaWidth * picHeight / 2 * 2;
+            frameSize = frameSizeY + frameSizeC;
+            break;
+        default:
+            break;
+        }       
+    }
+    if ((pYuv=(Uint8*)osal_malloc(frameSize)) == NULL) {
+        VLOG(ERR, "%s:%d Failed to allocate memory\n", __FUNCTION__, __LINE__);
+        return NULL;
+    }
+
+    VPU_DecGiveCommand(decHandle, GET_TILEDMAP_CONFIG, &mapCfg);
+    if (fb->mapType == LINEAR_FRAME_MAP || fb->mapType == COMPRESSED_FRAME_MAP) {
+        if (decHandle->codecMode == C7_VP9_DEC) {
+            *retSize = StoreYuvImageBurstLinear(coreIdx, fb, mapCfg, pYuv, rcFrame, TRUE, TRUE); 
+        }
+        else {
+            *retSize = StoreYuvImageBurstLinear(coreIdx, fb, mapCfg, pYuv, rcFrame, TRUE, FALSE);
+        }
+    }
+    else {
+        *retSize = StoreYuvImageBurstFormat(coreIdx, fb, mapCfg, pYuv, rcFrame, TRUE); 
+    }
+
+    *retWidth  = picWidth;
+    *retHeight = picHeight;
+    *retBpp    = Bpp; 
+
+    return pYuv;
+}
+
+void PrepareDecoderTest(
+    DecHandle decHandle
+    )
+{
+    UNREFERENCED_PARAMETER(decHandle);
+}
+
+void PreparationWorkForDecTest(
+    DecHandle handle
+    )
+{
+    UNREFERENCED_PARAMETER(handle);
+}
+
+void PreparationWorkForEncTest(
+    EncHandle   handle 
+    )
+{
+    UNREFERENCED_PARAMETER(handle);
+}
+
+int ProcessEncodedBitstreamBurst(Uint32 coreIdx, osal_file_t fp, int targetAddr,
+    PhysicalAddress bsBufStartAddr, PhysicalAddress bsBufEndAddr,
+    int size, int endian, Comparator comparator)
+{
+    Uint8 * buffer = 0;
+    int room = 0;
+    int file_wr_size = 0;
+
+    buffer = (Uint8 *)osal_malloc(size);
+    if( ( targetAddr + size ) > (int)bsBufEndAddr )
+    {
+        room = bsBufEndAddr - targetAddr;
+        vdi_read_memory(coreIdx, targetAddr, buffer, room,  endian);
+        vdi_read_memory(coreIdx, bsBufStartAddr, buffer+room, (size-room), endian);
+    }
+    else
+    {
+        vdi_read_memory(coreIdx, targetAddr, buffer, size, endian); 
+    }   
+
+    if ( comparator) {
+        if (Comparator_Act(comparator, buffer, size) == FALSE) {
+            osal_free(buffer);
+            return 0;
+        }
+    }
+
+    if (fp) {
+        file_wr_size = osal_fwrite(buffer, sizeof(Uint8), size, fp);
+        osal_fflush(fp);
+    }
+
+    osal_free( buffer );
+
+    return file_wr_size;
+}
+
+#ifdef SUPPORT_ENCODE_CUSTOM_HEADER
+Uint32 activeParameterSEIEncode(sei_active_parameter_t *sap, hrd_t *hrd, Uint8 *pBuffer, Uint32 bufferSize)
+{
+    spp_enc_context spp;
+    Uint32 code;
+    const Uint32 layer_id = 0;
+    const Uint32 temporal_id_plus_one = 1;
+    const Uint32 payload_type = (Uint32)ACTIVE_PARAMETER_SETS;
+
+    Uint32 put_bit_byte_size;
+    Uint32 payload_bit_size;
+    Uint32 payload_byte_size;
+    int i;
+
+    payload_bit_size = 0;
+    payload_byte_size = 0;
+
+    spp = spp_enc_init(pBuffer, bufferSize, 1);
+
+    // put start code
+    spp_enc_put_nal_byte(spp, 1, 4);
+
+    // put nal header
+    code = (SNT_PREFIX_SEI << 9) | (layer_id << 3) | temporal_id_plus_one;
+    spp_enc_put_nal_byte(spp, code, 2);
+
+    // put payload type
+    spp_enc_put_nal_byte(spp, payload_type, 1);
+
+    // put payload size
+    payload_bit_size = 4/*active_video_parameter_set_id*/ + 1/*self_contained_cvs_flag*/ + 1/*no_parameter_set_update_flag*/;
+    payload_bit_size += spp_enc_get_ue_bit_size(sap->num_sps_ids_minus1);
+    for (i=0; i <= sap->num_sps_ids_minus1; i++)
+        payload_bit_size+= spp_enc_get_ue_bit_size(sap->active_seq_parameter_set_id[i]);
+
+    payload_byte_size = ((payload_bit_size+7)/8);
+    spp_enc_put_nal_byte(spp, payload_byte_size, 1); 
+
+    spp_enc_put_bits(spp, sap->active_video_parameter_set_id, 4); 
+    spp_enc_put_bits(spp, sap->self_contained_cvs_flag, 1); 
+    spp_enc_put_bits(spp, sap->no_parameter_set_update_flag, 1); 
+    spp_enc_put_ue(spp, sap->num_sps_ids_minus1); 		
+    for (i=0; i <= sap->num_sps_ids_minus1; i++)
+    {
+        spp_enc_put_ue(spp, sap->active_seq_parameter_set_id[i]); 		
+    }
+
+    if (payload_bit_size & 7)
+    {
+        spp_enc_put_bits(spp, 1/*payload_bit_equal_to_one*/, 1);
+        spp_enc_put_bits(spp, 0/*payload_bit_equal_to_zero*/,  (8 - (payload_bit_size & 7)-1));
+    }
+    spp_enc_put_byte_align(spp, 1);
+    spp_enc_flush(spp);
+
+    put_bit_byte_size = spp_enc_get_nal_cnt(spp);
+
+    spp_enc_deinit(spp);
+    return put_bit_byte_size;
+}
+Uint32 picTimingSEIEncode(sei_pic_timing_t *spt, hrd_t *hrd, Uint8 *pBuffer, Uint32 bufferSize)
+{
+    spp_enc_context spp;
+    Uint32 code;
+    const Uint32 layer_id = 0;
+    const Uint32 temporal_id_plus_one = 1;
+    const Uint32 payload_type = (Uint32)PICTURE_TIMING;
+
+    Uint32 put_bit_byte_size;
+    Uint32 payload_bit_size;
+    Uint32 payload_byte_size;
+    int i;
+
+    payload_bit_size = 0;
+    payload_byte_size = 0;
+
+    if (hrd->nal_hrd_parameters_present_flag || hrd->vcl_hrd_parameters_present_flag)
+        spt->CpbDpbDelaysPresentFlag = 1;
+
+    spp = spp_enc_init(pBuffer, bufferSize, 1);
+
+    // put start code
+    spp_enc_put_nal_byte(spp, 1, 4);
+
+    // put nal header
+    code = (SNT_PREFIX_SEI << 9) | (layer_id << 3) | temporal_id_plus_one;
+    spp_enc_put_nal_byte(spp, code, 2);
+
+    // put payload type
+    spp_enc_put_nal_byte(spp, payload_type, 1);
+
+    // put payload size
+    payload_bit_size = 4/*pic_struct*/ + 2/*source_scan_type*/ + 1/*duplicate_flag*/;
+
+    if (spt->CpbDpbDelaysPresentFlag)
+    {
+        payload_bit_size += (hrd->au_cpb_removal_delay_length_minus1 + 1); //spt->au_cpb_removal_delay_minus1
+        payload_bit_size += (hrd->dpb_output_delay_length_minus1+ 1);		// spt->pic_dpb_output_delay
+        if (hrd->sub_pic_hrd_params_present_flag)
+            payload_bit_size += (hrd->dpb_output_delay_du_length_minus1 + 1); //spt->pic_dpb_output_du_delay
+        if (hrd->sub_pic_hrd_params_present_flag &&
+            hrd->sub_pic_cpb_params_in_pic_timing_sei_flag)
+        {
+            payload_bit_size += spp_enc_get_ue_bit_size(spt->num_decoding_units_minus1);	//spt->num_decoding_units_minus1
+            payload_bit_size += 1;	// spt->du_common_cpb_removal_delay_flag
+            if (spt->du_common_cpb_removal_delay_flag)
+                payload_bit_size +=  (hrd->du_cpb_removal_delay_increment_length_minus1 + 1);	//spt->du_common_cpb_removal_delay_increment_minus1
+            for (i=0; i <= spt->num_decoding_units_minus1; i++)
+            {
+                payload_bit_size += spp_enc_get_ue_bit_size(spt->num_nalus_in_du_minus1[i]);	//spt->num_nalus_in_du_minus1[i]
+                if (!spt->du_common_cpb_removal_delay_flag && i < spt->num_decoding_units_minus1)
+                {
+                    payload_bit_size += (hrd->du_cpb_removal_delay_increment_length_minus1 + 1);	// spt->du_cpb_removal_delay_increment_minus1[i]
+                }
+            }
+        }
+    }
+
+    payload_byte_size = ((payload_bit_size+7)/8);
+    spp_enc_put_nal_byte(spp, payload_byte_size, 1); 
+
+    spp_enc_put_bits(spp, spt->pic_struct, 4); 
+    spp_enc_put_bits(spp, spt->source_scan_type, 2); 
+    spp_enc_put_bits(spp, spt->duplicate_flag, 1); 		
+
+    if (spt->CpbDpbDelaysPresentFlag)
+    {
+        spp_enc_put_bits(spp, spt->au_cpb_removal_delay_minus1, (hrd->au_cpb_removal_delay_length_minus1 + 1));
+        spp_enc_put_bits(spp, spt->pic_dpb_output_delay, (hrd->dpb_output_delay_length_minus1+ 1));
+        if (hrd->sub_pic_hrd_params_present_flag)
+            spp_enc_put_bits(spp, spt->pic_dpb_output_du_delay, (hrd->dpb_output_delay_du_length_minus1 + 1));
+        if (hrd->sub_pic_hrd_params_present_flag &&
+            hrd->sub_pic_cpb_params_in_pic_timing_sei_flag)
+        {
+            spp_enc_put_ue(spp, spt->num_decoding_units_minus1);
+            spp_enc_put_bits(spp, spt->du_common_cpb_removal_delay_flag, 1);
+            if (spt->du_common_cpb_removal_delay_flag)
+                spp_enc_put_bits(spp, spt->du_common_cpb_removal_delay_increment_minus1, (hrd->du_cpb_removal_delay_increment_length_minus1 + 1));
+            for (i=0; i <= spt->num_decoding_units_minus1; i++)
+            {
+                spp_enc_put_ue(spp, spt->num_nalus_in_du_minus1[i]);
+                if (!spt->du_common_cpb_removal_delay_flag && i < spt->num_decoding_units_minus1)
+                {
+                    spp_enc_put_bits(spp, spt->du_cpb_removal_delay_increment_minus1[i], (hrd->du_cpb_removal_delay_increment_length_minus1 + 1));
+                }
+            }
+
+        }
+
+    }
+    if (payload_bit_size & 7)
+    {
+        spp_enc_put_bits(spp, 1/*payload_bit_equal_to_one*/, 1);
+        spp_enc_put_bits(spp, 0/*payload_bit_equal_to_zero*/,  (8 - (payload_bit_size & 7)-1));
+    }
+
+    spp_enc_put_byte_align(spp, 1);
+    spp_enc_flush(spp);
+
+    put_bit_byte_size = spp_enc_get_nal_cnt(spp);
+
+    spp_enc_deinit(spp);
+    return put_bit_byte_size;
+}
+
+Uint32 bufferingPeriodSeiEncode(sei_buffering_period_t *sbp, hrd_t *hrd, Uint8 *pBuffer, Uint32 bufferSize)
+{
+    spp_enc_context spp;
+    Uint32 code;
+    const Uint32 layer_id = 0;
+    const Uint32 temporal_id_plus_one = 1;
+    const Uint32 payload_type = (Uint32)BUFFERING_PERIOD;
+    int i;
+    Uint32 put_bit_byte_size;
+    Uint32 payload_bit_size;
+    Uint32 payload_byte_size;
+
+    payload_bit_size = 0;
+    payload_byte_size = 0;
+
+    sbp->sub_pic_hrd_params_present_flag = hrd->sub_pic_hrd_params_present_flag;
+    sbp->au_cpb_removal_delay_length_minus1 =  hrd->au_cpb_removal_delay_length_minus1;
+    sbp->initial_cpb_removal_delay_length_minus1 =  hrd->initial_cpb_removal_delay_length_minus1;
+    sbp->CpbCnt =  hrd->cpb_cnt_minus1[0]+1;
+    sbp->NalHrdBpPresentFlag =  hrd->nal_hrd_parameters_present_flag;
+    sbp->VclHrdBpPresentFlag =  hrd->vcl_hrd_parameters_present_flag;
+
+    payload_bit_size += spp_enc_get_ue_bit_size(sbp->bp_seq_parameter_set_id);
+    if (!sbp->sub_pic_hrd_params_present_flag)
+        payload_bit_size += 1;	//irap_cpb_params_present_flag
+    if (sbp->irap_cpb_params_present_flag)
+    {
+        payload_bit_size += (sbp->au_cpb_removal_delay_length_minus1+1);	//cpb_delay_offset
+        payload_bit_size += (sbp->au_cpb_removal_delay_length_minus1+1);	//dpb_delay_offset
+    }	
+    payload_bit_size += 1;	//concatenation_flag
+    payload_bit_size += (sbp->au_cpb_removal_delay_length_minus1+1); //au_cpb_removal_delay_delta_minus1
+    if (sbp->NalHrdBpPresentFlag)
+    {
+        for (i=0; i < (int)sbp->CpbCnt; i++)
+        {
+            payload_bit_size += (sbp->initial_cpb_removal_delay_length_minus1+1);	//nal_initial_cpb_removal_delay
+            payload_bit_size += (sbp->initial_cpb_removal_delay_length_minus1+1);	//nal_initial_cpb_removal_offset
+
+            if (sbp->sub_pic_hrd_params_present_flag || sbp->irap_cpb_params_present_flag)
+            {
+                payload_bit_size += (sbp->initial_cpb_removal_delay_length_minus1+1);	// nal_initial_alt_cpb_removal_delay
+                payload_bit_size += (sbp->initial_cpb_removal_delay_length_minus1+1);	//nal_initial_alt_cpb_removal_offset
+            }
+        }
+    }
+    if (sbp->VclHrdBpPresentFlag )
+    {
+        for (i=0; i < (int)sbp->CpbCnt; i++)
+        {
+            payload_bit_size += (sbp->initial_cpb_removal_delay_length_minus1+1);	//vcl_initial_cpb_removal_delay
+            payload_bit_size += (sbp->initial_cpb_removal_delay_length_minus1+1);	//vcl_initial_cpb_removal_offset
+
+            if (sbp->sub_pic_hrd_params_present_flag || sbp->irap_cpb_params_present_flag)
+            {
+                payload_bit_size += (sbp->initial_cpb_removal_delay_length_minus1+1);	//vcl_initial_alt_cpb_removal_delay
+                payload_bit_size += (sbp->initial_cpb_removal_delay_length_minus1+1);	//vcl_initial_alt_cpb_removal_offset
+            }
+        }
+    }
+
+    spp = spp_enc_init(pBuffer, bufferSize, 1);
+
+    // put start code
+    spp_enc_put_nal_byte(spp, 1, 4);
+
+    // put nal header
+    code = (SNT_PREFIX_SEI << 9) | (layer_id << 3) | temporal_id_plus_one;
+    spp_enc_put_nal_byte(spp, code, 2);
+
+    // put payload type
+    spp_enc_put_nal_byte(spp, payload_type, 1);
+
+    // put payload size
+    payload_byte_size = ((payload_bit_size+7)/8);
+    spp_enc_put_nal_byte(spp, payload_byte_size, 1); 
+
+    // put buffering period
+    spp_enc_put_ue(spp, sbp->bp_seq_parameter_set_id);
+    if (!sbp->sub_pic_hrd_params_present_flag)
+        spp_enc_put_bits(spp, sbp->irap_cpb_params_present_flag, 1);
+    if (sbp->irap_cpb_params_present_flag)
+    {
+        spp_enc_put_bits(spp, sbp->dpb_delay_offset, (sbp->au_cpb_removal_delay_length_minus1+1));
+        spp_enc_put_bits(spp, sbp->dpb_delay_offset, (sbp->au_cpb_removal_delay_length_minus1+1));
+    }
+    spp_enc_put_bits(spp, sbp->concatenation_flag, 1); 
+    spp_enc_put_bits(spp, sbp->au_cpb_removal_delay_delta_minus1, (sbp->au_cpb_removal_delay_length_minus1+1)); 
+    if (sbp->NalHrdBpPresentFlag)
+    {
+        for (i=0; i < (int)sbp->CpbCnt; i++)
+        {
+            spp_enc_put_bits(spp, sbp->nal_initial_cpb_removal_delay[i], (sbp->initial_cpb_removal_delay_length_minus1+1));
+            spp_enc_put_bits(spp, sbp->nal_initial_cpb_removal_offset[i], (sbp->initial_cpb_removal_delay_length_minus1+1));
+            if (sbp->sub_pic_hrd_params_present_flag || sbp->irap_cpb_params_present_flag)
+            {
+                spp_enc_put_bits(spp, sbp->nal_initial_alt_cpb_removal_delay[i], (sbp->initial_cpb_removal_delay_length_minus1+1));
+                spp_enc_put_bits(spp, sbp->nal_initial_alt_cpb_removal_offset[i], (sbp->initial_cpb_removal_delay_length_minus1+1));
+            }
+        }
+    }
+    if (sbp->VclHrdBpPresentFlag)
+    {
+        for (i=0; i < (int)sbp->CpbCnt; i++)
+        {
+            spp_enc_put_bits(spp, sbp->vcl_initial_cpb_removal_delay[i], (sbp->initial_cpb_removal_delay_length_minus1+1));
+            spp_enc_put_bits(spp, sbp->vcl_initial_cpb_removal_offset[i], (sbp->initial_cpb_removal_delay_length_minus1+1));
+            if (sbp->sub_pic_hrd_params_present_flag || sbp->irap_cpb_params_present_flag)
+            {
+                spp_enc_put_bits(spp, sbp->vcl_initial_alt_cpb_removal_delay[i], (sbp->initial_cpb_removal_delay_length_minus1+1));
+                spp_enc_put_bits(spp, sbp->vcl_initial_alt_cpb_removal_offset[i], (sbp->initial_cpb_removal_delay_length_minus1+1));
+            }
+        }
+    }		
+
+    if (payload_bit_size & 7)
+    {
+        spp_enc_put_bits(spp, 1/*payload_bit_equal_to_one*/, 1);
+        spp_enc_put_bits(spp, 0/*payload_bit_equal_to_zero*/,  (8 - (payload_bit_size & 7)-1));
+    }
+
+    spp_enc_put_byte_align(spp, 1);
+    spp_enc_flush(spp);
+
+    put_bit_byte_size = spp_enc_get_nal_cnt(spp);
+
+    spp_enc_deinit(spp);
+
+    return put_bit_byte_size;
+}
+
+Uint32 EncodePrefixSEI( sei_active_parameter_t *sap, sei_pic_timing_t *spt, sei_buffering_period_t *sbp, hrd_t *hrd, Uint8 *pBuffer, Uint32 bufferSize)
+{
+    Uint8 *ptrBuffer;
+    Uint32 byteSize;
+
+    byteSize = 0;
+
+    ptrBuffer = (Uint8 *)(pBuffer + byteSize);
+    byteSize += activeParameterSEIEncode(sap, hrd, ptrBuffer, bufferSize);
+
+    ptrBuffer = (Uint8 *)(pBuffer + byteSize);
+    byteSize += picTimingSEIEncode(spt, hrd, ptrBuffer, bufferSize);
+
+    ptrBuffer = (Uint8 *)(pBuffer + byteSize);
+    byteSize += bufferingPeriodSeiEncode(sbp, hrd, ptrBuffer, bufferSize);
+
+    return byteSize;
+}
+
+// calculate scale value of bitrate and initial delay
+int calcScale(int x)
+{
+    Uint32 iMask = 0xffffffff;
+    int scaleValue = 32;
+
+    if (x==0)
+    {
+        return 0;
+    }
+
+    while ((x&iMask) != 0)
+    {
+        scaleValue--;
+        iMask = (iMask >> 1);
+    }
+
+    return scaleValue;
+}
+
+static void hrdEncode(spp_enc_context spp, hrd_t *hrd)
+{
+    Uint32 layer;
+    Uint32 cpb;
+
+    hrd->commonInfPresentFlag = 1;
+    // the other parameters can be configured according to the target application.
+    if (hrd->commonInfPresentFlag)
+    {
+        spp_enc_put_bits(spp, hrd->nal_hrd_parameters_present_flag, 1);
+        spp_enc_put_bits(spp, hrd->vcl_hrd_parameters_present_flag, 1);
+
+        if (hrd->nal_hrd_parameters_present_flag || hrd->vcl_hrd_parameters_present_flag)
+        {
+            spp_enc_put_bits(spp, hrd->sub_pic_hrd_params_present_flag, 1);
+            if (hrd->sub_pic_hrd_params_present_flag)
+            {
+                spp_enc_put_bits(spp, hrd->tick_divisor_minus2, 8);
+                spp_enc_put_bits(spp, hrd->du_cpb_removal_delay_increment_length_minus1, 5);
+                spp_enc_put_bits(spp, hrd->sub_pic_cpb_params_in_pic_timing_sei_flag, 1);
+                spp_enc_put_bits(spp, hrd->dpb_output_delay_du_length_minus1, 5);
+            }
+
+            spp_enc_put_bits(spp, hrd->bit_rate_scale, 4);
+
+            spp_enc_put_bits(spp, hrd->cpb_size_scale, 4);
+
+            if (hrd->sub_pic_hrd_params_present_flag)
+            {
+                spp_enc_put_bits(spp, hrd->cpb_size_du_scale, 4);
+            }
+
+            spp_enc_put_bits(spp, hrd->initial_cpb_removal_delay_length_minus1, 5);
+            spp_enc_put_bits(spp, hrd->au_cpb_removal_delay_length_minus1, 5);
+            spp_enc_put_bits(spp, hrd->dpb_output_delay_length_minus1, 5);
+        }
+    }
+
+    for (layer=0; layer <= (Uint32)hrd->vps_max_sub_layers_minus1; layer++)
+    {
+        spp_enc_put_bits(spp, hrd->fixed_pic_rate_general_flag[layer], 1);
+
+        if (!hrd->fixed_pic_rate_general_flag[layer])
+            spp_enc_put_bits(spp, hrd->fixed_pic_rate_within_cvs_flag[layer], 1);
+
+        if (hrd->fixed_pic_rate_within_cvs_flag[layer])
+            spp_enc_put_ue(spp, hrd->elemental_duration_in_tc_minus1[layer]);
+        else
+            spp_enc_put_bits(spp, hrd->low_delay_hrd_flag[layer], 1);
+
+        if (!hrd->low_delay_hrd_flag[layer])
+            spp_enc_put_ue(spp, hrd->cpb_cnt_minus1[layer]);
+
+        if (hrd->nal_hrd_parameters_present_flag)
+        {
+            for(cpb=0; cpb <= (Uint32)hrd->cpb_cnt_minus1[layer]; cpb++ )
+            {
+                spp_enc_put_ue(spp, hrd->bit_rate_value_minus1[cpb][layer]);
+
+                spp_enc_put_ue(spp, hrd->cpb_size_value_minus1[cpb][layer]);
+
+                if (hrd->sub_pic_hrd_params_present_flag)
+                {
+                    spp_enc_put_ue(spp, hrd->cpb_size_du_value_minus1[cpb][layer]);
+
+                    spp_enc_put_ue(spp, hrd->bit_rate_du_value_minus1[cpb][layer]);
+                }
+                spp_enc_put_bits(spp, hrd->cbr_flag[cpb][layer], 1);					
+            }
+        }
+
+        if (hrd->vcl_hrd_parameters_present_flag)
+        {
+            for(cpb=0; cpb <= (Uint32)hrd->cpb_cnt_minus1[layer]; cpb++ )
+            {
+                spp_enc_put_ue(spp, hrd->bit_rate_value_minus1[cpb][layer]);
+
+                spp_enc_put_ue(spp, hrd->cpb_size_value_minus1[cpb][layer]);
+
+                if (hrd->sub_pic_hrd_params_present_flag)
+                {
+                    spp_enc_put_ue(spp, hrd->cpb_size_du_value_minus1[cpb][layer]);
+
+                    spp_enc_put_ue(spp, hrd->bit_rate_du_value_minus1[cpb][layer]);
+                }
+                spp_enc_put_bits(spp, hrd->cbr_flag[cpb][layer], 1);					
+            }
+        }
+    }
+}
+
+BOOL EncodeVUI(hrd_t *hrd, vui_t *vui, Uint8 *pBuffer, Uint32 bufferSize, Uint32 *pByteSize, Uint32 *pBitSize, double dframeRate)
+{
+    spp_enc_context spp;
+    Uint32 put_bit_byte_size;
+    Uint32 put_bit_bit_size;
+
+    // the other parameters can be configured according to the target application.
+
+    spp = spp_enc_init(pBuffer, bufferSize, 0);
+
+    spp_enc_put_bits(spp, vui->aspect_ratio_info_present_flag, 1); 
+    if (vui->aspect_ratio_info_present_flag)
+    {
+        spp_enc_put_bits(spp, vui->aspect_ratio_idc, 8); 
+
+        if (vui->aspect_ratio_idc == EXTENDED_SAR)
+        {
+            spp_enc_put_bits(spp, vui->sar_width, 16); 
+            spp_enc_put_bits(spp, vui->sar_height, 16); 
+        }
+    }
+
+    spp_enc_put_bits(spp, vui->overscan_info_present_flag, 1); 
+    if (vui->overscan_info_present_flag)
+    {
+        spp_enc_put_bits(spp, vui->overscan_appropriate_flag, 1); 
+    }
+
+    spp_enc_put_bits(spp, vui->video_signal_type_present_flag, 1); 
+    if (vui->video_signal_type_present_flag)
+    {
+        spp_enc_put_bits(spp, vui->video_format, 3); 
+        spp_enc_put_bits(spp, vui->video_full_range_flag, 1); 
+        spp_enc_put_bits(spp, vui->colour_description_present_flag, 1); 
+
+        if (vui->colour_description_present_flag)
+        {
+            spp_enc_put_bits(spp, vui->colour_primaries, 8); 
+            spp_enc_put_bits(spp, vui->transfer_characteristics, 1); 
+            spp_enc_put_bits(spp, vui->matrix_coeffs, 1); 
+        }
+    }
+
+    spp_enc_put_bits(spp, vui->chroma_loc_info_present_flag, 1); 
+    if (vui->chroma_loc_info_present_flag)
+    {
+        spp_enc_put_ue(spp, vui->chroma_sample_loc_type_top_field);
+        spp_enc_put_ue(spp, vui->chroma_sample_loc_type_bottom_field);
+    }
+
+    spp_enc_put_bits(spp, vui->neutral_chroma_indication_flag, 1); 
+    spp_enc_put_bits(spp, vui->field_seq_flag, 1); 
+    spp_enc_put_bits(spp, vui->frame_field_info_present_flag, 1); 
+    spp_enc_put_bits(spp, vui->default_display_window_flag, 1); 
+    if (vui->default_display_window_flag)
+    {
+        spp_enc_put_ue(spp, vui->def_disp_win_left_offset);
+        spp_enc_put_ue(spp, vui->def_disp_win_right_offset);
+        spp_enc_put_ue(spp, vui->def_disp_win_top_offset);
+        spp_enc_put_ue(spp, vui->def_disp_win_bottom_offset);
+    }
+    spp_enc_put_bits(spp, vui->vui_timing_info_present_flag, 1); 
+    if (vui->vui_timing_info_present_flag)
+    {
+        spp_enc_put_bits(spp, vui->vui_num_units_in_tick, 32); 
+        spp_enc_put_bits(spp, vui->vui_time_scale, 32); 
+        spp_enc_put_bits(spp, vui->vui_poc_proportional_to_timing_flag, 1); 
+        if (vui->vui_poc_proportional_to_timing_flag)
+        {
+            spp_enc_put_ue(spp, vui->vui_num_ticks_poc_diff_one_minus1); 
+        }
+
+        spp_enc_put_bits(spp, vui->vui_hrd_parameters_present_flag, 1); 
+        if (vui->vui_hrd_parameters_present_flag)
+            hrdEncode(spp, hrd);
+    }
+
+    spp_enc_put_bits(spp, vui->bitstream_restriction_flag, 1); 
+    if (vui->bitstream_restriction_flag)
+    {
+        spp_enc_put_bits(spp, vui->tiles_fixed_structure_flag, 1);
+        spp_enc_put_bits(spp, vui->motion_vectors_over_pic_boundaries_flag, 1);
+        spp_enc_put_bits(spp, vui->restricted_ref_pic_lists_flag, 1);
+        spp_enc_put_ue(spp, vui->min_spatial_segmentation_idc);
+        spp_enc_put_ue(spp, vui->max_bytes_per_pic_denom);
+        spp_enc_put_ue(spp, vui->max_bits_per_min_cu_denom);
+        spp_enc_put_ue(spp, vui->log2_max_mv_length_horizontal);
+        spp_enc_put_ue(spp, vui->log2_max_mv_length_vertical);
+    }
+
+    spp_enc_flush(spp);		
+
+    put_bit_byte_size = spp_enc_get_nal_cnt(spp);
+    put_bit_bit_size = spp_enc_get_rbsp_bit(spp);
+
+    if (pByteSize)
+        *pByteSize = put_bit_byte_size;
+
+    if (pBitSize)
+        *pBitSize = put_bit_bit_size;
+
+    spp_enc_deinit(spp);
+    return 1;
+}
+
+#endif 
+
+

+ 289 - 0
wave420l/code/sample/helper/misc/container.c

@@ -0,0 +1,289 @@
+//--=========================================================================--
+//  This file is a part of VPU Reference API project
+//-----------------------------------------------------------------------------
+//
+//       This confidential and proprietary software may be used only
+//     as authorized by a licensing agreement from Chips&Media Inc.
+//     In the event of publication, the following notice is applicable:
+//
+//            (C) COPYRIGHT 2006 - 2013  CHIPS&MEDIA INC.
+//                      ALL RIGHTS RESERVED
+//
+//       The entire notice above must be reproduced on all authorized
+//       copies.
+//
+//--=========================================================================--
+
+#include <stdio.h>
+
+#include "main_helper.h"
+
+
+/* make container */
+#if 0//def SUPPORT_FFMPEG_DEMUX
+#include <libavformat/avformat.h>
+#include <libavcodec/avcodec.h>
+
+/* add a video output stream */
+static AVStream *add_stream(AVFormatContext *oc, int codec_id, EncConfigParam encConfig, int gopSize)
+{
+    AVCodecContext *c;
+    AVStream *st;
+
+    st = avformat_new_stream(oc, 0);
+    if (!st) {
+        VLOG(ERR, "Could not alloc stream\n");
+        return 0;
+    }
+    st->id = oc->nb_streams-1;
+    c = st->codec;
+    c->codec_id = codec_id;
+    c->codec_type = AVMEDIA_TYPE_VIDEO;
+
+    /* put sample parameters */
+    c->bit_rate = encConfig.kbps * 1000;
+    /* resolution must be a multiple of two */
+    c->width = (encConfig.rotAngle==90||encConfig.rotAngle ==270)?encConfig.picHeight:encConfig.picWidth;
+    c->height = (encConfig.rotAngle==90||encConfig.rotAngle ==270)?encConfig.picWidth:encConfig.picHeight;
+
+    /* time base: this is the fundamental unit of time (in seconds) in terms
+    of which frame timestamps are represented. for fixed-fps content,
+    timebase should be 1/framerate and timestamp increments should be
+    identically 1. */
+    c->time_base.den = encConfig.container_frame_rate;
+    c->time_base.num = 1;
+
+    c->gop_size = gopSize; /* emit one intra frame every (gop_size)frames at most */
+
+    c->pix_fmt = PIX_FMT_YUV420P;
+    if (c->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
+        /* just for testing, we also add B frames */
+        c->max_b_frames = 2;
+    }
+    if (c->codec_id == AV_CODEC_ID_MPEG1VIDEO){
+        /* Needed to avoid using macroblocks in which some coeffs overflow.
+        This does not happen with normal video, it just happens here as
+        the motion of the chroma plane does not match the luma plane. */
+        c->mb_decision=2;
+    }
+    // some formats want stream headers to be separate
+    if(oc->oformat->flags & AVFMT_GLOBALHEADER)
+        c->flags |= CODEC_FLAG_GLOBAL_HEADER;
+
+    return st;
+}
+
+static int write_video_frame(AVFormatContext *oc, AVStream *st, unsigned char *addr, int size, int picType)
+{
+    int ret;
+    static struct SwsContext *img_convert_ctx;
+
+    /* if zero size, it means the image was buffered */
+    if (size > 0) {
+        AVPacket pkt;
+        av_init_packet(&pkt);
+
+        if (picType == 0)   //I Frame
+            pkt.flags |= AV_PKT_FLAG_KEY;
+        pkt.stream_index= st->index;
+        pkt.data= addr;
+        pkt.size= size;
+
+        /* write the compressed frame in the media file */
+        ret = av_interleaved_write_frame(oc, &pkt);
+    } 
+    else
+        ret = 0;
+
+    if (ret != 0) {
+        VLOG(ERR, "Error while writing video frame\n");
+        return 0;
+    }
+
+    return 1;
+}
+
+/*
+* make a file and write a container's header part
+* must set -> en_container, container_frame_rate, gopSize, kbps, rotAngle, picHeight, picWidth,
+*             stdMode and bitstreamFileName in struct EncConfigParam
+*/
+int container_init(EncConfigParam encConfig,
+    AVOutputFormat **fmt,
+    AVFormatContext **oc,
+    AVStream **video_st, 
+    int gopSize)
+{
+    int stdMode = encConfig.stdMode;
+    char *filename = encConfig.bitstreamFileName;
+    unsigned int i;
+
+    if (encConfig.ringBufferEnable == 1)
+    {
+        VLOG(ERR, "not supported format\n");
+        return 0;
+    }
+
+    /* initialize libavcodec, and register all codecs and formats */
+    av_register_all();
+
+    /* allocate the output media context */
+	if (avformat_open_input(oc, filename, NULL, NULL) < 0) {
+        fprintf(stderr, "failed to avformat_open_input\n");
+		return 0;
+    }
+
+    *fmt = (*oc)->oformat;
+
+    if (stdMode == 0)
+        (*fmt)->video_codec = AV_CODEC_ID_MPEG4;
+    else if (stdMode == 1)
+        (*fmt)->video_codec = AV_CODEC_ID_H263;
+    else if (stdMode == 2)
+        (*fmt)->video_codec = AV_CODEC_ID_H264;
+    else
+        VLOG(ERR, "unknown codec type = 0x%x\n", stdMode);
+
+    (*oc)->video_codec_id = (*fmt)->video_codec;
+    (*oc)->audio_codec_id = (*fmt)->audio_codec;
+
+    /* add the audio and video streams using the default format codecs
+    and initialize the codecs */
+    *video_st = add_stream(*oc, (int)(*fmt)->video_codec, encConfig, gopSize);
+
+    av_dump_format(*oc, 0, filename, 1);
+
+    /* open the output file, if needed */
+    if (avio_open(&(*oc)->pb, filename, AVIO_FLAG_WRITE) < 0) {
+        VLOG(ERR, "Could not open '%s'\n", filename);
+        for(i=0; i<(*oc)->nb_streams; i++) {
+            av_freep(&(*oc)->streams[i]->codec);
+            av_freep(&(*oc)->streams[i]);
+        }
+        /* free the stream */
+        av_free(*oc);
+        return 0;
+    }
+
+    /* write the stream header, if any */
+    if (avformat_write_header(*oc, NULL) < 0) {
+        VLOG(ERR, "Could not write header for output file (incorrect codec paramters ?)\n");
+        /* free the streams */
+        for(i=0; i<(*oc)->nb_streams; i++) {
+            av_freep(&(*oc)->streams[i]->codec);
+            av_freep(&(*oc)->streams[i]);
+        }
+
+        /* close the output file */
+        avio_close((*oc)->pb);
+
+        /* free the stream */
+        av_free(*oc);
+        *oc = NULL;
+        return 0;
+    }
+
+    return 1;
+}
+
+/*
+* save the header data to temp_buf(header_buf). (instead of ReadBsResetBufHelper)
+*/
+int container_copy_header_from_bitstream_buffer(const Uint32 core_idx,
+    const PhysicalAddress bitstream,
+    const int size,
+    const int endian,
+    char *buf,
+    int *pos)
+{
+    vdi_read_memory(core_idx, bitstream, (unsigned char *)(buf+(*pos)), size, endian);
+    *pos += size;
+
+    //to check memory boundary
+    if (*pos >= CONTAINER_HEADER_SIZE)
+    {
+        VLOG(ERR, "exceed header buffer, header buffer size[%d]\n", *pos);
+        return 0;
+    }
+    return 1;
+}
+
+/*
+* write the Element stream data with syntax header to the container file
+*/
+int container_write_es(const Uint32 core_idx,
+    const PhysicalAddress bitstream,
+    const int size,
+    const int endian,
+    AVFormatContext *oc, 
+    AVStream *st,
+    char *header_buffer,
+    int *header_pos,
+    int format, 
+    int picType)
+{
+    unsigned char *buf = osal_malloc(size);
+
+    if (!buf)
+    {
+        VLOG(ERR, "fail to allocate bitstream buffer\n");
+        return 0;
+    }
+    vdi_read_memory(core_idx, bitstream, buf, size, endian);
+
+    //video data = write only 1 SPS & PPS data in the file, 
+    //JPEG = copy jpeg header to every chunk in the file
+    if (*header_pos)//I Frame || MJPEG
+    {
+        unsigned char *buf2 = osal_malloc(size + *header_pos);
+
+        osal_memcpy(buf2, header_buffer, *header_pos);
+        osal_memcpy(buf2 + *header_pos, buf, size);
+
+        write_video_frame(oc, st, buf2,size + *header_pos, picType);
+
+        osal_free(buf2);
+
+        //to write a header to the first chunk just one time in container except JPEG
+        if ( format != 8 ) //(format != MJPEG)
+            *header_pos = 0;
+    }
+    else
+        write_video_frame(oc, st, buf, size, picType);
+
+    osal_free(buf);
+
+    return 1;
+}
+
+int container_deinit(AVFormatContext *oc)
+{
+    unsigned int i;
+
+    if (!oc || !oc->pb)
+        return 0;
+
+    /* write the trailer, if any.  the trailer must be written
+    * before you close the CodecContexts open when you wrote the
+    * header; otherwise write_trailer may try to use memory that
+    * was freed on av_codec_close() */
+    av_write_trailer(oc);
+
+    /* free the streams */
+    for(i=0; i<oc->nb_streams; i++) {
+        av_freep(&oc->streams[i]->codec);
+        av_freep(&oc->streams[i]);
+    }
+
+    /* close the output file */
+    avio_close(oc->pb);
+
+    /* free the stream */
+    av_free(oc);
+
+    return 1;
+}
+
+#endif /* SUPPORT_FFMPEG_DEMUX */
+
+ 

+ 211 - 0
wave420l/code/sample/helper/misc/datastructure.c

@@ -0,0 +1,211 @@
+//--=========================================================================--
+//  This file is a part of VPU Reference API project
+//-----------------------------------------------------------------------------
+//
+//       This confidential and proprietary software may be used only
+//     as authorized by a licensing agreement from Chips&Media Inc.
+//     In the event of publication, the following notice is applicable:
+//
+//            (C) COPYRIGHT 2006 - 2013  CHIPS&MEDIA INC.
+//                      ALL RIGHTS RESERVED
+//
+//       The entire notice above must be reproduced on all authorized
+//       copies.
+//
+//--=========================================================================--
+
+#include "main_helper.h"
+
+Queue* Queue_Create(
+    Uint32      itemCount,
+    Uint32      itemSize
+    )
+{
+    Queue* queue = NULL; 
+
+    if ((queue=(Queue *)osal_malloc(sizeof(Queue))) == NULL)
+        return NULL;
+    queue->size   = itemCount;
+    queue->itemSize = itemSize;
+    queue->count  = 0;
+    queue->front  = 0;
+    queue->rear   = 0;
+    queue->buffer = (Uint8*)osal_malloc(itemCount*itemSize);
+    queue->lock = NULL;
+
+    return queue;
+}
+
+Queue* Queue_Create_With_Lock(
+    Uint32      itemCount,
+    Uint32      itemSize
+    )
+{
+    Queue* queue = NULL; 
+
+    if ((queue=(Queue *)osal_malloc(sizeof(Queue))) == NULL)
+        return NULL;
+    queue->size   = itemCount;
+    queue->itemSize = itemSize;
+    queue->count  = 0;
+    queue->front  = 0;
+    queue->rear   = 0;
+    queue->buffer = (Uint8*)osal_malloc(itemCount*itemSize);
+    queue->lock = VpuMutex_Create();
+
+    return queue;
+}
+
+void Queue_Destroy(
+    Queue*      queue
+    )
+{
+    if (queue == NULL) 
+        return;
+
+    if (queue->buffer)
+        osal_free(queue->buffer);
+    if (queue->lock)
+        VpuMutex_Destroy(queue->lock);
+    osal_free(queue);
+}
+
+BOOL Queue_Enqueue(
+    Queue*      queue, 
+    void*       data
+    )
+{
+    Uint8*      ptr;
+    Uint32      offset;
+
+    if (queue == NULL) return FALSE;
+
+    /* Queue is full */
+    if (queue->count == queue->size) 
+        return -1;
+
+    if (queue->lock)
+        VpuMutex_Lock(queue->lock);
+    offset = queue->rear * queue->itemSize;
+
+    ptr = &queue->buffer[offset];
+    osal_memcpy(ptr, data, queue->itemSize);
+    queue->rear++;
+    queue->rear %= queue->size;
+    queue->count++;
+    if (queue->lock)
+        VpuMutex_Unlock(queue->lock);
+
+    return TRUE;
+}
+
+void* Queue_Dequeue(
+    Queue*      queue
+    )
+{
+    void* data;
+    Uint32   offset;
+
+    if (queue == NULL) 
+        return NULL;
+    /* Queue is empty */
+    if (queue->count == 0) 
+        return NULL;
+    if (queue->lock)
+        VpuMutex_Lock(queue->lock);
+    offset = queue->front * queue->itemSize;
+    data   = (void*)&queue->buffer[offset];
+    queue->front++;
+    queue->front %= queue->size;
+    queue->count--;
+    if (queue->lock)
+        VpuMutex_Unlock(queue->lock);
+    return data;
+}
+
+void Queue_Flush(
+    Queue*      queue
+    )
+{
+    if (queue == NULL) 
+        return;
+    if (queue->lock)
+        VpuMutex_Lock(queue->lock);
+    queue->count = 0;
+    queue->front = 0;
+    queue->rear  = 0;
+    if (queue->lock)
+        VpuMutex_Unlock(queue->lock);
+    return;
+}
+
+void* Queue_Peek(
+    Queue*      queue
+    )
+{
+    Uint32      offset;
+    void*       temp;
+
+    if (queue == NULL) 
+        return NULL;
+    /* Queue is empty */
+    if (queue->count == 0) 
+        return NULL;
+    if (queue->lock)
+        VpuMutex_Lock(queue->lock);
+    offset = queue->front * queue->itemSize;
+    temp = (void*)&queue->buffer[offset];
+    if (queue->lock)
+        VpuMutex_Unlock(queue->lock);
+    return  temp;
+}
+
+Uint32   Queue_Get_Cnt(
+    Queue*      queue
+    )
+{
+    Uint32      cnt;
+
+    if (queue == NULL) 
+        return 0;
+    if (queue->lock)
+        VpuMutex_Lock(queue->lock);
+    cnt = queue->count;
+    if (queue->lock)
+        VpuMutex_Unlock(queue->lock);
+    return cnt;
+}
+
+Queue* Queue_Copy(
+    Queue*  dstQ,
+    Queue*  srcQ
+    )
+{
+    Queue*   queue = NULL; 
+    Uint32   bufferSize;
+
+    if (dstQ == NULL) {
+        if ((queue=(Queue *)osal_malloc(sizeof(Queue))) == NULL)
+            return NULL;
+        osal_memset((void*)queue, 0x00, sizeof(Queue));
+    } 
+    else {
+        queue = dstQ;
+    }
+
+    bufferSize      = srcQ->size * srcQ->itemSize;
+    queue->size     = srcQ->size;
+    queue->itemSize = srcQ->itemSize;
+    queue->count    = srcQ->count;
+    queue->front    = srcQ->front;
+    queue->rear     = srcQ->rear;
+    if (queue->buffer) {
+        osal_free(queue->buffer);
+    }
+    queue->buffer   = (Uint8*)osal_malloc(bufferSize);
+
+    osal_memcpy(queue->buffer, srcQ->buffer, bufferSize);
+
+    return queue;
+}
+

+ 1225 - 0
wave420l/code/sample/helper/misc/debug.c

@@ -0,0 +1,1225 @@
+//--=========================================================================--
+//  This file is a part of VPU Reference API project
+//-----------------------------------------------------------------------------
+//
+//       This confidential and proprietary software may be used only
+//     as authorized by a licensing agreement from Chips&Media Inc.
+//     In the event of publication, the following notice is applicable:
+//
+//            (C) COPYRIGHT CHIPS&MEDIA INC.
+//                      ALL RIGHTS RESERVED
+//
+//       The entire notice above must be reproduced on all authorized
+//       copies.
+//
+//--=========================================================================--
+#include "config.h"
+#include <stdio.h>
+#include <assert.h>
+#include <string.h>
+#include <time.h>
+#include "wave/common/common_regdefine.h"
+#include "wave/wave4/wave4_regdefine.h"
+#include "wave/wave5/wave5_regdefine.h"
+#include "wave/wave5/wave5.h"
+#include "coda9/coda9_regdefine.h"
+#include "wave/common/common_vpuconfig.h"
+#if defined(PLATFORM_LINUX) || defined(PLATFORM_QNX)
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <unistd.h>
+#include <time.h>
+#endif
+#include "main_helper.h"
+#include "misc/debug.h"
+
+enum { False, True };
+
+void InitializeDebugEnv(
+    Uint32  productId,
+    Uint32  options
+    )
+{
+    UNREFERENCED_PARAMETER(productId);
+}
+
+void ReleaseDebugEnv(
+    void
+    )
+{
+}
+
+
+static void	DisplayVceEncDebugCommon(int core_idx, int vcore_idx, int set_mode, int debug0, int debug1, int debug2)
+{
+    int reg_val;
+    VLOG(ERR, "---------------Common Debug INFO-----------------\n");
+
+    WriteRegVCE(core_idx,vcore_idx, set_mode,0 );
+
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug0);
+    VLOG(ERR,"\t- pipe_on       :  0x%x\n", ((reg_val >> 8) & 0xf));
+    VLOG(ERR,"\t- cur_pipe      :  0x%x\n", ((reg_val >> 12) & 0xf));
+    VLOG(ERR,"\t- cur_s2ime     :  0x%x\n", ((reg_val >> 16) & 0xf));
+    VLOG(ERR,"\t- cur_s2cache   :  0x%x\n", ((reg_val >> 20) & 0x7));
+    VLOG(ERR,"\t- subblok_done  :  0x%x\n", ((reg_val >> 24) & 0x7f));
+
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug1);
+    VLOG(ERR,"\t- subblok_done  :  SFU 0x%x LF 0x%x RDO 0x%x IMD 0x%x FME 0x%x IME 0x%x\n", ((reg_val >> 5) & 0x1), ((reg_val >> 4) & 0x1), ((reg_val >> 3) & 0x1), ((reg_val >> 2) & 0x1), ((reg_val >> 1) & 0x1), ((reg_val >> 0) & 0x1));
+    VLOG(ERR,"\t- pipe_on       :  0x%x\n", ((reg_val >> 8) & 0xf));
+    VLOG(ERR,"\t- cur_pipe      :  0x%x\n", ((reg_val >> 12) & 0xf));
+    VLOG(ERR,"\t- cur_s2cache   :  0x%x\n", ((reg_val >> 16) & 0x7));
+    VLOG(ERR,"\t- cur_s2ime     :  0x%x\n", ((reg_val >> 24) & 0xf));
+
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug2);
+    VLOG(ERR,"\t- main_ctu_ypos :  0x%x\n", ((reg_val >> 0) & 0xff));
+    VLOG(ERR,"\t- main_ctu_xpos :  0x%x\n", ((reg_val >> 8) & 0xff));
+    VLOG(ERR,"\t- o_prp_ctu_ypos:  0x%x\n", ((reg_val >> 16) & 0xff));
+    VLOG(ERR,"\t- o_prp_ctu_xpos:  0x%x\n", ((reg_val >> 24) & 0xff));
+
+    SetClockGate(0, 1);
+    reg_val  = vdi_fio_read_register(core_idx, W4_GDI_VCORE0_BUS_STATUS);
+    VLOG(ERR,"\t- =========== GDI_BUS_STATUS ==========  \n");
+    VLOG(ERR,"\t- pri_bus_busy:  0x%x\n", ((reg_val >> 0) & 0x1));
+    VLOG(ERR,"\t- sec_bus_busy:  0x%x\n", ((reg_val >> 16) & 0x1));
+    reg_val= VpuReadReg(core_idx, W4_RET_ENC_PIC_TYPE);
+    VLOG(ERR,"[DEBUG] ret_core1_init : %d\n", (reg_val >> 16) & 0x3ff);
+    reg_val = VpuReadReg(core_idx, W4_RET_ENC_PIC_FLAG);
+    VLOG(ERR,"[DEBUG] ret_core0_init : %d\n", (reg_val >> 5) & 0x3ff);
+    SetClockGate(0, 0);
+    VLOG(ERR, "\n");
+    VLOG(ERR, "\n");
+    VLOG(ERR, "\n");
+    VLOG(ERR, "\n");
+}
+
+static void	DisplayVceEncDebugDCI(int core_idx, int vcore_idx, int set_mode, int* debug)
+{
+    int reg_val;
+    VLOG(ERR,"----------- MODE 0 : DCI DEBUG INFO----------\n");
+
+    WriteRegVCE(core_idx,vcore_idx, set_mode,0 );
+
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[3]);
+    VLOG(ERR,"\t- i_cnt_dci_rd_tuh       :  0x%x\n", ((reg_val >> 16) & 0xffff));
+    VLOG(ERR,"\t- i_cnt_dci_wd_tuh       :  0x%x\n", ((reg_val >>  0) & 0xffff));
+
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[4]);
+    VLOG(ERR,"\t- i_cnt_dci_rd_cu        :  0x%x\n", ((reg_val >> 16) & 0xffff));
+    VLOG(ERR,"\t- i_cnt_dci_wd_cu        :  0x%x\n", ((reg_val >>  0) & 0xffff));
+
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[5]);
+    VLOG(ERR,"\t- i_cnt_dci_rd_ctu       :  0x%x\n", ((reg_val >> 16) & 0xffff));
+    VLOG(ERR,"\t- i_cnt_dci_2d_ctu       :  0x%x\n", ((reg_val >>  0) & 0xffff));
+
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[6]);
+    VLOG(ERR,"\t- i_cnt_dci_rd_coef      :  0x%x\n", ((reg_val >> 16) & 0xffff));
+    VLOG(ERR,"\t- i_cnt_dci_wd_coef      :  0x%x\n", ((reg_val >>  0) & 0xffff));
+
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[7]);
+    VLOG(ERR,"\t- i_dci_full_empty_flag  :  0x%x\n", reg_val);
+
+    VLOG(ERR,"----------- MODE 0 : VCE_CTRL DEBUG INFO----------\n");
+    // HW_PARAM
+    reg_val = ReadRegVCE(core_idx, vcore_idx, 0x0b08);
+    VLOG(ERR,"\t- r_cnt_enable           :  0x%x\n", (reg_val >> 8) & 0x1);
+    VLOG(ERR,"\t- r_pic_done_sel         :  0x%x\n", (reg_val >> 9) & 0x1);
+
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[8]);
+    VLOG(ERR,"\t- vce_cnt                :  0x%x\n", reg_val);
+
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[8]);
+    VLOG(ERR,"\t- prp_cnt                :  0x%x\n", reg_val);
+    VLOG(ERR, "\n");
+    VLOG(ERR, "\n");
+    VLOG(ERR, "\n");
+    VLOG(ERR, "\n");
+}
+
+static void	DisplayVceEncDebugRDO(int core_idx, int vcore_idx, int set_mode, int* debug)
+{
+    int reg_val;
+    int reg_val_sub;
+
+    VLOG(ERR,"----------- MODE 1 : RDO DEBUG INFO ----------\n");
+
+    WriteRegVCE(core_idx,vcore_idx, set_mode,1 );
+
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[3]);
+    VLOG(ERR,"\t- o_rdo_cu_root_cb                    :  0x%x\n", ((reg_val >>  0) & 0x1));
+    VLOG(ERR,"\t- o_rdo_tu_cbf_y                      :  0x%x\n", ((reg_val >>  1) & 0x1));
+    VLOG(ERR,"\t- o_rdo_tu_cbf_u                      :  0x%x\n", ((reg_val >>  2) & 0x1));
+    VLOG(ERR,"\t- o_rdo_tu_cbf_v                      :  0x%x\n", ((reg_val >>  3) & 0x1));
+    VLOG(ERR,"\t- w_rdo_wdma_wait                     :  0x%x\n", ((reg_val >>  4) & 0x1));
+    VLOG(ERR,"\t- |o_rdo_tu_sb_luma_csbf[63: 0]       :  0x%x\n", ((reg_val >>  5) & 0x1));
+    VLOG(ERR,"\t- |o_rdo_tu_sb_chro_csbf[31:16]       :  0x%x\n", ((reg_val >>  6) & 0x1));
+    VLOG(ERR,"\t- |o_rdo_tu_sb_chro_csbf[15: 0]       :  0x%x\n", ((reg_val >>  7) & 0x1));
+    VLOG(ERR,"\t- o_sub_ctu_coe_ready                 :  0x%x\n", ((reg_val >>  8) & 0x1));
+    VLOG(ERR,"\t- o_sub_ctu_rec_ready                 :  0x%x\n", ((reg_val >>  9) & 0x1));
+    VLOG(ERR,"\t- o_rdo_wdma_busy                     :  0x%x\n", ((reg_val >> 10) & 0x1));
+    VLOG(ERR,"\t- w_rdo_rdma_wait                     :  0x%x\n", ((reg_val >> 11) & 0x1));
+    VLOG(ERR,"\t- o_log2_cu_size[07:06]               :  0x%x\n", ((reg_val >> 12) & 0x3));
+    VLOG(ERR,"\t- o_log2_cu_size[15:14]               :  0x%x\n", ((reg_val >> 14) & 0x3));
+    VLOG(ERR,"\t- o_log2_cu_size[23:22]               :  0x%x\n", ((reg_val >> 16) & 0x3));
+    VLOG(ERR,"\t- o_log2_cu_size[31:30]               :  0x%x\n", ((reg_val >> 18) & 0x3));
+    VLOG(ERR,"\t- o_rdo_dbk_valid                     :  0x%x\n", ((reg_val >> 20) & 0x1));
+
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[4]);
+    VLOG(ERR,"\t- debug_status_ctrl                   :  0x%x\n", ((reg_val >>  0) & 0xff));
+    reg_val_sub = (reg_val >>  0) & 0xff; 
+    VLOG(ERR,"\t- debug_status_ctrl.fsm_main_cur      :  0x%x\n", ((reg_val_sub >>  0) & 0x7));
+    VLOG(ERR,"\t- debug_status_ctrl.i_rdo_wdma_wait   :  0x%x\n", ((reg_val_sub >>  3) & 0x1));
+    VLOG(ERR,"\t- debug_status_ctrl.fsm_cu08_cur      :  0x%x\n", ((reg_val_sub >>  4) & 0x7));
+    VLOG(ERR,"\t- debug_status_ctrl.init_hold         :  0x%x\n", ((reg_val_sub >>  7) & 0x1));
+
+    VLOG(ERR,"\t- debug_status_nb                     :  0x%x\n", ((reg_val >>  8) & 0xff));
+    reg_val_sub =(reg_val >>  8) & 0xff; 
+    VLOG(ERR,"\t- debug_status_nb.fsm_save_cur        :  0x%x\n", ((reg_val_sub >>  0) & 0x7));
+    VLOG(ERR,"\t- debug_status_nb.fsm_load_cur        :  0x%x\n", ((reg_val_sub >>  4) & 0x7));
+
+    VLOG(ERR,"\t- debug_status_rec                    :  0x%x\n", ((reg_val >> 16) & 0xf));
+    reg_val_sub = (reg_val >> 16) & 0xf; 
+    VLOG(ERR,"\t- debug_status_rec.fsm_obuf_cur       :  0x%x\n", ((reg_val_sub >>  0) & 0x7));
+
+    VLOG(ERR,"\t- debug_status_coe                    :  0x%x\n", ((reg_val >> 20) & 0xf));
+    reg_val_sub = (reg_val >> 20) & 0xf; 
+    VLOG(ERR,"\t- debug_status_coe.fsm_obuf_cur       :  0x%x\n", ((reg_val_sub >> 0) & 0x7));
+
+    VLOG(ERR,"\t- debug_status_para                   :  0x%x\n", ((reg_val >> 24) & 0xff));
+    reg_val_sub = (reg_val >> 24) & 0xff; 
+    VLOG(ERR,"\t- debug_status_para.cur_sfu_rd_state  :  0x%x\n", ((reg_val_sub >> 0) & 0xf));
+    VLOG(ERR,"\t- debug_status_para.cur_para_state    :  0x%x\n", ((reg_val_sub >> 4) & 0xf));
+
+    VLOG(ERR, "\n");
+    VLOG(ERR, "\n");
+    VLOG(ERR, "\n");
+    VLOG(ERR, "\n");
+}
+
+static void	DisplayVceEncDebugLF(int core_idx, int vcore_idx, int set_mode, int* debug)
+{
+    int reg_val;
+    VLOG(ERR,"----------- MODE 2 : LF DEBUG INFO----------\n");
+
+    WriteRegVCE(core_idx,vcore_idx, set_mode,2 );
+
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[3]);
+
+    VLOG(ERR,"\t- cur_enc_main_state   : 0x%x \n", (reg_val>>27)&0x1F);
+    VLOG(ERR,"\t- i_sao_para_valie     : 0x%x \n", (reg_val>>26)&0x1);
+    VLOG(ERR,"\t- i_sao_fetch_done     : 0x%x \n", (reg_val>>25)&0x1);
+    VLOG(ERR,"\t- i_global_encode_en   : 0x%x \n", (reg_val>>24)&0x1);
+    VLOG(ERR,"\t- i_bs_valid           : 0x%x \n", (reg_val>>23)&0x1);
+    VLOG(ERR,"\t- i_rec_buf_rdo_ready  : 0x%x \n", (reg_val>>22)&0x1);
+    VLOG(ERR,"\t- o_rec_buf_dbk_hold   : 0x%x \n", (reg_val>>21)&0x1);
+    VLOG(ERR,"\t- cur_main_state       : 0x%x \n", (reg_val>>16)&0x1F);
+    VLOG(ERR,"\t- r_lf_pic_dbk_disable : 0x%x \n", (reg_val>>15)&0x1);
+    VLOG(ERR,"\t- r_lf_pic_sao_disable : 0x%x \n", (reg_val>>14)&0x1);
+    VLOG(ERR,"\t- para_load_done       : 0x%x \n", (reg_val>>13)&0x1);
+    VLOG(ERR,"\t- i_rdma_ack_wait      : 0x%x \n", (reg_val>>12)&0x1);
+    VLOG(ERR,"\t- i_sao_intl_col_done  : 0x%x \n", (reg_val>>11)&0x1);
+    VLOG(ERR,"\t- i_sao_outbuf_full    : 0x%x \n", (reg_val>>10)&0x1);
+    VLOG(ERR,"\t- lf_sub_done          : 0x%x \n", (reg_val>>9)&0x1);
+    VLOG(ERR,"\t- i_wdma_ack_wait      : 0x%x \n", (reg_val>>8)&0x1);
+    VLOG(ERR,"\t- lf_all_sub_done      : 0x%x \n", (reg_val>>6)&0x1);
+    VLOG(ERR,"\t- cur_ycbcr            : 0x%x \n", (reg_val>>5)&0x3);
+    VLOG(ERR,"\t- sub8x8_done          : 0x%x \n", (reg_val>>0)&0xF);
+
+    VLOG(ERR,"----------- MODE 2 : SYNC_Y_POS DEBUG INFO----------\n");
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[4]);
+
+    VLOG(ERR,"\t- fbc_y_pos            : 0x%x \n", (reg_val>>0)&0xff);
+    VLOG(ERR,"\t- bwb_y_pos            : 0x%x \n", (reg_val>>16)&0xff);
+
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[5]);
+    VLOG(ERR,"\t- trace_frame		   :  0x%x\n", ((reg_val >> 0) & 0xffff));
+
+    VLOG(ERR, "\n");
+    VLOG(ERR, "\n");
+    VLOG(ERR, "\n");
+    VLOG(ERR, "\n");
+}
+
+static void	DisplayVceEncDebugSFU(int core_idx, int vcore_idx, int set_mode, int* debug)
+{
+    int reg_val;
+    VLOG(ERR,"----------- MODE 3 : SFU DEBUG INFO----------\n");
+
+    WriteRegVCE(core_idx,vcore_idx, set_mode,3 );
+
+    reg_val = ReadRegVCE(0, vcore_idx, debug[3]);
+    VLOG(ERR,"\t- i_sub_ctu_pos_y         : 0x%x \n", (reg_val>>0)&0xff);
+    VLOG(ERR,"\t- i_sub_ctu_pos_x         : 0x%x \n", (reg_val>>8)&0xff);
+    VLOG(ERR,"\t- i_cu_fifo_wvalid        : 0x%x \n", (reg_val>>16)&0x1);
+    VLOG(ERR,"\t- i_ctu_busy              : 0x%x \n", (reg_val>>20)&0x1);
+    VLOG(ERR,"\t- i_cs_sctu               : 0x%x \n", (reg_val>>24)&0x7);
+
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[4]);
+    VLOG(ERR,"\t- i_ctu_pos_y             : 0x%x \n", (reg_val>>0)&0xff);
+    VLOG(ERR,"\t- i_ctu_pos_x             : 0x%x \n", (reg_val>>8)&0xff);
+    VLOG(ERR,"\t- i_sao_rdo_valid         : 0x%x \n", (reg_val>>16)&0x1);
+    VLOG(ERR,"\t- i_sao_en_r              : 0x%x \n", (reg_val>>20)&0x1);
+    VLOG(ERR,"\t- i_ctu_fifo_wvalid       : 0x%x \n", (reg_val>>24)&0x1);
+    VLOG(ERR,"\t- cs_sfu_ctu              : 0x%x \n", (reg_val>>28)&0x3);
+
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[5]);
+    VLOG(ERR,"\t- i_cu_fifo_wvalid        : 0x%x \n", (reg_val>>0)&0x1);
+    VLOG(ERR,"\t- i_rdo_cu_rd_valid       : 0x%x \n", (reg_val>>4)&0x1);
+    VLOG(ERR,"\t- i_cu_size_r             : 0x%x \n", (reg_val>>8)&0x3);
+    VLOG(ERR,"\t- i_cu_idx_r              : 0x%x \n", (reg_val>>12)&0xf);
+    VLOG(ERR,"\t- cs_cu                   : 0x%x \n", (reg_val>>16)&0x7);
+    VLOG(ERR,"\t- cs_fifo                 : 0x%x \n", (reg_val>>20)&0x7);
+
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[6]);
+    VLOG(ERR,"\t- w_dbg_tu_fifo_fsm       : 0x%x \n", (reg_val>>0)&0xff);
+    VLOG(ERR,"\t- i_coff_fifo_wvalid      : 0x%x \n", (reg_val>>8)&0x1);
+    VLOG(ERR,"\t- i_tuh_fifo_wvalid       : 0x%x \n", (reg_val>>12)&0x1);
+    VLOG(ERR,"\t- w_dbg_tu_ctrl_fsm       : 0x%x \n", (reg_val>>16)&0xf);
+    VLOG(ERR,"\t- i_rdo_tc_ready          : 0x%x \n", (reg_val>>20)&0x1);
+    VLOG(ERR,"\t- w_dbg_coef_st_in_pic    : 0x%x \n", (reg_val>>24)&0x7);
+    VLOG(ERR,"\t- i_rdo_tu_rd-valid       : 0x%x \n", (reg_val>>28)&0x1);
+    VLOG(ERR, "\n");
+    VLOG(ERR, "\n");
+    VLOG(ERR, "\n");
+    VLOG(ERR, "\n");
+}
+
+static void	DisplayVceEncDebugDCI2(int core_idx, int vcore_idx, int set_mode, int* debug)
+{
+    int reg_val;
+    VLOG(ERR,"----------- MODE 4 : DCI2 DEBUG INFO----------\n");
+
+    WriteRegVCE(core_idx,vcore_idx, set_mode,4 );
+
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[3]);
+    VLOG(ERR,"\t- i_cnt_dci_rd_tuh2       : 0x%x \n", (reg_val>>16)&0xffff);
+    VLOG(ERR,"\t- i_cnt_dci_wd_tuh2       : 0x%x \n", (reg_val>> 0)&0xffff);
+
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[4]);
+    VLOG(ERR,"\t- i_cnt_dci_rd_cu2        : 0x%x \n", (reg_val>>16)&0xffff);
+    VLOG(ERR,"\t- i_cnt_dci_wd_cu2        : 0x%x \n", (reg_val>> 0)&0xffff);
+
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[5]);
+    VLOG(ERR,"\t- i_cnt_dci_rd_ctu2       : 0x%x \n", (reg_val>>16)&0xffff);
+    VLOG(ERR,"\t- i_cnt_dci_wd_ctu2       : 0x%x \n", (reg_val>> 0)&0xffff);
+
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[6]);
+    VLOG(ERR,"\t- i_cnt_dci_rd_coef2      : 0x%x \n", (reg_val>>16)&0xffff);
+    VLOG(ERR,"\t- i_cnt_dci_wd_coef2      : 0x%x \n", (reg_val>> 0)&0xffff);
+
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[7]);
+    VLOG(ERR,"\t- i_dci_full_empty_flag   : 0x%x \n", reg_val);
+    VLOG(ERR, "\n");
+    VLOG(ERR, "\n");
+    VLOG(ERR, "\n");
+    VLOG(ERR, "\n");
+}
+
+static void	DisplayVceEncDebugDCILast(int core_idx, int vcore_idx, int set_mode, int* debug)
+{
+    int reg_val;
+    VLOG(ERR,"----------- MODE 5 : DCI LAST DEBUG INFO----------\n");
+
+    WriteRegVCE(core_idx,vcore_idx, set_mode,5 );
+
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[3]);
+    VLOG(ERR,"\t- i_cnt_dci_last_rdata[143:112]    : 0x%x \n", reg_val);
+
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[4]);
+    VLOG(ERR,"\t- i_cnt_dci_last_rdata[111: 96]    : 0x%x \n", reg_val & 0xffff);
+
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[5]);
+    VLOG(ERR,"\t- i_cnt_dci_last_rdata[ 95: 64]    : 0x%x \n", reg_val);
+
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[6]);
+    VLOG(ERR,"\t- i_cnt_dci_last_rdata[ 63: 32]    : 0x%x \n", reg_val);
+
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[7]);
+    VLOG(ERR,"\t- i_cnt_dci_last_rdata[ 31:  0]    : 0x%x \n", reg_val);
+
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[8]);
+    VLOG(ERR,"\t- i_wr_read_point                  : 0x%x \n", (reg_val >> 16) & 0x7ff );
+    VLOG(ERR,"\t- i_wr_read_point_limit            : 0x%x \n", (reg_val >>  0) & 0x7ff );
+
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[9]);
+    VLOG(ERR,"\t- i_sbuf_raddr_store               : 0x%x \n", (reg_val >>  0) & 0x3f );
+    VLOG(ERR,"\t- i_read_point                     : 0x%x \n", (reg_val >>  8) & 0x1f );
+    VLOG(ERR,"\t- i_dci_write_addr_b               : 0x%x \n", (reg_val >> 16) & 0x3f );
+    VLOG(ERR,"\t- i_dci_write_addr_c               : 0x%x \n", (reg_val >> 24) & 0x1f );
+    VLOG(ERR, "\n");
+    VLOG(ERR, "\n");
+    VLOG(ERR, "\n");
+    VLOG(ERR, "\n");
+}
+
+static void	DisplayVceEncDebugBigBufferCnt(int core_idx, int vcore_idx, int set_mode, int* debug)
+{
+    int reg_val;
+    VLOG(ERR,"----------- MODE 6 : BIG BUFFER CNT DEBUG INFO----------\n");
+
+    WriteRegVCE(core_idx,vcore_idx, set_mode,6 );
+
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[3]);
+    VLOG(ERR,"\t- i_cnt_bbuf_read_tuh    : 0x%x \n", (reg_val >> 16) & 0xffff);
+    VLOG(ERR,"\t- i_cnt_bbuf_write_tuh   : 0x%x \n", (reg_val >>  0) & 0xffff);
+
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[4]);
+    VLOG(ERR,"\t- i_cnt_bbuf_read_cu     : 0x%x \n", (reg_val >> 16) & 0xffff);
+    VLOG(ERR,"\t- i_cnt_bbuf_write_cu    : 0x%x \n", (reg_val >>  0) & 0xffff);
+
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[5]);
+    VLOG(ERR,"\t- i_cnt_bbuf_read_coef   : 0x%x \n", (reg_val >> 16) & 0xffff);
+    VLOG(ERR,"\t- i_cnt_bbuf_write_coef  : 0x%x \n", (reg_val >>  0) & 0xffff);
+
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[6]);
+    VLOG(ERR,"\t- i_cnt_sbuf_read_tuh    : 0x%x \n", (reg_val >> 16) & 0xffff);
+    VLOG(ERR,"\t- i_cnt_sbuf_write_tuh   : 0x%x \n", (reg_val >>  0) & 0xffff);
+
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[7]);
+    VLOG(ERR,"\t- i_cnt_sbuf_read_cu     : 0x%x \n", (reg_val >> 16) & 0xffff);
+    VLOG(ERR,"\t- i_cnt_sbuf_write_cu    : 0x%x \n", (reg_val >>  0) & 0xffff);
+
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[8]);
+    VLOG(ERR,"\t- i_cnt_sbuf_read_ctu    : 0x%x \n", (reg_val >> 16) & 0xffff);
+    VLOG(ERR,"\t- i_cnt_sbuf_write_tcu   : 0x%x \n", (reg_val >>  0) & 0xffff);
+
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[9]);
+    VLOG(ERR,"\t- i_cnt_sbuf_read_coef   : 0x%x \n", (reg_val >> 16) & 0xffff);
+    VLOG(ERR,"\t- i_cnt_sbuf_write_coef  : 0x%x \n", (reg_val >>  0) & 0xffff);
+    VLOG(ERR, "\n");
+    VLOG(ERR, "\n");
+    VLOG(ERR, "\n");
+    VLOG(ERR, "\n");
+}
+
+static void	DisplayVceEncDebugBigBufferAddr(int core_idx, int vcore_idx, int set_mode, int* debug)
+{
+    int reg_val;
+    VLOG(ERR,"----------- MODE 6 : BIG BUFFER ADDR DEBUG INFO----------\n");
+
+    WriteRegVCE(core_idx,vcore_idx, set_mode,7 );
+
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[3]);
+    VLOG(ERR,"\t- i_cnt_bbuf_raddr_read_tuh    : 0x%x \n", (reg_val >> 16) & 0x7ff);
+    VLOG(ERR,"\t- i_cnt_bbuf_raddr_write_tuh   : 0x%x \n", (reg_val >>  0) & 0x7ff);
+
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[4]);
+    VLOG(ERR,"\t- i_cnt_bbuf_raddr_read_cu     : 0x%x \n", (reg_val >> 16) & 0x1ff);
+    VLOG(ERR,"\t- i_cnt_bbuf_raddr_write_cu    : 0x%x \n", (reg_val >>  0) & 0x1ff);
+
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[5]);
+    VLOG(ERR,"\t- i_cnt_bbuf_raddr_read_coef   : 0x%x \n", (reg_val >> 16) & 0xfff);
+    VLOG(ERR,"\t- i_cnt_bbuf_raddr_write_coef  : 0x%x \n", (reg_val >>  0) & 0xfff);
+
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[6]);
+    VLOG(ERR,"\t- i_cnt_sbuf_raddr_read_tuh    : 0x%x \n", (reg_val >> 16) & 0x1f);
+    VLOG(ERR,"\t- i_cnt_sbuf_raddr_write_tuh   : 0x%x \n", (reg_val >>  0) & 0x1f);
+
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[7]);
+    VLOG(ERR,"\t- i_cnt_sbuf_raddr_read_cu     : 0x%x \n", (reg_val >> 16) & 0x1f);
+    VLOG(ERR,"\t- i_cnt_sbuf_raddr_write_cu    : 0x%x \n", (reg_val >>  0) & 0x1f);
+
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[8]);
+    VLOG(ERR,"\t- i_cnt_sbuf_raddr_read_ctu    : 0x%x \n", (reg_val >> 16) & 0x1f);
+    VLOG(ERR,"\t- i_cnt_sbuf_raddr_write_tcu   : 0x%x \n", (reg_val >>  0) & 0x1f);
+
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[9]);
+    VLOG(ERR,"\t- i_cnt_sbuf_raddr_read_coef   : 0x%x \n", (reg_val >> 16) & 0x1f);
+    VLOG(ERR,"\t- i_cnt_sbuf_raddr_write_coef  : 0x%x \n", (reg_val >>  0) & 0x1f);
+    VLOG(ERR, "\n");
+    VLOG(ERR, "\n");
+    VLOG(ERR, "\n");
+    VLOG(ERR, "\n");
+}
+
+static void	DisplayVceEncDebugSubWb(int core_idx, int vcore_idx, int set_mode, int* debug)
+{
+    int reg_val;
+    VLOG(ERR,"----------- MODE 7 : SUB_WB DEBUG INFO----------\n");
+
+    WriteRegVCE(core_idx,vcore_idx, set_mode,8 );
+
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[3]);
+    VLOG(ERR,"\t- subwb_debug_0              : 0x%x \n", reg_val);
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[4]);
+    VLOG(ERR,"\t- subwb_debug_1              : 0x%x \n", reg_val);
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[5]);
+    VLOG(ERR,"\t- subwb_debug_2              : 0x%x \n", reg_val);
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[6]);
+    VLOG(ERR,"\t- subwb_debug_3              : 0x%x \n", reg_val);
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[7]);
+    VLOG(ERR,"\t- subwb_debug_4              : 0x%x \n", reg_val);
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[8]);
+    VLOG(ERR,"\t- int_sync_ypos              : 0x%x \n", reg_val);
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[9]);
+    VLOG(ERR,"\t- pic_run_cnt                : 0x%x \n", ((reg_val) >> 0) & 0xffff);
+    VLOG(ERR,"\t- pic_init_ct                : 0x%x \n", ((reg_val) >> 16) & 0xffff);
+
+    VLOG(ERR, "\n");
+    VLOG(ERR, "\n");
+    VLOG(ERR, "\n");
+    VLOG(ERR, "\n");
+}
+
+static void	DisplayVceEncDebugFBC(int core_idx, int vcore_idx, int set_mode, int* debug)
+{
+    int reg_val;
+    VLOG(ERR,"----------- MODE 8 : FBC DEBUG INFO----------\n");
+
+    WriteRegVCE(core_idx,vcore_idx, set_mode,9 );
+
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[3]);
+    VLOG(ERR,"\t- ofs_request_count            : 0x%x \n", reg_val);
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[4]);
+    VLOG(ERR,"\t- ofs_bvalid_count             : 0x%x \n", reg_val);
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[5]);
+    VLOG(ERR,"\t- dat_request_count            : 0x%x \n", reg_val);
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[6]);
+    VLOG(ERR,"\t- dat_bvalid_count             : 0x%x \n", reg_val);
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[7]);
+    VLOG(ERR,"\t- fbc_debug                    : 0x%x \n", ((reg_val) >> 0) &  0x3FFFFFFF);
+    VLOG(ERR,"\t- fbc_cr_idle_3d               : 0x%x \n", ((reg_val) >> 30) & 0x1);
+    VLOG(ERR,"\t- fbc_cr_busy_3d               : 0x%x \n", ((reg_val) >> 31) & 0x1);
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[8]);
+    VLOG(ERR,"\t- outbuf_debug                 : 0x%x \n", reg_val);
+    reg_val = ReadRegVCE(core_idx, vcore_idx, debug[9]);
+    VLOG(ERR,"\t- fbcif_debug                  : 0x%x \n", reg_val);
+
+    VLOG(ERR, "\n");
+    VLOG(ERR, "\n");
+    VLOG(ERR, "\n");
+    VLOG(ERR, "\n");
+}
+
+#define VCORE_DBG_ADDR(__vCoreIdx)      0x8000+(0x1000*__vCoreIdx) + 0x300
+#define VCORE_DBG_DATA(__vCoreIdx)      0x8000+(0x1000*__vCoreIdx) + 0x304
+#define VCORE_DBG_READY(__vCoreIdx)     0x8000+(0x1000*__vCoreIdx) + 0x308
+Uint32 ReadRegVCE(
+    Uint32 core_idx,
+    Uint32 vce_core_idx,
+    Uint32 vce_addr
+    )
+{
+    int     vcpu_reg_addr;
+    int     udata;
+    int     vce_core_base = 0x8000 + 0x1000*vce_core_idx;
+
+    SetClockGate(core_idx, 1);
+    vdi_fio_write_register(core_idx, VCORE_DBG_READY(vce_core_idx), 0);
+
+    vcpu_reg_addr = vce_addr >> 2;
+
+    vdi_fio_write_register(core_idx, VCORE_DBG_ADDR(vce_core_idx),vcpu_reg_addr + vce_core_base);
+
+    if (vdi_fio_read_register(0, VCORE_DBG_READY(vce_core_idx)) == 1)
+        udata= vdi_fio_read_register(0, VCORE_DBG_DATA(vce_core_idx));
+    else {
+        VLOG(ERR, "failed to read VCE register: %d, 0x%04x\n", vce_core_idx, vce_addr);
+        udata = -2;//-1 can be a valid value
+    }
+
+    SetClockGate(core_idx, 0);
+    return udata;
+}
+
+void WriteRegVCE(
+    Uint32   core_idx,
+    Uint32   vce_core_idx,
+    Uint32   vce_addr,
+    Uint32   udata
+    )
+{
+    int vcpu_reg_addr;
+
+    SetClockGate(core_idx, 1);
+
+    vdi_fio_write_register(core_idx, VCORE_DBG_READY(vce_core_idx),0);
+
+    vcpu_reg_addr = vce_addr >> 2;
+
+    vdi_fio_write_register(core_idx, VCORE_DBG_DATA(vce_core_idx),udata);
+    vdi_fio_write_register(core_idx, VCORE_DBG_ADDR(vce_core_idx),(vcpu_reg_addr) & 0x00007FFF);
+
+    if (vdi_fio_read_register(0, VCORE_DBG_READY(vce_core_idx)) < 0) 
+        VLOG(ERR, "failed to write VCE register: 0x%04x\n", vce_addr);
+    SetClockGate(core_idx, 0);
+}
+
+void PrintVpuStatus(
+    Uint32 coreIdx, 
+    Uint32 productId
+    )
+{
+    SetClockGate(coreIdx, 1);
+    if (PRODUCT_ID_W_SERIES(productId))
+    {
+        int      rd, wr;
+        Uint32    tq, ip, mc, lf;
+        Uint32    avail_cu, avail_tu, avail_tc, avail_lf, avail_ip;
+        Uint32	 ctu_fsm, nb_fsm, cabac_fsm, cu_info, mvp_fsm, tc_busy, lf_fsm, bs_data, bbusy, fv;
+        Uint32    reg_val;
+        Uint32    index;
+        Uint32    vcpu_reg[31]= {0,};
+
+        VLOG(ERR,"-------------------------------------------------------------------------------\n");
+        VLOG(ERR,"------                            VCPU STATUS(DEC)                        -----\n");
+        VLOG(ERR,"-------------------------------------------------------------------------------\n");
+        rd = VpuReadReg(coreIdx, W4_BS_RD_PTR);
+        wr = VpuReadReg(coreIdx, W4_BS_WR_PTR);
+        VLOG(ERR,"RD_PTR: 0x%08x WR_PTR: 0x%08x BS_OPT: 0x%08x BS_PARAM: 0x%08x\n", 
+            rd, wr, VpuReadReg(coreIdx, W4_BS_OPTION), VpuReadReg(coreIdx, W4_BS_PARAM));
+
+        // --------- VCPU register Dump 
+        VLOG(ERR,"[+] VCPU REG Dump\n");
+        for (index = 0; index < 25; index++) {
+            VpuWriteReg (coreIdx, 0x14, (1<<9) | (index & 0xff));
+            vcpu_reg[index] = VpuReadReg (coreIdx, 0x1c);
+
+            if (index < 16) {
+                VLOG(ERR,"0x%08x\t",  vcpu_reg[index]);
+                if ((index % 4) == 3) VLOG(ERR,"\n");
+            }
+            else {
+                switch (index) {
+                case 16: VLOG(ERR,"CR0: 0x%08x\t", vcpu_reg[index]); break;
+                case 17: VLOG(ERR,"CR1: 0x%08x\n", vcpu_reg[index]); break;
+                case 18: VLOG(ERR,"ML:  0x%08x\t", vcpu_reg[index]); break;
+                case 19: VLOG(ERR,"MH:  0x%08x\n", vcpu_reg[index]); break;
+                case 21: VLOG(ERR,"LR:  0x%08x\n", vcpu_reg[index]); break;
+                case 22: VLOG(ERR,"PC:  0x%08x\n", vcpu_reg[index]);break;
+                case 23: VLOG(ERR,"SR:  0x%08x\n", vcpu_reg[index]);break;
+                case 24: VLOG(ERR,"SSP: 0x%08x\n", vcpu_reg[index]);break;
+                }
+            }
+        }
+
+        VLOG(ERR,"[-] VCPU REG Dump\n");
+        // --------- BIT register Dump 
+        VLOG(ERR,"[+] BPU REG Dump\n");
+        for (index=0;index < 30; index++)
+        {
+            int temp;
+            temp = vdi_fio_read_register(coreIdx, (W4_REG_BASE + 0x8000 + 0x18));
+            VLOG(ERR,"BITPC = 0x%08x\n", temp);
+            if ( temp == 0xffffffff)
+                return;
+        }
+        VLOG(ERR,"BIT START=0x%08x, BIT END=0x%08x\n", vdi_fio_read_register(coreIdx, (W4_REG_BASE + 0x8000 + 0x11c)), 
+            vdi_fio_read_register(coreIdx, (W4_REG_BASE + 0x8000 + 0x120)) );
+        if (productId == PRODUCT_ID_410 )
+            VLOG(ERR,"BIT COMMAND 0x%x\n", vdi_fio_read_register(coreIdx, (W4_REG_BASE + 0x8000 + 0x100))); 
+        if (productId == PRODUCT_ID_4102 || productId == PRODUCT_ID_510)
+            VLOG(ERR,"BIT COMMAND 0x%x\n", vdi_fio_read_register(coreIdx, (W4_REG_BASE + 0x8000 + 0x1FC))); 
+
+        //DECODER SDMA INFO
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16)| 0x120);
+        while((vdi_fio_read_register(0,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        reg_val = vdi_fio_read_register(0,(W4_REG_BASE + 0x8000 + 0x78));
+        VLOG(ERR,"C_SDMA_LOAD_CMD    = 0x%x\n",reg_val); 
+
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16)| 0x121);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        reg_val = vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78));
+        VLOG(ERR,"C_SDMA_AURO_MODE  = 0x%x\n",reg_val); 
+
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16)| 0x122);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        reg_val = vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78));
+        VLOG(ERR,"C_SDMA_BASE_ADDR  = 0x%x\n",reg_val); 
+
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16)| 0x123);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        reg_val = vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78));
+        VLOG(ERR,"C_SDMA_ENC_ADDR   = 0x%x\n",reg_val); 
+
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16)| 0x124);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        reg_val = vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78));
+        VLOG(ERR,"C_SDMA_ENDIAN     = 0x%x\n",reg_val); 
+
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16)| 0x125);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        reg_val = vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78));
+        VLOG(ERR,"C_SDMA_IRQ_CLEAR  = 0x%x\n",reg_val); 
+
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16)| 0x126);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        reg_val = vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78));
+        VLOG(ERR,"C_SDMA_BUSY       = 0x%x\n",reg_val); 
+
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16)| 0x127);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        reg_val = vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78));
+        VLOG(ERR,"C_SDMA_LAST_ADDR  = 0x%x\n",reg_val); 
+
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16)| 0x128);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        reg_val = vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78));
+        VLOG(ERR,"C_SDMA_SC_BASE_ADDR = 0x%x\n",reg_val); 
+
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16)| 0x129);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        reg_val = vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78));
+        VLOG(ERR,"C_SDMA_RD_SEL      = 0x%x\n",reg_val);
+
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16)| 0x130);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        reg_val = vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78));
+        VLOG(ERR,"C_SDMA_WR_SEL      = 0x%x\n",reg_val); 
+
+        //DECODER SHU INFO
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16)| 0x140);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        reg_val = vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78));
+        VLOG(ERR,"C_SHU_INIT         = 0x%x\n",reg_val); 
+
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16)| 0x141);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        reg_val = vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78));
+        VLOG(ERR,"C_SHU_SEEK_NXT_NAL = 0x%x\n",reg_val); 
+
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16)| 0x142);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        reg_val = vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78));
+        VLOG(ERR,"C_SHU_RD_NAL_ADDR  = 0x%x\n",reg_val); 
+
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16)| 0x143);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        reg_val = vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78));
+        VLOG(ERR,"C_SHU_STATUS       = 0x%x\n",reg_val); 
+
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16)| 0x144);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        reg_val = vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78));
+        VLOG(ERR,"C_SHU_GBYTE0       = 0x%x\n",reg_val); 
+
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16)| 0x145);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        reg_val = vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78));
+        VLOG(ERR,"C_SHU_GBYTE1       = 0x%x\n",reg_val); 
+
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16)| 0x146);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        reg_val = vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78));
+        VLOG(ERR,"C_SHU_GBYTE2       = 0x%x\n",reg_val); 
+
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16)| 0x147);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        reg_val = vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78));
+        VLOG(ERR,"C_SHU_GBYTE3       = 0x%x\n",reg_val); 
+
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16)| 0x148);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        reg_val = vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78));
+        VLOG(ERR,"C_SHU_GBYTE4       = 0x%x\n",reg_val); 
+
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16)| 0x14C);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        reg_val = vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78));
+        VLOG(ERR,"C_SHU_SBYTE_LOW   = 0x%x\n",reg_val); 
+
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16)| 0x14D);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        reg_val = vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78));
+        VLOG(ERR,"C_SHU_SBYTE_HIGH  = 0x%x\n",reg_val); 
+
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16)| 0x14E);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        reg_val = vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78));
+        VLOG(ERR,"C_SHU_ST_PAT_DIS  = 0x%x\n",reg_val); 
+
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16)| 0x150);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        reg_val = vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78));
+        VLOG(ERR,"C_SHU_NBUF0      = 0x%x\n",reg_val); 
+
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16)| 0x151);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        reg_val = vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78));
+        VLOG(ERR,"C_SHU_NBUF1      	= 0x%x\n",reg_val); 
+
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16)| 0x152);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        reg_val = vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78));
+        VLOG(ERR,"C_SHU_NBUF2      	= 0x%x\n",reg_val); 
+
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16)| 0x153);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        reg_val = vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78));
+        VLOG(ERR,"C_SHU_NBUF3      	= 0x%x\n",reg_val); 
+
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16)| 0x15C);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        reg_val = vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78));
+        VLOG(ERR,"C_SHU_NBUF_RPTR   = 0x%x\n",reg_val); 
+
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16)| 0x15D);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        reg_val = vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78));
+        VLOG(ERR,"C_SHU_NBUF_WPTR   = 0x%x\n",reg_val); 
+
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16)| 0x15E);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        reg_val = vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78));
+        VLOG(ERR,"C_SHU_REMAIN_BYTE = 0x%x\n",reg_val); 
+
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16)| 0x15F);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        reg_val = vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78));
+        VLOG(ERR,"C_SHU_CONSUME_BYTE= 0x%x\n",reg_val); 
+
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16)| 0x160);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        reg_val = vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78));
+        VLOG(ERR,"C_SHU_RD_SEL     = 0x%x\n",reg_val); 
+
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16)| 0x161);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        reg_val = vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78));
+        VLOG(ERR,"C_SHU_WR_SEL     = 0x%x\n",reg_val); 
+
+        // --------- BIT HEVC Status Dump 
+        ctu_fsm		= vdi_fio_read_register(coreIdx, (W4_REG_BASE + 0x8000 + 0x48));
+        nb_fsm		= vdi_fio_read_register(coreIdx, (W4_REG_BASE + 0x8000 + 0x4c));
+        cabac_fsm	= vdi_fio_read_register(coreIdx, (W4_REG_BASE + 0x8000 + 0x50));
+        cu_info		= vdi_fio_read_register(coreIdx, (W4_REG_BASE + 0x8000 + 0x54));
+        mvp_fsm		= vdi_fio_read_register(coreIdx, (W4_REG_BASE + 0x8000 + 0x58));
+        tc_busy		= vdi_fio_read_register(coreIdx, (W4_REG_BASE + 0x8000 + 0x5c));
+        lf_fsm		= vdi_fio_read_register(coreIdx, (W4_REG_BASE + 0x8000 + 0x60));
+        bs_data		= vdi_fio_read_register(coreIdx, (W4_REG_BASE + 0x8000 + 0x64));
+        bbusy		= vdi_fio_read_register(coreIdx, (W4_REG_BASE + 0x8000 + 0x68));
+        fv		    = vdi_fio_read_register(coreIdx, (W4_REG_BASE + 0x8000 + 0x6C));
+
+        VLOG(ERR,"[DEBUG-BPUHEVC] CTU_X: %4d, CTU_Y: %4d\n",  vdi_fio_read_register(coreIdx, (W4_REG_BASE + 0x8000 + 0x40)), vdi_fio_read_register(coreIdx, (W4_REG_BASE + 0x8000 + 0x44))); 
+        VLOG(ERR,"[DEBUG-BPUHEVC] CTU_FSM>   Main: 0x%02x, FIFO: 0x%1x, NB: 0x%02x, DBK: 0x%1x\n", ((ctu_fsm >> 24) & 0xff), ((ctu_fsm >> 16) & 0xff), ((ctu_fsm >> 8) & 0xff), (ctu_fsm & 0xff));
+        VLOG(ERR,"[DEBUG-BPUHEVC] NB_FSM:	0x%02x\n", nb_fsm & 0xff);
+        VLOG(ERR,"[DEBUG-BPUHEVC] CABAC_FSM> SAO: 0x%02x, CU: 0x%02x, PU: 0x%02x, TU: 0x%02x, EOS: 0x%02x\n", ((cabac_fsm>>25) & 0x3f), ((cabac_fsm>>19) & 0x3f), ((cabac_fsm>>13) & 0x3f), ((cabac_fsm>>6) & 0x7f), (cabac_fsm & 0x3f));
+        VLOG(ERR,"[DEBUG-BPUHEVC] CU_INFO value = 0x%04x \n\t\t(l2cb: 0x%1x, cux: %1d, cuy; %1d, pred: %1d, pcm: %1d, wr_done: %1d, par_done: %1d, nbw_done: %1d, dec_run: %1d)\n", cu_info, 
+            ((cu_info>> 16) & 0x3), ((cu_info>> 13) & 0x7), ((cu_info>> 10) & 0x7), ((cu_info>> 9) & 0x3), ((cu_info>> 8) & 0x1), ((cu_info>> 6) & 0x3), ((cu_info>> 4) & 0x3), ((cu_info>> 2) & 0x3), (cu_info & 0x3));
+        VLOG(ERR,"[DEBUG-BPUHEVC] MVP_FSM> 0x%02x\n", mvp_fsm & 0xf);
+        VLOG(ERR,"[DEBUG-BPUHEVC] TC_BUSY> tc_dec_busy: %1d, tc_fifo_busy: 0x%02x\n", ((tc_busy >> 3) & 0x1), (tc_busy & 0x7));
+        VLOG(ERR,"[DEBUG-BPUHEVC] LF_FSM>  SAO: 0x%1x, LF: 0x%1x\n", ((lf_fsm >> 4) & 0xf), (lf_fsm  & 0xf));
+        VLOG(ERR,"[DEBUG-BPUHEVC] BS_DATA> ExpEnd=%1d, bs_valid: 0x%03x, bs_data: 0x%03x\n", ((bs_data >> 31) & 0x1), ((bs_data >> 16) & 0xfff), (bs_data & 0xfff));
+        VLOG(ERR,"[DEBUG-BPUHEVC] BUS_BUSY> mib_wreq_done: %1d, mib_busy: %1d, sdma_bus: %1d\n", ((bbusy >> 2) & 0x1), ((bbusy >> 1) & 0x1) , (bbusy & 0x1));
+        VLOG(ERR,"[DEBUG-BPUHEVC] FIFO_VALID> cu: %1d, tu: %1d, iptu: %1d, lf: %1d, coff: %1d\n\n", ((fv >> 4) & 0x1), ((fv >> 3) & 0x1), ((fv >> 2) & 0x1), ((fv >> 1) & 0x1), (fv & 0x1));
+        VLOG(ERR,"[-] BPU REG Dump\n");
+
+        // --------- VCE register Dump 
+        VLOG(ERR,"[+] VCE REG Dump\n");
+        tq = ReadRegVCE(coreIdx, 0, 0xd0);
+        ip = ReadRegVCE(coreIdx, 0, 0xd4); 
+        mc = ReadRegVCE(coreIdx, 0, 0xd8);
+        lf = ReadRegVCE(coreIdx, 0, 0xdc);
+        avail_cu = (ReadRegVCE(coreIdx, 0, 0x11C)>>16) - (ReadRegVCE(coreIdx, 0, 0x110)>>16);
+        avail_tu = (ReadRegVCE(coreIdx, 0, 0x11C)&0xFFFF) - (ReadRegVCE(coreIdx, 0, 0x110)&0xFFFF);
+        avail_tc = (ReadRegVCE(coreIdx, 0, 0x120)>>16) - (ReadRegVCE(coreIdx, 0, 0x114)>>16);
+        avail_lf = (ReadRegVCE(coreIdx, 0, 0x120)&0xFFFF) - (ReadRegVCE(coreIdx, 0, 0x114)&0xFFFF);
+        avail_ip = (ReadRegVCE(coreIdx, 0, 0x124)>>16) - (ReadRegVCE(coreIdx, 0, 0x118)>>16);
+        VLOG(ERR,"       TQ            IP              MC             LF      GDI_EMPTY          ROOM \n");
+        VLOG(ERR,"------------------------------------------------------------------------------------------------------------\n");
+        SetClockGate(coreIdx, 1);
+        VLOG(ERR,"| %d %04d %04d | %d %04d %04d |  %d %04d %04d | %d %04d %04d | 0x%08x | CU(%d) TU(%d) TC(%d) LF(%d) IP(%d)\n",
+            (tq>>22)&0x07, (tq>>11)&0x3ff, tq&0x3ff,
+            (ip>>22)&0x07, (ip>>11)&0x3ff, ip&0x3ff,
+            (mc>>22)&0x07, (mc>>11)&0x3ff, mc&0x3ff,
+            (lf>>22)&0x07, (lf>>11)&0x3ff, lf&0x3ff,
+            vdi_fio_read_register(coreIdx, 0x88f4),                      /* GDI empty */
+            avail_cu, avail_tu, avail_tc, avail_lf, avail_ip);
+        /* CU/TU Queue count */
+        reg_val = ReadRegVCE(coreIdx, 0, 0x12C);
+        VLOG(ERR,"[DCIDEBUG] QUEUE COUNT: CU(%5d) TU(%5d) ", (reg_val>>16)&0xffff, reg_val&0xffff);
+        reg_val = ReadRegVCE(coreIdx, 0, 0x1A0);
+        VLOG(ERR,"TC(%5d) IP(%5d) ", (reg_val>>16)&0xffff, reg_val&0xffff);
+        reg_val = ReadRegVCE(coreIdx, 0, 0x1A4);
+        VLOG(ERR,"LF(%5d)\n", (reg_val>>16)&0xffff);
+        VLOG(ERR,"VALID SIGNAL : CU0(%d)  CU1(%d)  CU2(%d) TU(%d) TC(%d) IP(%5d) LF(%5d)\n" 
+            "               DCI_FALSE_RUN(%d) VCE_RESET(%d) CORE_INIT(%d) SET_RUN_CTU(%d) \n",
+            (reg_val>>6)&1, (reg_val>>5)&1, (reg_val>>4)&1, (reg_val>>3)&1, 
+            (reg_val>>2)&1, (reg_val>>1)&1, (reg_val>>0)&1,
+            (reg_val>>10)&1, (reg_val>>9)&1, (reg_val>>8)&1, (reg_val>>7)&1);
+
+        VLOG(ERR,"State TQ: 0x%08x IP: 0x%08x MC: 0x%08x LF: 0x%08x\n", 
+            ReadRegVCE(coreIdx, 0, 0xd0), ReadRegVCE(coreIdx, 0, 0xd4), ReadRegVCE(coreIdx, 0, 0xd8), ReadRegVCE(coreIdx, 0, 0xdc));
+        VLOG(ERR,"BWB[1]: RESPONSE_CNT(0x%08x) INFO(0x%08x)\n", ReadRegVCE(coreIdx, 0, 0x194), ReadRegVCE(coreIdx, 0, 0x198));
+        VLOG(ERR,"BWB[2]: RESPONSE_CNT(0x%08x) INFO(0x%08x)\n", ReadRegVCE(coreIdx, 0, 0x194), ReadRegVCE(coreIdx, 0, 0x198));
+        VLOG(ERR,"DCI INFO\n");
+        VLOG(ERR,"READ_CNT_0 : 0x%08x\n", ReadRegVCE(coreIdx, 0, 0x110));
+        VLOG(ERR,"READ_CNT_1 : 0x%08x\n", ReadRegVCE(coreIdx, 0, 0x114));
+        VLOG(ERR,"READ_CNT_2 : 0x%08x\n", ReadRegVCE(coreIdx, 0, 0x118));
+        VLOG(ERR,"WRITE_CNT_0: 0x%08x\n", ReadRegVCE(coreIdx, 0, 0x11c));
+        VLOG(ERR,"WRITE_CNT_1: 0x%08x\n", ReadRegVCE(coreIdx, 0, 0x120));
+        VLOG(ERR,"WRITE_CNT_2: 0x%08x\n", ReadRegVCE(coreIdx, 0, 0x124));
+        reg_val = ReadRegVCE(coreIdx, 0, 0x128);
+        VLOG(ERR,"LF_DEBUG_PT: 0x%08x\n", reg_val & 0xffffffff);
+        VLOG(ERR,"cur_main_state %2d, r_lf_pic_deblock_disable %1d, r_lf_pic_sao_disable %1d\n",
+            (reg_val >> 16) & 0x1f, 
+            (reg_val >> 15) & 0x1, 
+            (reg_val >> 14) & 0x1);
+        VLOG(ERR,"para_load_done %1d, i_rdma_ack_wait %1d, i_sao_intl_col_done %1d, i_sao_outbuf_full %1d\n",
+            (reg_val >> 13) & 0x1, 
+            (reg_val >> 12) & 0x1, 
+            (reg_val >> 11) & 0x1, 
+            (reg_val >> 10) & 0x1);
+        VLOG(ERR,"lf_sub_done %1d, i_wdma_ack_wait %1d, lf_all_sub_done %1d, cur_ycbcr %1d, sub8x8_done %2d\n", 
+            (reg_val >> 9) & 0x1, 
+            (reg_val >> 8) & 0x1, 
+            (reg_val >> 6) & 0x1, 
+            (reg_val >> 4) & 0x1, 
+            reg_val & 0xf);
+        VLOG(ERR,"[-] VCE REG Dump\n");
+        VLOG(ERR,"[-] VCE REG Dump\n");
+
+        VLOG(ERR,"-------------------------------------------------------------------------------\n");
+    }
+    if (productId == PRODUCT_ID_420 || productId == PRODUCT_ID_420L)
+    {
+        int       rd, wr;
+        Uint32    reg_val, num;
+        int       vce_enc_debug[12] = {0, };
+        int		  set_mode;
+        int       vcore_num, vcore_idx;
+        Uint32    index;
+        Uint32    vcpu_reg[31]= {0,};
+
+        SetClockGate(coreIdx, 1);
+        VLOG(ERR,"-------------------------------------------------------------------------------\n");
+        VLOG(ERR,"------                            VCPU STATUS(ENC)                        -----\n");
+        VLOG(ERR,"-------------------------------------------------------------------------------\n");
+        rd = VpuReadReg(coreIdx, W4_BS_RD_PTR);
+        wr = VpuReadReg(coreIdx, W4_BS_WR_PTR);
+        VLOG(ERR,"RD_PTR: 0x%08x WR_PTR: 0x%08x BS_OPT: 0x%08x BS_PARAM: 0x%08x\n", 
+            rd, wr, VpuReadReg(coreIdx, W4_BS_OPTION), VpuReadReg(coreIdx, W4_BS_PARAM));
+
+        // --------- VCPU register Dump 
+        VLOG(ERR,"[+] VCPU REG Dump\n");
+        for (index = 0; index < 25; index++) {
+            VpuWriteReg (coreIdx, W4_VPU_PDBG_IDX_REG, (1<<9) | (index & 0xff));
+            vcpu_reg[index] = VpuReadReg (coreIdx, W4_VPU_PDBG_RDATA_REG);
+
+            if (index < 16) {
+                VLOG(ERR,"0x%08x\t",  vcpu_reg[index]);
+                if ((index % 4) == 3) VLOG(ERR,"\n");
+            }
+            else {
+                switch (index) {
+                case 16: VLOG(ERR,"CR0: 0x%08x\t", vcpu_reg[index]); break;
+                case 17: VLOG(ERR,"CR1: 0x%08x\n", vcpu_reg[index]); break;
+                case 18: VLOG(ERR,"ML:  0x%08x\t", vcpu_reg[index]); break;
+                case 19: VLOG(ERR,"MH:  0x%08x\n", vcpu_reg[index]); break;
+                case 21: VLOG(ERR,"LR:  0x%08x\n", vcpu_reg[index]); break;
+                case 22: VLOG(ERR,"PC:  0x%08x\n", vcpu_reg[index]);break;
+                case 23: VLOG(ERR,"SR:  0x%08x\n", vcpu_reg[index]);break;
+                case 24: VLOG(ERR,"SSP: 0x%08x\n", vcpu_reg[index]);break;
+                }
+            }
+        }
+        VLOG(ERR,"[-] VCPU REG Dump\n");
+        VLOG(ERR,"vce run flag = %d\n", VpuReadReg(coreIdx, 0x1E8));
+        // --------- BIT register Dump 
+        VLOG(ERR,"[+] BPU REG Dump\n");
+        for (index=0;index < 30; index++)
+        {
+            int temp;
+            temp = vdi_fio_read_register(coreIdx, (W4_REG_BASE + 0x8000 + 0x18));
+            VLOG(ERR,"BITPC = 0x%08x\n", temp);
+            if ( temp == 0xffffffff)
+                return;
+        }
+
+        // --------- BIT HEVC Status Dump 
+        VLOG(ERR,"==================================\n");
+        VLOG(ERR,"[-] BPU REG Dump\n");
+        VLOG(ERR,"==================================\n");
+
+        VLOG(ERR,"DBG_FIFO_VALID		[%08x]\n",vdi_fio_read_register(coreIdx, (W4_REG_BASE + 0x8000 + 0x6C)));
+
+        //SDMA debug information
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20) | (1<<16)| 0x13c);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        reg_val = vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78));
+        VLOG(ERR,"SDMA_DBG_INFO		[%08x]\n", reg_val);
+        VLOG(ERR,"\t- [   28] need_more_update  : 0x%x \n", (reg_val>>28)&0x1 );
+        VLOG(ERR,"\t- [27:25] tr_init_fsm       : 0x%x \n", (reg_val>>25)&0x7 );
+        VLOG(ERR,"\t- [24:18] remain_trans_size : 0x%x \n", (reg_val>>18)&0x7F);
+        VLOG(ERR,"\t- [17:13] wdata_out_cnt     : 0x%x \n", (reg_val>>13)&0x1F);
+        VLOG(ERR,"\t- [12:10] wdma_wd_fsm       : 0x%x \n", (reg_val>>10)&0x1F);
+        VLOG(ERR,"\t- [ 9: 7] wdma_wa_fsm       : 0x%x ", (reg_val>> 7)&0x7 );
+        if (((reg_val>>7) &0x7) == 3)
+            VLOG(ERR,"-->WDMA_WAIT_ADDR  \n");
+        else
+            VLOG(ERR,"\n");
+        VLOG(ERR,"\t- [ 6: 5] sdma_init_fsm     : 0x%x \n", (reg_val>> 5)&0x3 );
+        VLOG(ERR,"\t- [ 4: 1] save_fsm          : 0x%x \n", (reg_val>> 1)&0xF );
+        VLOG(ERR,"\t- [    0] unalign_written   : 0x%x \n", (reg_val>> 0)&0x1 );
+
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16)| 0x13b);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        reg_val = vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78));
+        VLOG(ERR,"SDMA_NAL_MEM_INF	[%08x]\n", reg_val);
+        VLOG(ERR,"\t- [ 7: 1] nal_mem_empty_room : 0x%x \n", (reg_val>> 1)&0x3F);
+        VLOG(ERR,"\t- [    0] ge_wnbuf_size      : 0x%x \n", (reg_val>> 0)&0x1 );
+
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16) | 0x131);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        reg_val = vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78));
+        VLOG(ERR,"SDMA_IRQ		[%08x]: [1]sdma_irq : 0x%x, [2]enable_sdma_irq : 0x%x\n",reg_val, (reg_val >> 1)&0x1,(reg_val &0x1));
+
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16) | 0x134);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        VLOG(ERR,"SDMA_BS_BASE_ADDR [%08x]\n",vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78)));
+
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16) | 0x135);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        VLOG(ERR,"SDMA_NAL_STR_ADDR [%08x]\n",vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78)));
+
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16) | 0x136);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        VLOG(ERR,"SDMA_IRQ_ADDR     [%08x]\n",vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78)));
+
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16) | 0x137);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        VLOG(ERR,"SDMA_BS_END_ADDR	[%08x]\n",vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78)));
+
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16) | 0x13A);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        VLOG(ERR,"SDMA_CUR_ADDR		[%08x]\n",vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78)));
+
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16) | 0x139);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        reg_val = vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78));
+        VLOG(ERR,"SDMA_STATUS			[%08x]\n",reg_val);
+        VLOG(ERR,"\t- [2] all_wresp_done : 0x%x \n", (reg_val>> 2)&0x1);
+        VLOG(ERR,"\t- [1] sdma_init_busy : 0x%x \n", (reg_val>> 1)&0x1 );
+        VLOG(ERR,"\t- [0] save_busy      : 0x%x \n", (reg_val>> 0)&0x1 );
+
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16) | 0x164);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        reg_val = vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78));
+        VLOG(ERR,"SHU_DBG				[%08x] : shu_unaligned_num (0x%x)\n",reg_val, reg_val);
+
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16) | 0x169);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        VLOG(ERR,"SHU_NBUF_WPTR		[%08x]\n",vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78)));
+
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16) | 0x16A);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        VLOG(ERR,"SHU_NBUF_RPTR		[%08x]\n",vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78)));
+
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16) | 0x16C);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        reg_val = vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78));
+        VLOG(ERR,"SHU_NBUF_INFO		[%08x]\n",reg_val);
+        VLOG(ERR,"\t- [5:1] nbuf_remain_byte : 0x%x \n", (reg_val>> 1)&0x1F);
+        VLOG(ERR,"\t- [  0] nbuf_wptr_wrap   : 0x%x \n", (reg_val>> 0)&0x1 );
+
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16) | 0x184);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        VLOG(ERR,"CTU_LAST_ENC_POS	[%08x]\n",vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78)));
+
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16) | 0x187);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        VLOG(ERR,"CTU_POS_IN_PIC		[%08x]\n",vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78)));
+
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16) | 0x110);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        VLOG(ERR,"MIB_EXTADDR			[%08x]\n",vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78)));
+
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16) | 0x111);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        VLOG(ERR,"MIB_INTADDR			[%08x]\n",vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78)));
+
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16) | 0x113);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        VLOG(ERR,"MIB_CMD				[%08x]\n",vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78)));
+
+        vdi_fio_write_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x74),(1<<20)| (1<<16) | 0x114);
+        while((vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x7c))& 0x1) ==0 );
+        VLOG(ERR,"MIB_BUSY			[%08x]\n",vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x78)));
+
+        VLOG(ERR,"DBG_BPU_ENC_NB0		[%08x]\n",vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x40)));
+        VLOG(ERR,"DBG_BPU_CTU_CTRL0	[%08x]\n",vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x44)));
+        VLOG(ERR,"DBG_BPU_CAB_FSM0	[%08x]\n",vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x48)));
+        VLOG(ERR,"DBG_BPU_BIN_GEN0	[%08x]\n",vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x4C)));
+        VLOG(ERR,"DBG_BPU_CAB_MBAE0	[%08x]\n",vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x50)));
+        VLOG(ERR,"DBG_BPU_BUS_BUSY	[%08x]\n",vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x68)));
+        VLOG(ERR,"DBG_FIFO_VALID		[%08x]\n",vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x6C)));
+        VLOG(ERR,"DBG_BPU_CTU_CTRL1	[%08x]\n",vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x54)));
+        VLOG(ERR,"DBG_BPU_CTU_CTRL2	[%08x]\n",vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x58)));
+        VLOG(ERR,"DBG_BPU_CTU_CTRL3	[%08x]\n",vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x5C)));
+
+        for (index=0x80; index<0xA0; index+=4) {
+            reg_val = vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + index));
+            num     = (index - 0x80)/2;
+            VLOG(ERR,"DBG_BIT_STACK		[%08x] : Stack%02d (0x%04x), Stack%02d(0x%04x) \n",reg_val, num, reg_val>>16, num+1, reg_val & 0xffff);
+        }
+
+        reg_val = vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0xA0));
+        VLOG(ERR,"DGB_BIT_CORE_INFO	[%08x] : pc_ctrl_id (0x%04x), pfu_reg_pc(0x%04x)\n",reg_val,reg_val>>16, reg_val & 0xffff);
+        reg_val = vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0xA4));
+        VLOG(ERR,"DGB_BIT_CORE_INFO	[%08x] : ACC0 (0x%08x)\n",reg_val, reg_val);
+        reg_val = vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0xA8));
+        VLOG(ERR,"DGB_BIT_CORE_INFO	[%08x] : ACC1 (0x%08x)\n",reg_val, reg_val);
+
+        reg_val = vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0xAC));
+        VLOG(ERR,"DGB_BIT_CORE_INFO	[%08x] : pfu_ibuff_id(0x%04x), pfu_ibuff_op(0x%04x)\n",reg_val,reg_val>>16, reg_val & 0xffff);
+
+        for (num=0; num<5; num+=1) {
+            reg_val = vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0xB0));
+            VLOG(ERR,"DGB_BIT_CORE_INFO	[%08x] : core_pram_rd_en(0x%04x), core_pram_rd_addr(0x%04x)\n",reg_val,reg_val>>16, reg_val & 0xffff);
+        }
+
+        VLOG(ERR,"SAO_LUMA_OFFSET	[%08x]\n",vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0xB4)));
+        VLOG(ERR,"SAO_CB_OFFSET	[%08x]\n",vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0xB8)));
+        VLOG(ERR,"SAO_CR_OFFSET	[%08x]\n",vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0xBC)));
+
+        VLOG(ERR,"GDI_NO_MORE_REQ		[%08x]\n",vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x8f0)));
+        VLOG(ERR,"GDI_EMPTY_FLAG		[%08x]\n",vdi_fio_read_register(coreIdx,(W4_REG_BASE + 0x8000 + 0x8f4)));
+
+        if ( productId == PRODUCT_ID_420) {
+            VLOG(ERR,"WAVE420_CODE VCE DUMP\n");
+            vce_enc_debug[0] = 0x0bc8;//MODE SEL
+            vce_enc_debug[1] = 0x0be0;
+            vce_enc_debug[2] = 0x0bcc;
+            vce_enc_debug[3] = 0x0be4;
+            vce_enc_debug[4] = 0x0be8;
+            vce_enc_debug[5] = 0x0bec;
+            vce_enc_debug[6] = 0x0bc0;
+            vce_enc_debug[7] = 0x0bc4;
+            vce_enc_debug[8] = 0x0bf0;
+            vce_enc_debug[9] = 0x0bf4;
+            set_mode         = 0x0bc8;
+            vcore_num        = 1;
+        } 
+        else if (productId == PRODUCT_ID_420L) {
+            VLOG(ERR,"WAVE420L_CODE VCE DUMP\n");
+            vce_enc_debug[0] = 0x0bd0;//MODE SEL
+            vce_enc_debug[1] = 0x0bd4;
+            vce_enc_debug[2] = 0x0bd8;
+            vce_enc_debug[3] = 0x0bdc;
+            vce_enc_debug[4] = 0x0be0;
+            vce_enc_debug[5] = 0x0be4;
+            vce_enc_debug[6] = 0x0be8;
+            vce_enc_debug[7] = 0x0bc4;
+            vce_enc_debug[8] = 0x0bf0;
+            vce_enc_debug[9] = 0x0bf4;
+            set_mode         = 0x0bd0;
+            vcore_num        = 1;
+        } 
+
+        for (vcore_idx = 0; vcore_idx < vcore_num ; vcore_idx++)
+        {
+            VLOG(ERR,"==========================================\n");
+            VLOG(ERR,"[+] VCE REG Dump VCORE_IDX : %d\n",vcore_idx);
+            VLOG(ERR,"==========================================\n");
+            DisplayVceEncDebugCommon         (coreIdx, vcore_idx, set_mode, vce_enc_debug[0], vce_enc_debug[1], vce_enc_debug[2]);
+            DisplayVceEncDebugDCI            (coreIdx, vcore_idx, set_mode, vce_enc_debug);
+            DisplayVceEncDebugRDO            (coreIdx, vcore_idx, set_mode, vce_enc_debug);
+            DisplayVceEncDebugLF             (coreIdx, vcore_idx, set_mode, vce_enc_debug);
+            DisplayVceEncDebugSFU            (coreIdx, vcore_idx, set_mode, vce_enc_debug);
+            DisplayVceEncDebugDCI2           (coreIdx, vcore_idx, set_mode, vce_enc_debug);
+            DisplayVceEncDebugDCILast        (coreIdx, vcore_idx, set_mode, vce_enc_debug);
+            DisplayVceEncDebugBigBufferCnt   (coreIdx, vcore_idx, set_mode, vce_enc_debug);
+            DisplayVceEncDebugBigBufferAddr  (coreIdx, vcore_idx, set_mode, vce_enc_debug);
+            DisplayVceEncDebugSubWb			 (coreIdx, vcore_idx, set_mode, vce_enc_debug);
+            DisplayVceEncDebugFBC			 (coreIdx, vcore_idx, set_mode, vce_enc_debug);
+        }
+
+    }
+    if ( productId == PRODUCT_ID_520 )
+    {
+        int       rd, wr;
+        SetClockGate(coreIdx, 1);
+        VLOG(ERR,"-------------------------------------------------------------------------------\n");
+        VLOG(ERR,"------                            VCPU STATUS(ENC)                        -----\n");
+        VLOG(ERR,"-------------------------------------------------------------------------------\n");
+        rd = VpuReadReg(coreIdx, W4_BS_RD_PTR);
+        wr = VpuReadReg(coreIdx, W4_BS_WR_PTR);
+        VLOG(ERR,"RD_PTR: 0x%08x WR_PTR: 0x%08x BS_OPT: 0x%08x BS_PARAM: 0x%08x\n", 
+            rd, wr, VpuReadReg(coreIdx, W4_BS_OPTION), VpuReadReg(coreIdx, W4_BS_PARAM));
+
+        VLOG(ERR,"=========Need to add debug code here =========\n");
+    }
+    else
+    {
+    }
+    SetClockGate(coreIdx, 0);
+}
+
+
+void HandleEncoderError(
+    EncHandle       handle,
+    Uint32          encPicCnt,
+    EncOutputInfo*  outputInfo
+    )
+{
+    UNREFERENCED_PARAMETER(handle);
+}
+
+void HandleDecoderError(
+    DecHandle       handle, 
+    Uint32          frameIdx,
+    TestDecConfig*  param,
+    vpu_buffer_t*   fbMem,
+    DecOutputInfo*  outputInfo
+    )
+{
+    UNREFERENCED_PARAMETER(handle);
+    UNREFERENCED_PARAMETER(outputInfo);
+}
+
+void PrintMemoryAccessViolationReason(
+    Uint32          core_idx, 
+    void            *outp
+    )
+{
+    UNREFERENCED_PARAMETER(core_idx);
+    UNREFERENCED_PARAMETER(outp);
+}
+
+/**
+* \brief           Handle error cases depending on product
+* \return  -1      SEQUENCE ERROR
+*/
+Int32 HandleDecInitSequenceError(DecHandle handle, Uint32 productId, DecOpenParam* openParam, DecInitialInfo* seqInfo, RetCode apiErrorCode)
+{
+    if (apiErrorCode == RETCODE_MEMORY_ACCESS_VIOLATION) {
+        PrintMemoryAccessViolationReason(handle->coreIdx, NULL);
+        return -1;
+    }
+
+    if (PRODUCT_ID_W_SERIES(productId)) {
+        if (seqInfo->seqInitErrReason == WAVE4_SPSERR_NOT_FOUND) {
+            return -2;
+        } else {
+            if (seqInfo->seqInitErrReason == WAVE4_SPEC_OVER_PICTURE_WIDTH_SIZE) {
+                VLOG(ERR, "Not supported picture width: MAX_SIZE(8192): %d\n", seqInfo->picWidth);
+            }
+            if (seqInfo->seqInitErrReason == WAVE4_SPEC_OVER_PICTURE_HEIGHT_SIZE) {
+                VLOG(ERR, "Not supported picture height: MAX_SIZE(8192): %d\n", seqInfo->picHeight);
+            }
+            if (seqInfo->seqInitErrReason == WAVE4_SPEC_OVER_CHROMA_FORMAT) {
+                VLOG(ERR, "Not supported chroma idc: %d\n", seqInfo->chromaFormatIDC);
+            }
+            if (seqInfo->seqInitErrReason == WAVE4_SPEC_OVER_BIT_DEPTH) {
+                VLOG(INFO, "Not supported Luma or Chroma bitdepth: L(%d), C(%d)\n", seqInfo->lumaBitdepth, seqInfo->chromaBitdepth);
+            }
+            if (seqInfo->seqInitErrReason == WAVE4_SPEC_OVER_PROFILE) {
+                VLOG(INFO, "Not supported profile: %d\n", seqInfo->profile);
+            }
+            if (seqInfo->seqInitErrReason == WAVE4_SPSERR_NOT_FOUND) {
+                VLOG(INFO, "Not found SPS: RD_PTR(0x%08x), WR_PTR(0x%08x)\n", seqInfo->rdPtr, seqInfo->wrPtr);
+            }
+            return -1;
+        }
+    } 
+    else {
+        if (openParam->bitstreamMode == BS_MODE_PIC_END && (seqInfo->seqInitErrReason&(1<<31))) {
+            VLOG(ERR, "SEQUENCE HEADER NOT FOUND\n");
+            return -1;
+        }
+        else {
+            return -1;
+        }
+    }
+}

+ 54 - 0
wave420l/code/sample/helper/misc/debug.h

@@ -0,0 +1,54 @@
+//--=========================================================================--
+//  This file is a part of VPU Reference API project
+//-----------------------------------------------------------------------------
+//
+//       This confidential and proprietary software may be used only
+//     as authorized by a licensing agreement from Chips&Media Inc.
+//     In the event of publication, the following notice is applicable:
+//
+//            (C) COPYRIGHT CHIPS&MEDIA INC.
+//                      ALL RIGHTS RESERVED
+//
+//       The entire notice above must be reproduced on all authorized
+//       copies.
+//
+//--=========================================================================--
+#ifndef _DEBUG_H_
+#define _DEBUG_H_
+
+#include "config.h"
+#include "main_helper.h"
+
+enum {
+    CNMQC_ENV_NONE,
+    CNMQC_ENV_GDBSERVER = (1<<16),      /*!<< It executes gdb server in order to debug F/W on the C&M FPGA env. */
+    CNMQC_ENV_MAX,
+};
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/* @param options   It can be multiples of the above options. 
+ */
+extern void InitializeDebugEnv(
+    Uint32 productId,
+    Uint32 options
+    );
+
+extern void ReleaseDebugEnv(
+    void
+    );
+
+void PrintVpuStatus(
+    Uint32 coreIdx, 
+    Uint32 productId
+    );
+
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* _SKIP_H_ */
+

+ 154 - 0
wave420l/code/sample/helper/misc/getopt.c

@@ -0,0 +1,154 @@
+/*	$NetBSD: getopt.c,v 1.16 1999/12/02 13:15:56 kleink Exp $	*/
+
+/*
+ * Copyright (c) 1987, 1993, 1994
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *	This product includes software developed by the University of
+ *	California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if 0
+static char sccsid[] = "@(#)getopt.c	8.3 (Berkeley) 4/27/95";
+#endif
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+
+#ifndef __P
+#define __P(x) x
+#endif
+
+#define _DIAGASSERT(x) assert(x)
+
+#ifdef __weak_alias
+__weak_alias(getopt,_getopt);
+#endif
+
+int	opterr = 1,		/* if error message should be printed */
+	optind = 1,		/* index into parent argv vector */
+	optopt,			/* character checked for validity */
+	optreset;		/* reset getopt */
+char	*optarg;		/* argument associated with option */
+
+static char * _progname __P((char *));
+int getopt_internal __P((int, char * const *, const char *));
+
+static char *
+_progname(nargv0)
+	char * nargv0;
+{
+	char * tmp;
+
+	_DIAGASSERT(nargv0 != NULL);
+
+	tmp = strrchr(nargv0, '/');
+	if (tmp)
+		tmp++;
+	else
+		tmp = nargv0;
+	return(tmp);
+}
+
+#define	BADCH	(int)'?'
+#define	BADARG	(int)':'
+#define	EMSG	""
+
+/*
+ * getopt --
+ *	Parse argc/argv argument vector.
+ */
+int
+getopt(nargc, nargv, ostr)
+	int nargc;
+	char * const nargv[];
+	const char *ostr;
+{
+	static char *__progname = 0;
+	static char *place = EMSG;		/* option letter processing */
+	char *oli;				/* option letter list index */
+        __progname = __progname?__progname:_progname(*nargv);
+
+	_DIAGASSERT(nargv != NULL);
+	_DIAGASSERT(ostr != NULL);
+
+	if (optreset || !*place) {		/* update scanning pointer */
+		optreset = 0;
+		if (optind >= nargc || *(place = nargv[optind]) != '-') {
+			place = EMSG;
+			return (-1);
+		}
+		if (place[1] && *++place == '-'	/* found "--" */
+		    && place[1] == '\0') {
+			++optind;
+			place = EMSG;
+			return (-1);
+		}
+	}					/* option letter okay? */
+	if ((optopt = (int)*place++) == (int)':' ||
+	    !(oli = strchr((char*)ostr, optopt))) {
+		/*
+		 * if the user didn't specify '-' as an option,
+		 * assume it means -1.
+		 */
+		if (optopt == (int)'-')
+			return (-1);
+		if (!*place)
+			++optind;
+		if (opterr && *ostr != ':')
+			(void)fprintf(stderr,
+			    "%s: illegal option -- %c\n", __progname, optopt);
+		return (BADCH);
+	}
+	if (*++oli != ':') {			/* don't need argument */
+		optarg = NULL;
+		if (!*place)
+			++optind;
+	}
+	else {					/* need an argument */
+		if (*place)			/* no white space */
+			optarg = place;
+		else if (nargc <= ++optind) {	/* no arg */
+			place = EMSG;
+			if (*ostr == ':')
+				return (BADARG);
+			if (opterr)
+				(void)fprintf(stderr,
+				    "%s: option requires an argument -- %c\n",
+				    __progname, optopt);
+			return (BADCH);
+		}
+	 	else				/* white space */
+			optarg = nargv[optind];
+		place = EMSG;
+		++optind;
+	}
+	return (optopt);			/* dump back option letter */
+} 

+ 37 - 0
wave420l/code/sample/helper/misc/getopt.h

@@ -0,0 +1,37 @@
+#ifndef __GETOPT_H__
+#define __GETOPT_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+    extern int opterr;		/* if error message should be printed */
+    extern int optind;		/* index into parent argv vector */
+    extern int optopt;		/* character checked for validity */
+    extern int optreset;		/* reset getopt */
+    extern char *optarg;		/* argument associated with option */
+
+    struct option
+    {
+        const char *name;
+        int has_arg;
+        int *flag;
+        int val;
+    };
+
+#define no_argument       0
+#define required_argument 1
+#define optional_argument 2
+
+    int getopt(int, char**, char*);
+#if defined(PLATFORM_QNX)
+#else
+    int getopt_long(int, char**, char*, struct option*, int*);
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __GETOPT_H__ */
+ 

+ 242 - 0
wave420l/code/sample/helper/misc/getopt_long.c

@@ -0,0 +1,242 @@
+/*
+ * Copyright (c) 1987, 1993, 1994, 1996
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *	This product includes software developed by the University of
+ *	California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "getopt.h"
+
+extern int	  opterr;	/* if error message should be printed */
+extern int	  optind;	/* index into parent argv vector */
+extern int	  optopt;	/* character checked for validity */
+extern int	  optreset;	/* reset getopt */
+extern char *optarg;	/* argument associated with option */
+
+#ifndef __P
+#define __P(x) x
+#endif
+#define _DIAGASSERT(x) assert(x)
+
+static char * __progname __P((char *));
+int getopt_internal __P((int, char * const *, const char *));
+
+static char *
+__progname(nargv0)
+	char * nargv0;
+{
+	char * tmp;
+
+	_DIAGASSERT(nargv0 != NULL);
+
+	tmp = strrchr(nargv0, '/');
+	if (tmp)
+		tmp++;
+	else
+		tmp = nargv0;
+	return(tmp);
+}
+
+#define	BADCH	(int)'?'
+#define	BADARG	(int)':'
+#define	EMSG	""
+
+/*
+ * getopt --
+ *	Parse argc/argv argument vector.
+ */
+int
+getopt_internal(nargc, nargv, ostr)
+	int nargc;
+	char * const *nargv;
+	const char *ostr;
+{
+	static char *place = EMSG;		/* option letter processing */
+	char *oli;				/* option letter list index */
+
+	_DIAGASSERT(nargv != NULL);
+	_DIAGASSERT(ostr != NULL);
+
+	if (optreset || !*place) {		/* update scanning pointer */
+		optreset = 0;
+		if (optind >= nargc || *(place = nargv[optind]) != '-') {
+			place = EMSG;
+			return (-1);
+		}
+		if (place[1] && *++place == '-') {	/* found "--" */
+			/* ++optind; */
+			place = EMSG;
+			return (-2);
+		}
+	}					/* option letter okay? */
+	if ((optopt = (int)*place++) == (int)':' ||
+	    !(oli = strchr((char*)ostr, optopt))) {
+		/*
+		 * if the user didn't specify '-' as an option,
+		 * assume it means -1.
+		 */
+		if (optopt == (int)'-')
+			return (-1);
+		if (!*place)
+			++optind;
+		if (opterr && *ostr != ':')
+			(void)fprintf(stderr,
+			    "%s: illegal option -- %c\n", __progname(nargv[0]), optopt);
+		return (BADCH);
+	}
+	if (*++oli != ':') {			/* don't need argument */
+		optarg = NULL;
+		if (!*place)
+			++optind;
+	} else {				/* need an argument */
+		if (*place)			/* no white space */
+			optarg = place;
+		else if (nargc <= ++optind) {	/* no arg */
+			place = EMSG;
+			if ((opterr) && (*ostr != ':'))
+				(void)fprintf(stderr,
+				    "%s: option requires an argument -- %c\n",
+				    __progname(nargv[0]), optopt);
+			return (BADARG);
+		} else				/* white space */
+			optarg = nargv[optind];
+		place = EMSG;
+		++optind;
+	}
+	return (optopt);			/* dump back option letter */
+}
+
+#if 0
+/*
+ * getopt --
+ *	Parse argc/argv argument vector.
+ */
+int
+getopt2(nargc, nargv, ostr)
+	int nargc;
+	char * const *nargv;
+	const char *ostr;
+{
+	int retval;
+
+	if ((retval = getopt_internal(nargc, nargv, ostr)) == -2) {
+		retval = -1;
+		++optind; 
+	}
+	return(retval);
+}
+#endif
+
+/*
+ * getopt_long --
+ *	Parse argc/argv argument vector.
+ */
+#if defined(PLATFORM_QNX)
+#else
+int
+getopt_long(nargc, nargv, options, long_options, index)
+	int nargc;
+	char ** nargv;
+	char * options;
+	struct option * long_options;
+	int * index;
+{
+	int retval;
+
+	_DIAGASSERT(nargv != NULL);
+	_DIAGASSERT(options != NULL);
+	_DIAGASSERT(long_options != NULL);
+	/* index may be NULL */
+
+	if ((retval = getopt_internal(nargc, nargv, options)) == -2) {
+		char *current_argv = nargv[optind++] + 2, *has_equal;
+		int i, current_argv_len, match = -1;
+
+		if (*current_argv == '\0') {
+			return(-1);
+		}
+		if ((has_equal = strchr(current_argv, '=')) != NULL) {
+			current_argv_len = has_equal - current_argv;
+			has_equal++;
+		} else
+			current_argv_len = strlen(current_argv);
+
+		for (i = 0; long_options[i].name; i++) { 
+			if (strncmp(current_argv, long_options[i].name, current_argv_len))
+				continue;
+
+			if (strlen(long_options[i].name) == (unsigned)current_argv_len) { 
+				match = i;
+				break;
+			}
+			if (match == -1)
+				match = i;
+		}
+		if (match != -1) {
+			if (long_options[match].has_arg == required_argument ||
+			    long_options[match].has_arg == optional_argument) {
+				if (has_equal)
+					optarg = has_equal;
+				else
+					optarg = nargv[optind++];
+			}
+			if ((long_options[match].has_arg == required_argument)
+			    && (optarg == NULL)) {
+				/*
+				 * Missing argument, leading :
+				 * indicates no error should be generated
+				 */
+				if ((opterr) && (*options != ':'))
+					(void)fprintf(stderr,
+				      "%s: option requires an argument -- %s\n",
+				      __progname(nargv[0]), current_argv);
+				return (BADARG);
+			}
+		} else { /* No matching argument */
+			if ((opterr) && (*options != ':'))
+				(void)fprintf(stderr,
+				    "%s: illegal option -- %s\n", __progname(nargv[0]), current_argv);
+			return (BADCH);
+		}
+		if (long_options[match].flag) {
+			*long_options[match].flag = long_options[match].val;
+			retval = 0;
+		} else 
+			retval = long_options[match].val;
+		if (index)
+			*index = match;
+	}
+	return(retval);
+}
+#endif
+ 

+ 238 - 0
wave420l/code/sample/helper/misc/header_struct.h

@@ -0,0 +1,238 @@
+#ifndef __HEADER_STRUCT_H__
+#define __HEADER_STRUCT_H__
+
+#define EXTENDED_SAR 255
+#define MAX_VPS_MAX_SUB_LAYERS 16
+#define MAX_CPB_COUNT 16
+
+typedef struct sei_buffering_period_tag {
+	Uint32 sub_pic_hrd_params_present_flag;	//derived from syntax elements found in the hrd_parameters( )
+	Uint32 au_cpb_removal_delay_length_minus1; //derived from syntax elements found in the hrd_parameters( )
+	Uint32 initial_cpb_removal_delay_length_minus1; //derived from syntax elements found in the hrd_parameters( )
+	Uint32 CpbCnt;	//CpbCnt are derived from syntax elements found in the sub_layer_hrd_parameters( ) syntax structure
+	Uint32 NalHrdBpPresentFlag;		// NalHrdBpPresentFlag and VclHrdBpPresentFlag are found in or derived from syntax elements found in the hrd_parameters( )
+	Uint32 VclHrdBpPresentFlag;		//NalHrdBpPresentFlag and VclHrdBpPresentFlag are found in or derived from syntax elements found in the hrd_parameters( )
+
+	Uint32 bp_seq_parameter_set_id; 	
+	Uint32 irap_cpb_params_present_flag;	
+	Uint32 cpb_delay_offset;					//The syntax element has a length in bits given by au_cpb_removal_delay_length_minus1 + 1
+	Uint32 dpb_delay_offset;
+	Uint32 concatenation_flag; 
+	Uint32 au_cpb_removal_delay_delta_minus1;	
+	Uint32 nal_initial_cpb_removal_delay[MAX_CPB_COUNT];	// 
+	Uint32 nal_initial_cpb_removal_offset[MAX_CPB_COUNT];
+	Uint32 nal_initial_alt_cpb_removal_delay[MAX_CPB_COUNT];
+	Uint32 nal_initial_alt_cpb_removal_offset[MAX_CPB_COUNT];
+
+	Uint32 vcl_initial_cpb_removal_delay[MAX_CPB_COUNT];
+	Uint32 vcl_initial_cpb_removal_offset[MAX_CPB_COUNT];
+	Uint32 vcl_initial_alt_cpb_removal_delay[MAX_CPB_COUNT];
+	Uint32 vcl_initial_alt_cpb_removal_offset[MAX_CPB_COUNT];	
+} sei_buffering_period_t;
+
+typedef struct sei_pic_timing_tag {
+	Uint32 duplicate_flag; 
+	Uint32 source_scan_type;
+	Uint32 pic_struct;
+
+	Uint32 CpbDpbDelaysPresentFlag;	// if nal_hrd_parameters_present_flag or vcl_hrd_parameters_present_flag  is 1,  
+	Uint32 au_cpb_removal_delay_minus1;
+	Uint32 pic_dpb_output_delay;
+	Uint32 pic_dpb_output_du_delay;
+	
+	Uint32 num_decoding_units_minus1;
+	Uint32 du_common_cpb_removal_delay_flag;
+	Uint32 du_common_cpb_removal_delay_increment_minus1;
+#define MAX_NUM_DECODING_UNIT 20
+	Uint32 num_nalus_in_du_minus1[MAX_NUM_DECODING_UNIT];
+	Uint32 du_cpb_removal_delay_increment_minus1[MAX_NUM_DECODING_UNIT];
+
+} sei_pic_timing_t;
+
+typedef struct sei_active_parameter_tag {
+	Uint32 active_video_parameter_set_id; 
+	Uint32 self_contained_cvs_flag;
+	Uint32 no_parameter_set_update_flag;
+
+	Uint32 num_sps_ids_minus1;
+#define MAX_NUM_SEQ_ID 20
+	Uint32 active_seq_parameter_set_id[MAX_NUM_SEQ_ID];
+} sei_active_parameter_t;
+
+typedef enum 
+{
+	BUFFERING_PERIOD = 0,
+	PICTURE_TIMING,
+	FILLER_PAYLOAD = 3,                      
+	USER_DATA_REGISTERED_ITU_T_T35,      
+	USER_DATA_UNREGISTERED,              
+	RECOVERY_POINT,                      
+	SCENE_INFO = 9,                          
+	FULL_FRAME_SNAPSHOT = 15,                 
+	PROGRESSIVE_REFINEMENT_SEGMENT_START,
+	PROGRESSIVE_REFINEMENT_SEGMENT_END,  
+	FILM_GRAIN_CHARACTERISTICS = 19,          
+	POST_FILTER_HINT = 22,                    
+	TONE_MAPPING_INFO,                   
+	KNEE_FUNCTION_INFO,                  
+	FRAME_PACKING = 45,                       
+	DISPLAY_ORIENTATION = 47,                 
+	SOP_DESCRIPTION,                     
+	ACTIVE_PARAMETER_SETS = 129,               
+	DECODING_UNIT_INFO,                  
+	TEMPORAL_LEVEL0_INDEX,               
+	DECODED_PICTURE_HASH,                
+	SCALABLE_NESTING = 133,                    
+	REGION_REFRESH_INFO,                 
+	NO_DISPLAY,                          
+	TIME_CODE,                           
+	MASTERING_DISPLAY_COLOUR_VOLUME,     
+	SEGM_RECT_FRAME_PACKING,             
+	TEMP_MOTION_CONSTRAINED_TILE_SETS,   
+	CHROMA_SAMPLING_FILTER_HINT
+} SeiPayloadType;
+
+enum 
+{
+	SNT_TRAIL_N         = 0,
+	SNT_TRAIL_R         = 1,
+	SNT_TSA_N           = 2,
+	SNT_TSA_R           = 3,
+	SNT_STSA_N          = 4,
+	SNT_STSA_R          = 5,
+	SNT_RADL_N          = 6,
+	SNT_RADL_R          = 7,
+	SNT_RASL_N          = 8,
+	SNT_RASL_R          = 9,
+	SNT_RSV_N10         = 10,
+	SNT_RSV_R11         = 11,
+	SNT_RSV_N12         = 12,
+	SNT_RSV_R13         = 13,
+	SNT_RSV_N14         = 14,
+	SNT_RSV_R15         = 15,
+	SNT_BLA_W_LP        = 16,
+	SNT_BLA_W_RADL      = 17,
+	SNT_BLA_N_LP        = 18,
+	SNT_IDR_W_RADL      = 19,
+	SNT_IDR_N_LP        = 20,
+	SNT_CRA             = 21,
+	SNT_RSV_IRAP22      = 22,
+	SNT_RSV_IRAP23      = 23,
+	SNT_VPS             = 32,
+	SNT_SPS             = 33,
+	SNT_PPS             = 34,
+	SNT_AUD             = 35,
+	SNT_EOS             = 36,
+	SNT_EOB             = 37,
+	SNT_FD              = 38,
+	SNT_PREFIX_SEI      = 39,
+	SNT_SUFFIX_SEI      = 40,
+};
+
+typedef struct 
+{
+	Uint32 vui_parameters_presesent_flag;
+
+	// vui_present_flags
+	Uint32 neutral_chroma_indication_flag;
+	Uint32 field_seq_flag;		// this syntax shall be 1 when pic_struct in sei_pic_timing is 1 or 2
+	Uint32 frame_field_info_present_flag;	//this syntax shall be 1 when pic_struct in sei_pic_timing is not 0
+	Uint32 aspect_ratio_info_present_flag;
+	Uint32 overscan_info_present_flag;
+	Uint32 video_signal_type_present_flag;
+	Uint32 colour_description_present_flag;
+	Uint32 chroma_loc_info_present_flag;
+	Uint32 default_display_window_flag;
+	Uint32 vui_timing_info_present_flag;
+	Uint32 bitstream_restriction_flag;
+
+	// vui_aspect_ratio_idc
+	Uint32 aspect_ratio_idc;
+
+	// vui_sar_size
+	Uint32 sar_width;
+	Uint32 sar_height;
+
+	// vui_overscan_appropriate
+	Uint32 overscan_appropriate_flag;
+
+	// vui_video_signal
+	Uint32 video_format;
+	Uint32 video_full_range_flag;
+	Uint32 colour_primaries;
+	Uint32 transfer_characteristics;
+	Uint32 matrix_coeffs;
+
+	// vui_chroma_sample_loc
+	Uint32 chroma_sample_loc_type_top_field;
+	Uint32 chroma_sample_loc_type_bottom_field;
+
+	// vui_disp_win_left_right
+	Uint32 def_disp_win_left_offset;
+	Uint32 def_disp_win_right_offset;
+
+	// vui_disp_win_top_bot
+	Uint32 def_disp_win_top_offset;
+	Uint32 def_disp_win_bottom_offset;
+
+	Uint32 vui_hrd_parameters_present_flag;
+
+	Uint32 vui_num_units_in_tick;     
+	Uint32 vui_time_scale;     
+	Uint32 vui_poc_proportional_to_timing_flag;     
+	Uint32 vui_num_ticks_poc_diff_one_minus1; 
+
+	Uint32 tiles_fixed_structure_flag;     
+	Uint32 motion_vectors_over_pic_boundaries_flag;     
+	Uint32 restricted_ref_pic_lists_flag;     
+	Uint32 min_spatial_segmentation_idc; 
+	Uint32 max_bytes_per_pic_denom; 
+	Uint32 max_bits_per_min_cu_denom; 
+	Uint32 log2_max_mv_length_horizontal; 
+	Uint32 log2_max_mv_length_vertical; 
+
+} vui_t;
+
+typedef struct 
+{
+	Uint32 encodeRbspHrdInVui;
+	Uint32 encodeRbspHrdInVps;
+
+	Uint32 commonInfPresentFlag;
+	Uint32 vps_max_sub_layers_minus1; // this parameter is from VPS
+
+	Uint32 nal_hrd_parameters_present_flag;
+	Uint32 vcl_hrd_parameters_present_flag;
+	Uint32 sub_pic_hrd_params_present_flag;
+
+	Uint32 tick_divisor_minus2;
+	Uint32 du_cpb_removal_delay_increment_length_minus1;
+	Uint32 sub_pic_cpb_params_in_pic_timing_sei_flag;
+	Uint32 dpb_output_delay_du_length_minus1;
+
+	Uint32 bit_rate_scale;
+	Uint32 cpb_size_scale;
+
+	Uint32 cpb_size_du_scale;
+	Uint32 initial_cpb_removal_delay_length_minus1;
+	Uint32 au_cpb_removal_delay_length_minus1;
+	Uint32 dpb_output_delay_length_minus1;
+
+	Uint32 fixed_pic_rate_general_flag[MAX_VPS_MAX_SUB_LAYERS];
+	Uint32 fixed_pic_rate_within_cvs_flag[MAX_VPS_MAX_SUB_LAYERS];
+	Uint32 elemental_duration_in_tc_minus1[MAX_VPS_MAX_SUB_LAYERS];
+	Uint32 low_delay_hrd_flag[MAX_VPS_MAX_SUB_LAYERS];
+	Uint32 cpb_cnt_minus1[MAX_VPS_MAX_SUB_LAYERS];
+
+	//sub_layer_hrd_parameters(
+
+	Uint32 bit_rate_value_minus1[MAX_CPB_COUNT][MAX_VPS_MAX_SUB_LAYERS];
+	Uint32 cpb_size_value_minus1[MAX_CPB_COUNT][MAX_VPS_MAX_SUB_LAYERS];
+	Uint32 cpb_size_du_value_minus1[MAX_CPB_COUNT][MAX_VPS_MAX_SUB_LAYERS];
+	Uint32 bit_rate_du_value_minus1[MAX_CPB_COUNT][MAX_VPS_MAX_SUB_LAYERS];
+	Uint32 cbr_flag[MAX_CPB_COUNT][MAX_VPS_MAX_SUB_LAYERS];	
+
+} hrd_t;
+
+#endif /* __HEADER_STRUCT_H__ */
+ 

+ 288 - 0
wave420l/code/sample/helper/misc/md5.c

@@ -0,0 +1,288 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "main_helper.h"
+
+#define MD5_CBLOCK	64
+#define MD5_LBLOCK	(MD5_CBLOCK/4)
+#define MD5_DIGEST_LENGTH 16
+
+#define DATA_ORDER_IS_LITTLE_ENDIAN
+
+#define	HASH_MAKE_STRING(c,s)	do {	\
+	unsigned long ll;		\
+	ll=(c)->A; HOST_l2c(ll,(s));	\
+	ll=(c)->B; HOST_l2c(ll,(s));	\
+	ll=(c)->C; HOST_l2c(ll,(s));	\
+	ll=(c)->D; HOST_l2c(ll,(s));	\
+	} while (0)
+
+#define ROTATE(a,n)     (((a)<<(n))|(((a)&0xffffffff)>>(32-(n))))
+
+#if defined(DATA_ORDER_IS_BIG_ENDIAN)
+#define HOST_c2l(c,l) \
+	(l =(((unsigned long)(*((c)++)))<<24),		\
+	 l|=(((unsigned long)(*((c)++)))<<16),		\
+	 l|=(((unsigned long)(*((c)++)))<< 8),		\
+	 l|=(((unsigned long)(*((c)++)))    ))
+    
+#define HOST_l2c(l,c) \
+	(*((c)++)=(unsigned char)(((l)>>24)&0xff),	\
+	 *((c)++)=(unsigned char)(((l)>>16)&0xff),	\
+	 *((c)++)=(unsigned char)(((l)>> 8)&0xff),	\
+	 *((c)++)=(unsigned char)(((l)    )&0xff))
+#endif
+#if defined(DATA_ORDER_IS_LITTLE_ENDIAN)
+#define HOST_c2l(c,l) \
+	(l =(((unsigned long)(*((c)++)))    ),		\
+	 l|=(((unsigned long)(*((c)++)))<< 8),		\
+	 l|=(((unsigned long)(*((c)++)))<<16),		\
+	 l|=(((unsigned long)(*((c)++)))<<24))
+
+#define HOST_l2c(l,c) \
+	(*((c)++)=(unsigned char)(((l)    )&0xff),	\
+	 *((c)++)=(unsigned char)(((l)>> 8)&0xff),	\
+	 *((c)++)=(unsigned char)(((l)>>16)&0xff),	\
+	 *((c)++)=(unsigned char)(((l)>>24)&0xff))
+#endif
+
+#define MD32_REG_T long
+
+#define	F(b,c,d)	((((c) ^ (d)) & (b)) ^ (d))
+#define	G(b,c,d)	((((b) ^ (c)) & (d)) ^ (c))
+#define	H(b,c,d)	((b) ^ (c) ^ (d))
+#define	I(b,c,d)	(((~(d)) | (b)) ^ (c))
+
+#define R0(a,b,c,d,k,s,t) { \
+	a+=((k)+(t)+F((b),(c),(d))); \
+	a=ROTATE(a,s); \
+	a+=b; };
+#define R1(a,b,c,d,k,s,t) { \
+	a+=((k)+(t)+G((b),(c),(d))); \
+	a=ROTATE(a,s); \
+	a+=b; };
+#define R2(a,b,c,d,k,s,t) { \
+	a+=((k)+(t)+H((b),(c),(d))); \
+	a=ROTATE(a,s); \
+	a+=b; };
+#define R3(a,b,c,d,k,s,t) { \
+	a+=((k)+(t)+I((b),(c),(d))); \
+	a=ROTATE(a,s); \
+	a+=b; };
+
+void md5_block_data_order (MD5_CTX *c, const void *data_, size_t num)
+{
+	const unsigned char *data=data_;
+	register unsigned MD32_REG_T A,B,C,D,l;
+#ifndef MD32_XARRAY
+	/* See comment in crypto/sha/sha_locl.h for details. */
+	unsigned MD32_REG_T	XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7,
+						XX8, XX9,XX10,XX11,XX12,XX13,XX14,XX15;
+# define X(i)	XX##i
+#else
+	Uint32 XX[MD5_LBLOCK];
+# define X(i)	XX[i]
+#endif
+
+	A=c->A;
+	B=c->B;
+	C=c->C;
+	D=c->D;
+
+	for (;num--;) {
+		HOST_c2l(data,l); X( 0)=l;
+		HOST_c2l(data,l); X( 1)=l;
+		/* Round 0 */
+		R0(A,B,C,D,X( 0), 7,0xd76aa478L);	HOST_c2l(data,l); X( 2)=l;
+		R0(D,A,B,C,X( 1),12,0xe8c7b756L);	HOST_c2l(data,l); X( 3)=l;
+		R0(C,D,A,B,X( 2),17,0x242070dbL);	HOST_c2l(data,l); X( 4)=l;
+		R0(B,C,D,A,X( 3),22,0xc1bdceeeL);	HOST_c2l(data,l); X( 5)=l;
+		R0(A,B,C,D,X( 4), 7,0xf57c0fafL);	HOST_c2l(data,l); X( 6)=l;
+		R0(D,A,B,C,X( 5),12,0x4787c62aL);	HOST_c2l(data,l); X( 7)=l;
+		R0(C,D,A,B,X( 6),17,0xa8304613L);	HOST_c2l(data,l); X( 8)=l;
+		R0(B,C,D,A,X( 7),22,0xfd469501L);	HOST_c2l(data,l); X( 9)=l;
+		R0(A,B,C,D,X( 8), 7,0x698098d8L);	HOST_c2l(data,l); X(10)=l;
+		R0(D,A,B,C,X( 9),12,0x8b44f7afL);	HOST_c2l(data,l); X(11)=l;
+		R0(C,D,A,B,X(10),17,0xffff5bb1L);	HOST_c2l(data,l); X(12)=l;
+		R0(B,C,D,A,X(11),22,0x895cd7beL);	HOST_c2l(data,l); X(13)=l;
+		R0(A,B,C,D,X(12), 7,0x6b901122L);	HOST_c2l(data,l); X(14)=l;
+		R0(D,A,B,C,X(13),12,0xfd987193L);	HOST_c2l(data,l); X(15)=l;
+		R0(C,D,A,B,X(14),17,0xa679438eL);
+		R0(B,C,D,A,X(15),22,0x49b40821L);
+		/* Round 1 */
+		R1(A,B,C,D,X( 1), 5,0xf61e2562L);
+		R1(D,A,B,C,X( 6), 9,0xc040b340L);
+		R1(C,D,A,B,X(11),14,0x265e5a51L);
+		R1(B,C,D,A,X( 0),20,0xe9b6c7aaL);
+		R1(A,B,C,D,X( 5), 5,0xd62f105dL);
+		R1(D,A,B,C,X(10), 9,0x02441453L);
+		R1(C,D,A,B,X(15),14,0xd8a1e681L);
+		R1(B,C,D,A,X( 4),20,0xe7d3fbc8L);
+		R1(A,B,C,D,X( 9), 5,0x21e1cde6L);
+		R1(D,A,B,C,X(14), 9,0xc33707d6L);
+		R1(C,D,A,B,X( 3),14,0xf4d50d87L);
+		R1(B,C,D,A,X( 8),20,0x455a14edL);
+		R1(A,B,C,D,X(13), 5,0xa9e3e905L);
+		R1(D,A,B,C,X( 2), 9,0xfcefa3f8L);
+		R1(C,D,A,B,X( 7),14,0x676f02d9L);
+		R1(B,C,D,A,X(12),20,0x8d2a4c8aL);
+		/* Round 2 */
+		R2(A,B,C,D,X( 5), 4,0xfffa3942L);
+		R2(D,A,B,C,X( 8),11,0x8771f681L);
+		R2(C,D,A,B,X(11),16,0x6d9d6122L);
+		R2(B,C,D,A,X(14),23,0xfde5380cL);
+		R2(A,B,C,D,X( 1), 4,0xa4beea44L);
+		R2(D,A,B,C,X( 4),11,0x4bdecfa9L);
+		R2(C,D,A,B,X( 7),16,0xf6bb4b60L);
+		R2(B,C,D,A,X(10),23,0xbebfbc70L);
+		R2(A,B,C,D,X(13), 4,0x289b7ec6L);
+		R2(D,A,B,C,X( 0),11,0xeaa127faL);
+		R2(C,D,A,B,X( 3),16,0xd4ef3085L);
+		R2(B,C,D,A,X( 6),23,0x04881d05L);
+		R2(A,B,C,D,X( 9), 4,0xd9d4d039L);
+		R2(D,A,B,C,X(12),11,0xe6db99e5L);
+		R2(C,D,A,B,X(15),16,0x1fa27cf8L);
+		R2(B,C,D,A,X( 2),23,0xc4ac5665L);
+		/* Round 3 */
+		R3(A,B,C,D,X( 0), 6,0xf4292244L);
+		R3(D,A,B,C,X( 7),10,0x432aff97L);
+		R3(C,D,A,B,X(14),15,0xab9423a7L);
+		R3(B,C,D,A,X( 5),21,0xfc93a039L);
+		R3(A,B,C,D,X(12), 6,0x655b59c3L);
+		R3(D,A,B,C,X( 3),10,0x8f0ccc92L);
+		R3(C,D,A,B,X(10),15,0xffeff47dL);
+		R3(B,C,D,A,X( 1),21,0x85845dd1L);
+		R3(A,B,C,D,X( 8), 6,0x6fa87e4fL);
+		R3(D,A,B,C,X(15),10,0xfe2ce6e0L);
+		R3(C,D,A,B,X( 6),15,0xa3014314L);
+		R3(B,C,D,A,X(13),21,0x4e0811a1L);
+		R3(A,B,C,D,X( 4), 6,0xf7537e82L);
+		R3(D,A,B,C,X(11),10,0xbd3af235L);
+		R3(C,D,A,B,X( 2),15,0x2ad7d2bbL);
+		R3(B,C,D,A,X( 9),21,0xeb86d391L);
+
+		A = c->A += A;
+		B = c->B += B;
+		C = c->C += C;
+		D = c->D += D;
+	}
+}
+
+/* Implemented from RFC1321 The MD5 Message-Digest Algorithm
+ */
+
+#define INIT_DATA_A (unsigned long)0x67452301L
+#define INIT_DATA_B (unsigned long)0xefcdab89L
+#define INIT_DATA_C (unsigned long)0x98badcfeL
+#define INIT_DATA_D (unsigned long)0x10325476L
+
+Int32 MD5_Init (MD5_CTX *c)
+{
+	c->A=INIT_DATA_A;
+	c->B=INIT_DATA_B;
+	c->C=INIT_DATA_C;
+	c->D=INIT_DATA_D;
+	c->Nl=0;
+	c->Nh=0;
+	c->num=0;
+	return 1;
+}
+
+Int32 MD5_Update (MD5_CTX *c, const void *data_, size_t len)
+{
+	const unsigned char *data=data_;
+	unsigned char *p;
+	Uint32 l;
+	size_t n;
+
+	if (len==0) return 1;
+
+	l=(c->Nl+(((Uint32)len)<<3))&0xffffffffUL;
+	/* 95-05-24 eay Fixed a bug with the overflow handling, thanks to
+	 * Wei Dai <weidai@eskimo.com> for pointing it out. */
+	if (l < c->Nl) /* overflow */
+		c->Nh++;
+	c->Nh+=(len>>29);	/* might cause compiler warning on 16-bit */
+	c->Nl=l;
+
+	n = c->num;
+	if (n != 0) {
+		p=(unsigned char *)c->data;
+
+		if (len >= MD5_CBLOCK || len+n >= MD5_CBLOCK) {
+			osal_memcpy (p+n,data,MD5_CBLOCK-n);
+			md5_block_data_order (c,p,1);
+			n      = MD5_CBLOCK-n;
+			data  += n;
+			len   -= n;
+			c->num = 0;
+			osal_memset (p,0,MD5_CBLOCK);	/* keep it zeroed */
+		} else {
+			osal_memcpy (p+n,data,len);
+			c->num += (unsigned int)len;
+			return 1;
+		}
+	}
+
+	n = len/MD5_CBLOCK;
+	if (n > 0) {
+		md5_block_data_order (c,data,n);
+		n    *= MD5_CBLOCK;
+		data += n;
+		len  -= n;
+	}
+
+	if (len != 0) {
+		p = (unsigned char *)c->data;
+		c->num = len;
+		osal_memcpy (p,data,len);
+	}
+	return 1;
+}
+
+Int32 MD5_Final (Uint8* md, MD5_CTX *c)
+{
+	unsigned char *p = (unsigned char *)c->data;
+	size_t n = c->num;
+
+	p[n] = 0x80; /* there is always room for one */
+	n++;
+
+	if (n > (MD5_CBLOCK-8)) {
+		osal_memset (p+n,0,MD5_CBLOCK-n);
+		n=0;
+		md5_block_data_order (c,p,1);
+	}
+	osal_memset (p+n,0,MD5_CBLOCK-8-n);
+
+	p += MD5_CBLOCK-8;
+#if   defined(DATA_ORDER_IS_BIG_ENDIAN)
+	(void)HOST_l2c(c->Nh,p);
+	(void)HOST_l2c(c->Nl,p);
+#elif defined(DATA_ORDER_IS_LITTLE_ENDIAN)
+	(void)HOST_l2c(c->Nl,p);
+	(void)HOST_l2c(c->Nh,p);
+#endif
+	p -= MD5_CBLOCK;
+	md5_block_data_order (c,p,1);
+	c->num=0;
+	osal_memset (p,0,MD5_CBLOCK);
+
+	HASH_MAKE_STRING(c,md);
+
+	return 1;
+}
+
+Uint8* MD5 (const Uint8* d, size_t n, Uint8* md)
+{
+	MD5_CTX c;
+	static unsigned char m[MD5_DIGEST_LENGTH];
+
+	if (md == NULL) md=m;
+	if (!MD5_Init(&c))
+		return NULL;
+	MD5_Update(&c,d,n);
+	MD5_Final(md,&c);
+	return(md);
+}
+ 

Some files were not shown because too many files changed in this diff