Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > e9a2bf4cbad8eb886872edae7c352314 > files > 38

libvpx-devel-1.0.0-1.fc15.i686.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>WebM VP8 Codec SDK: vpxenc</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.7.4 -->
<div id="top">
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">WebM VP8 Codec SDK</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li class="current"><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="samples.html">Sample Code</a>      </li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<div class="title">vpxenc </div>  </div>
</div>
<div class="contents">
<div class="textblock"><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.</span>
<a name="l00003"></a>00003 <span class="comment"> *</span>
<a name="l00004"></a>00004 <span class="comment"> *  Use of this source code is governed by a BSD-style license</span>
<a name="l00005"></a>00005 <span class="comment"> *  that can be found in the LICENSE file in the root of the source</span>
<a name="l00006"></a>00006 <span class="comment"> *  tree. An additional intellectual property rights grant can be found</span>
<a name="l00007"></a>00007 <span class="comment"> *  in the file PATENTS.  All contributing project authors may</span>
<a name="l00008"></a>00008 <span class="comment"> *  be found in the AUTHORS file in the root of the source tree.</span>
<a name="l00009"></a>00009 <span class="comment"> */</span>
<a name="l00010"></a>00010 
<a name="l00011"></a>00011 
<a name="l00012"></a>00012 <span class="comment">/* This is a simple program that encodes YV12 files and generates ivf</span>
<a name="l00013"></a>00013 <span class="comment"> * files using the new interface.</span>
<a name="l00014"></a>00014 <span class="comment"> */</span>
<a name="l00015"></a>00015 <span class="preprocessor">#if defined(_WIN32) || !CONFIG_OS_SUPPORT</span>
<a name="l00016"></a>00016 <span class="preprocessor"></span><span class="preprocessor">#define USE_POSIX_MMAP 0</span>
<a name="l00017"></a>00017 <span class="preprocessor"></span><span class="preprocessor">#else</span>
<a name="l00018"></a>00018 <span class="preprocessor"></span><span class="preprocessor">#define USE_POSIX_MMAP 1</span>
<a name="l00019"></a>00019 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00020"></a>00020 <span class="preprocessor"></span>
<a name="l00021"></a>00021 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
<a name="l00022"></a>00022 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
<a name="l00023"></a>00023 <span class="preprocessor">#include &lt;stdarg.h&gt;</span>
<a name="l00024"></a>00024 <span class="preprocessor">#include &lt;string.h&gt;</span>
<a name="l00025"></a>00025 <span class="preprocessor">#include &lt;limits.h&gt;</span>
<a name="l00026"></a>00026 <span class="preprocessor">#include &lt;assert.h&gt;</span>
<a name="l00027"></a>00027 <span class="preprocessor">#include &quot;<a class="code" href="vpx__encoder_8h.html" title="Describes the encoder algorithm interface to applications.">vpx/vpx_encoder.h</a>&quot;</span>
<a name="l00028"></a>00028 <span class="preprocessor">#if USE_POSIX_MMAP</span>
<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include &lt;sys/types.h&gt;</span>
<a name="l00030"></a>00030 <span class="preprocessor">#include &lt;sys/stat.h&gt;</span>
<a name="l00031"></a>00031 <span class="preprocessor">#include &lt;sys/mman.h&gt;</span>
<a name="l00032"></a>00032 <span class="preprocessor">#include &lt;fcntl.h&gt;</span>
<a name="l00033"></a>00033 <span class="preprocessor">#include &lt;unistd.h&gt;</span>
<a name="l00034"></a>00034 <span class="preprocessor">#endif</span>
<a name="l00035"></a>00035 <span class="preprocessor"></span><span class="preprocessor">#include &quot;<a class="code" href="vp8cx_8h.html" title="Provides definitions for using the VP8 encoder algorithm within the vpx Codec Interface.">vpx/vp8cx.h</a>&quot;</span>
<a name="l00036"></a>00036 <span class="preprocessor">#include &quot;vpx_ports/mem_ops.h&quot;</span>
<a name="l00037"></a>00037 <span class="preprocessor">#include &quot;vpx_ports/vpx_timer.h&quot;</span>
<a name="l00038"></a>00038 <span class="preprocessor">#include &quot;tools_common.h&quot;</span>
<a name="l00039"></a>00039 <span class="preprocessor">#include &quot;y4minput.h&quot;</span>
<a name="l00040"></a>00040 <span class="preprocessor">#include &quot;libmkv/EbmlWriter.h&quot;</span>
<a name="l00041"></a>00041 <span class="preprocessor">#include &quot;libmkv/EbmlIDs.h&quot;</span>
<a name="l00042"></a>00042 
<a name="l00043"></a>00043 <span class="comment">/* Need special handling of these functions on Windows */</span>
<a name="l00044"></a>00044 <span class="preprocessor">#if defined(_MSC_VER)</span>
<a name="l00045"></a>00045 <span class="preprocessor"></span><span class="comment">/* MSVS doesn&#39;t define off_t, and uses _f{seek,tell}i64 */</span>
<a name="l00046"></a>00046 <span class="keyword">typedef</span> __int64 off_t;
<a name="l00047"></a>00047 <span class="preprocessor">#define fseeko _fseeki64</span>
<a name="l00048"></a>00048 <span class="preprocessor"></span><span class="preprocessor">#define ftello _ftelli64</span>
<a name="l00049"></a>00049 <span class="preprocessor"></span><span class="preprocessor">#elif defined(_WIN32)</span>
<a name="l00050"></a>00050 <span class="preprocessor"></span><span class="comment">/* MinGW defines off_t as long</span>
<a name="l00051"></a>00051 <span class="comment">   and uses f{seek,tell}o64/off64_t for large files */</span>
<a name="l00052"></a>00052 <span class="preprocessor">#define fseeko fseeko64</span>
<a name="l00053"></a>00053 <span class="preprocessor"></span><span class="preprocessor">#define ftello ftello64</span>
<a name="l00054"></a>00054 <span class="preprocessor"></span><span class="preprocessor">#define off_t off64_t</span>
<a name="l00055"></a>00055 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00056"></a>00056 <span class="preprocessor"></span>
<a name="l00057"></a>00057 <span class="preprocessor">#if defined(_MSC_VER)</span>
<a name="l00058"></a>00058 <span class="preprocessor"></span><span class="preprocessor">#define LITERALU64(n) n</span>
<a name="l00059"></a>00059 <span class="preprocessor"></span><span class="preprocessor">#else</span>
<a name="l00060"></a>00060 <span class="preprocessor"></span><span class="preprocessor">#define LITERALU64(n) n##LLU</span>
<a name="l00061"></a>00061 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00062"></a>00062 <span class="preprocessor"></span>
<a name="l00063"></a>00063 <span class="comment">/* We should use 32-bit file operations in WebM file format</span>
<a name="l00064"></a>00064 <span class="comment"> * when building ARM executable file (.axf) with RVCT */</span>
<a name="l00065"></a>00065 <span class="preprocessor">#if !CONFIG_OS_SUPPORT</span>
<a name="l00066"></a>00066 <span class="preprocessor"></span><span class="keyword">typedef</span> <span class="keywordtype">long</span> off_t;
<a name="l00067"></a>00067 <span class="preprocessor">#define fseeko fseek</span>
<a name="l00068"></a>00068 <span class="preprocessor"></span><span class="preprocessor">#define ftello ftell</span>
<a name="l00069"></a>00069 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00070"></a>00070 <span class="preprocessor"></span>
<a name="l00071"></a>00071 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> *exec_name;
<a name="l00072"></a>00072 
<a name="l00073"></a>00073 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">struct </span>codec_item
<a name="l00074"></a>00074 {
<a name="l00075"></a>00075     <span class="keywordtype">char</span> <span class="keyword">const</span>              *name;
<a name="l00076"></a>00076     <span class="keyword">const</span> <a class="code" href="group__codec.html#gad654f3da60151f5dfef70aca00ef1e9e" title="Codec interface structure.">vpx_codec_iface_t</a> *iface;
<a name="l00077"></a>00077     <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>             fourcc;
<a name="l00078"></a>00078 } codecs[] =
<a name="l00079"></a>00079 {
<a name="l00080"></a>00080 <span class="preprocessor">#if CONFIG_VP8_ENCODER</span>
<a name="l00081"></a>00081 <span class="preprocessor"></span>    {<span class="stringliteral">&quot;vp8&quot;</span>,  &amp;vpx_codec_vp8_cx_algo, 0x30385056},
<a name="l00082"></a>00082 <span class="preprocessor">#endif</span>
<a name="l00083"></a>00083 <span class="preprocessor"></span>};
<a name="l00084"></a>00084 
<a name="l00085"></a>00085 <span class="keyword">static</span> <span class="keywordtype">void</span> usage_exit();
<a name="l00086"></a>00086 
<a name="l00087"></a>00087 <span class="keywordtype">void</span> die(<span class="keyword">const</span> <span class="keywordtype">char</span> *fmt, ...)
<a name="l00088"></a>00088 {
<a name="l00089"></a>00089     va_list ap;
<a name="l00090"></a>00090     va_start(ap, fmt);
<a name="l00091"></a>00091     vfprintf(stderr, fmt, ap);
<a name="l00092"></a>00092     fprintf(stderr, <span class="stringliteral">&quot;\n&quot;</span>);
<a name="l00093"></a>00093     usage_exit();
<a name="l00094"></a>00094 }
<a name="l00095"></a>00095 
<a name="l00096"></a>00096 <span class="keyword">static</span> <span class="keywordtype">void</span> ctx_exit_on_error(<a class="code" href="structvpx__codec__ctx.html" title="Codec context structure.">vpx_codec_ctx_t</a> *ctx, <span class="keyword">const</span> <span class="keywordtype">char</span> *s)
<a name="l00097"></a>00097 {
<a name="l00098"></a>00098     <span class="keywordflow">if</span> (ctx-&gt;<a class="code" href="structvpx__codec__ctx.html#a6f448802b0675013fd8c5179675c30de">err</a>)
<a name="l00099"></a>00099     {
<a name="l00100"></a>00100         <span class="keyword">const</span> <span class="keywordtype">char</span> *detail = <a class="code" href="group__codec.html#ga29273cb552ed1a437fe263c4a0a54300" title="Retrieve detailed error information for codec context.">vpx_codec_error_detail</a>(ctx);
<a name="l00101"></a>00101 
<a name="l00102"></a>00102         fprintf(stderr, <span class="stringliteral">&quot;%s: %s\n&quot;</span>, s, <a class="code" href="group__codec.html#ga4d265df00d42b36a4f0e3eb83fc22c5e" title="Retrieve error synopsis for codec context.">vpx_codec_error</a>(ctx));
<a name="l00103"></a>00103 
<a name="l00104"></a>00104         <span class="keywordflow">if</span> (detail)
<a name="l00105"></a>00105             fprintf(stderr, <span class="stringliteral">&quot;    %s\n&quot;</span>, detail);
<a name="l00106"></a>00106 
<a name="l00107"></a>00107         exit(EXIT_FAILURE);
<a name="l00108"></a>00108     }
<a name="l00109"></a>00109 }
<a name="l00110"></a>00110 
<a name="l00111"></a>00111 <span class="comment">/* This structure is used to abstract the different ways of handling</span>
<a name="l00112"></a>00112 <span class="comment"> * first pass statistics.</span>
<a name="l00113"></a>00113 <span class="comment"> */</span>
<a name="l00114"></a>00114 <span class="keyword">typedef</span> <span class="keyword">struct</span>
<a name="l00115"></a>00115 {
<a name="l00116"></a>00116     <a class="code" href="structvpx__fixed__buf.html" title="Generic fixed size buffer structure.">vpx_fixed_buf_t</a> buf;
<a name="l00117"></a>00117     <span class="keywordtype">int</span>             pass;
<a name="l00118"></a>00118     FILE           *file;
<a name="l00119"></a>00119     <span class="keywordtype">char</span>           *buf_ptr;
<a name="l00120"></a>00120     <span class="keywordtype">size_t</span>          buf_alloc_sz;
<a name="l00121"></a>00121 } stats_io_t;
<a name="l00122"></a>00122 
<a name="l00123"></a>00123 <span class="keywordtype">int</span> stats_open_file(stats_io_t *stats, <span class="keyword">const</span> <span class="keywordtype">char</span> *fpf, <span class="keywordtype">int</span> pass)
<a name="l00124"></a>00124 {
<a name="l00125"></a>00125     <span class="keywordtype">int</span> res;
<a name="l00126"></a>00126 
<a name="l00127"></a>00127     stats-&gt;pass = pass;
<a name="l00128"></a>00128 
<a name="l00129"></a>00129     <span class="keywordflow">if</span> (pass == 0)
<a name="l00130"></a>00130     {
<a name="l00131"></a>00131         stats-&gt;file = fopen(fpf, <span class="stringliteral">&quot;wb&quot;</span>);
<a name="l00132"></a>00132         stats-&gt;buf.sz = 0;
<a name="l00133"></a>00133         stats-&gt;buf.buf = NULL,
<a name="l00134"></a>00134                    res = (stats-&gt;file != NULL);
<a name="l00135"></a>00135     }
<a name="l00136"></a>00136     <span class="keywordflow">else</span>
<a name="l00137"></a>00137     {
<a name="l00138"></a>00138 <span class="preprocessor">#if 0</span>
<a name="l00139"></a>00139 <span class="preprocessor"></span><span class="preprocessor">#elif USE_POSIX_MMAP</span>
<a name="l00140"></a>00140 <span class="preprocessor"></span>        <span class="keyword">struct </span>stat stat_buf;
<a name="l00141"></a>00141         <span class="keywordtype">int</span> fd;
<a name="l00142"></a>00142 
<a name="l00143"></a>00143         fd = open(fpf, O_RDONLY);
<a name="l00144"></a>00144         stats-&gt;file = fdopen(fd, <span class="stringliteral">&quot;rb&quot;</span>);
<a name="l00145"></a>00145         fstat(fd, &amp;stat_buf);
<a name="l00146"></a>00146         stats-&gt;buf.sz = stat_buf.st_size;
<a name="l00147"></a>00147         stats-&gt;buf.buf = mmap(NULL, stats-&gt;buf.sz, PROT_READ, MAP_PRIVATE,
<a name="l00148"></a>00148                               fd, 0);
<a name="l00149"></a>00149         res = (stats-&gt;buf.buf != NULL);
<a name="l00150"></a>00150 <span class="preprocessor">#else</span>
<a name="l00151"></a>00151 <span class="preprocessor"></span>        <span class="keywordtype">size_t</span> nbytes;
<a name="l00152"></a>00152 
<a name="l00153"></a>00153         stats-&gt;file = fopen(fpf, <span class="stringliteral">&quot;rb&quot;</span>);
<a name="l00154"></a>00154 
<a name="l00155"></a>00155         <span class="keywordflow">if</span> (fseek(stats-&gt;file, 0, SEEK_END))
<a name="l00156"></a>00156         {
<a name="l00157"></a>00157             fprintf(stderr, <span class="stringliteral">&quot;First-pass stats file must be seekable!\n&quot;</span>);
<a name="l00158"></a>00158             exit(EXIT_FAILURE);
<a name="l00159"></a>00159         }
<a name="l00160"></a>00160 
<a name="l00161"></a>00161         stats-&gt;buf.sz = stats-&gt;buf_alloc_sz = ftell(stats-&gt;file);
<a name="l00162"></a>00162         rewind(stats-&gt;file);
<a name="l00163"></a>00163 
<a name="l00164"></a>00164         stats-&gt;buf.buf = malloc(stats-&gt;buf_alloc_sz);
<a name="l00165"></a>00165 
<a name="l00166"></a>00166         <span class="keywordflow">if</span> (!stats-&gt;buf.buf)
<a name="l00167"></a>00167         {
<a name="l00168"></a>00168             fprintf(stderr, <span class="stringliteral">&quot;Failed to allocate first-pass stats buffer (%lu bytes)\n&quot;</span>,
<a name="l00169"></a>00169                     (<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>)stats-&gt;buf_alloc_sz);
<a name="l00170"></a>00170             exit(EXIT_FAILURE);
<a name="l00171"></a>00171         }
<a name="l00172"></a>00172 
<a name="l00173"></a>00173         nbytes = fread(stats-&gt;buf.buf, 1, stats-&gt;buf.sz, stats-&gt;file);
<a name="l00174"></a>00174         res = (nbytes == stats-&gt;buf.sz);
<a name="l00175"></a>00175 <span class="preprocessor">#endif</span>
<a name="l00176"></a>00176 <span class="preprocessor"></span>    }
<a name="l00177"></a>00177 
<a name="l00178"></a>00178     <span class="keywordflow">return</span> res;
<a name="l00179"></a>00179 }
<a name="l00180"></a>00180 
<a name="l00181"></a>00181 <span class="keywordtype">int</span> stats_open_mem(stats_io_t *stats, <span class="keywordtype">int</span> pass)
<a name="l00182"></a>00182 {
<a name="l00183"></a>00183     <span class="keywordtype">int</span> res;
<a name="l00184"></a>00184     stats-&gt;pass = pass;
<a name="l00185"></a>00185 
<a name="l00186"></a>00186     <span class="keywordflow">if</span> (!pass)
<a name="l00187"></a>00187     {
<a name="l00188"></a>00188         stats-&gt;buf.sz = 0;
<a name="l00189"></a>00189         stats-&gt;buf_alloc_sz = 64 * 1024;
<a name="l00190"></a>00190         stats-&gt;buf.buf = malloc(stats-&gt;buf_alloc_sz);
<a name="l00191"></a>00191     }
<a name="l00192"></a>00192 
<a name="l00193"></a>00193     stats-&gt;buf_ptr = stats-&gt;buf.buf;
<a name="l00194"></a>00194     res = (stats-&gt;buf.buf != NULL);
<a name="l00195"></a>00195     <span class="keywordflow">return</span> res;
<a name="l00196"></a>00196 }
<a name="l00197"></a>00197 
<a name="l00198"></a>00198 
<a name="l00199"></a>00199 <span class="keywordtype">void</span> stats_close(stats_io_t *stats, <span class="keywordtype">int</span> last_pass)
<a name="l00200"></a>00200 {
<a name="l00201"></a>00201     <span class="keywordflow">if</span> (stats-&gt;file)
<a name="l00202"></a>00202     {
<a name="l00203"></a>00203         <span class="keywordflow">if</span> (stats-&gt;pass == last_pass)
<a name="l00204"></a>00204         {
<a name="l00205"></a>00205 <span class="preprocessor">#if 0</span>
<a name="l00206"></a>00206 <span class="preprocessor"></span><span class="preprocessor">#elif USE_POSIX_MMAP</span>
<a name="l00207"></a>00207 <span class="preprocessor"></span>            munmap(stats-&gt;buf.buf, stats-&gt;buf.sz);
<a name="l00208"></a>00208 <span class="preprocessor">#else</span>
<a name="l00209"></a>00209 <span class="preprocessor"></span>            free(stats-&gt;buf.buf);
<a name="l00210"></a>00210 <span class="preprocessor">#endif</span>
<a name="l00211"></a>00211 <span class="preprocessor"></span>        }
<a name="l00212"></a>00212 
<a name="l00213"></a>00213         fclose(stats-&gt;file);
<a name="l00214"></a>00214         stats-&gt;file = NULL;
<a name="l00215"></a>00215     }
<a name="l00216"></a>00216     <span class="keywordflow">else</span>
<a name="l00217"></a>00217     {
<a name="l00218"></a>00218         <span class="keywordflow">if</span> (stats-&gt;pass == last_pass)
<a name="l00219"></a>00219             free(stats-&gt;buf.buf);
<a name="l00220"></a>00220     }
<a name="l00221"></a>00221 }
<a name="l00222"></a>00222 
<a name="l00223"></a>00223 <span class="keywordtype">void</span> stats_write(stats_io_t *stats, <span class="keyword">const</span> <span class="keywordtype">void</span> *pkt, <span class="keywordtype">size_t</span> len)
<a name="l00224"></a>00224 {
<a name="l00225"></a>00225     <span class="keywordflow">if</span> (stats-&gt;file)
<a name="l00226"></a>00226     {
<a name="l00227"></a>00227         <span class="keywordflow">if</span>(fwrite(pkt, 1, len, stats-&gt;file));
<a name="l00228"></a>00228     }
<a name="l00229"></a>00229     <span class="keywordflow">else</span>
<a name="l00230"></a>00230     {
<a name="l00231"></a>00231         <span class="keywordflow">if</span> (stats-&gt;buf.sz + len &gt; stats-&gt;buf_alloc_sz)
<a name="l00232"></a>00232         {
<a name="l00233"></a>00233             <span class="keywordtype">size_t</span>  new_sz = stats-&gt;buf_alloc_sz + 64 * 1024;
<a name="l00234"></a>00234             <span class="keywordtype">char</span>   *new_ptr = realloc(stats-&gt;buf.buf, new_sz);
<a name="l00235"></a>00235 
<a name="l00236"></a>00236             <span class="keywordflow">if</span> (new_ptr)
<a name="l00237"></a>00237             {
<a name="l00238"></a>00238                 stats-&gt;buf_ptr = new_ptr + (stats-&gt;buf_ptr - (<span class="keywordtype">char</span> *)stats-&gt;buf.buf);
<a name="l00239"></a>00239                 stats-&gt;buf.buf = new_ptr;
<a name="l00240"></a>00240                 stats-&gt;buf_alloc_sz = new_sz;
<a name="l00241"></a>00241             }
<a name="l00242"></a>00242             <span class="keywordflow">else</span>
<a name="l00243"></a>00243             {
<a name="l00244"></a>00244                 fprintf(stderr,
<a name="l00245"></a>00245                         <span class="stringliteral">&quot;\nFailed to realloc firstpass stats buffer.\n&quot;</span>);
<a name="l00246"></a>00246                 exit(EXIT_FAILURE);
<a name="l00247"></a>00247             }
<a name="l00248"></a>00248         }
<a name="l00249"></a>00249 
<a name="l00250"></a>00250         memcpy(stats-&gt;buf_ptr, pkt, len);
<a name="l00251"></a>00251         stats-&gt;buf.sz += len;
<a name="l00252"></a>00252         stats-&gt;buf_ptr += len;
<a name="l00253"></a>00253     }
<a name="l00254"></a>00254 }
<a name="l00255"></a>00255 
<a name="l00256"></a>00256 <a class="code" href="structvpx__fixed__buf.html" title="Generic fixed size buffer structure.">vpx_fixed_buf_t</a> stats_get(stats_io_t *stats)
<a name="l00257"></a>00257 {
<a name="l00258"></a>00258     <span class="keywordflow">return</span> stats-&gt;<a class="code" href="structvpx__fixed__buf.html#ac93e43ae3fcc1023dca86d37016ae3f0">buf</a>;
<a name="l00259"></a>00259 }
<a name="l00260"></a>00260 
<a name="l00261"></a>00261 <span class="comment">/* Stereo 3D packed frame format */</span>
<a name="l00262"></a>00262 <span class="keyword">typedef</span> <span class="keyword">enum</span> stereo_format
<a name="l00263"></a>00263 {
<a name="l00264"></a>00264     STEREO_FORMAT_MONO       = 0,
<a name="l00265"></a>00265     STEREO_FORMAT_LEFT_RIGHT = 1,
<a name="l00266"></a>00266     STEREO_FORMAT_BOTTOM_TOP = 2,
<a name="l00267"></a>00267     STEREO_FORMAT_TOP_BOTTOM = 3,
<a name="l00268"></a>00268     STEREO_FORMAT_RIGHT_LEFT = 11
<a name="l00269"></a>00269 } stereo_format_t;
<a name="l00270"></a>00270 
<a name="l00271"></a>00271 <span class="keyword">enum</span> video_file_type
<a name="l00272"></a>00272 {
<a name="l00273"></a>00273     FILE_TYPE_RAW,
<a name="l00274"></a>00274     FILE_TYPE_IVF,
<a name="l00275"></a>00275     FILE_TYPE_Y4M
<a name="l00276"></a>00276 };
<a name="l00277"></a>00277 
<a name="l00278"></a>00278 <span class="keyword">struct </span>detect_buffer {
<a name="l00279"></a>00279     <span class="keywordtype">char</span> buf[4];
<a name="l00280"></a>00280     <span class="keywordtype">size_t</span> buf_read;
<a name="l00281"></a>00281     <span class="keywordtype">size_t</span> position;
<a name="l00282"></a>00282 };
<a name="l00283"></a>00283 
<a name="l00284"></a>00284 
<a name="l00285"></a>00285 <span class="preprocessor">#define IVF_FRAME_HDR_SZ (4+8) </span><span class="comment">/* 4 byte size + 8 byte timestamp */</span>
<a name="l00286"></a>00286 <span class="keyword">static</span> <span class="keywordtype">int</span> read_frame(FILE *f, <a class="code" href="structvpx__image.html" title="Image Descriptor.">vpx_image_t</a> *img, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> file_type,
<a name="l00287"></a>00287                       y4m_input *y4m, <span class="keyword">struct</span> detect_buffer *detect)
<a name="l00288"></a>00288 {
<a name="l00289"></a>00289     <span class="keywordtype">int</span> plane = 0;
<a name="l00290"></a>00290     <span class="keywordtype">int</span> shortread = 0;
<a name="l00291"></a>00291 
<a name="l00292"></a>00292     <span class="keywordflow">if</span> (file_type == FILE_TYPE_Y4M)
<a name="l00293"></a>00293     {
<a name="l00294"></a>00294         <span class="keywordflow">if</span> (y4m_input_fetch_frame(y4m, f, img) &lt; 1)
<a name="l00295"></a>00295            <span class="keywordflow">return</span> 0;
<a name="l00296"></a>00296     }
<a name="l00297"></a>00297     <span class="keywordflow">else</span>
<a name="l00298"></a>00298     {
<a name="l00299"></a>00299         <span class="keywordflow">if</span> (file_type == FILE_TYPE_IVF)
<a name="l00300"></a>00300         {
<a name="l00301"></a>00301             <span class="keywordtype">char</span> junk[IVF_FRAME_HDR_SZ];
<a name="l00302"></a>00302 
<a name="l00303"></a>00303             <span class="comment">/* Skip the frame header. We know how big the frame should be. See</span>
<a name="l00304"></a>00304 <span class="comment">             * write_ivf_frame_header() for documentation on the frame header</span>
<a name="l00305"></a>00305 <span class="comment">             * layout.</span>
<a name="l00306"></a>00306 <span class="comment">             */</span>
<a name="l00307"></a>00307             <span class="keywordflow">if</span>(fread(junk, 1, IVF_FRAME_HDR_SZ, f));
<a name="l00308"></a>00308         }
<a name="l00309"></a>00309 
<a name="l00310"></a>00310         <span class="keywordflow">for</span> (plane = 0; plane &lt; 3; plane++)
<a name="l00311"></a>00311         {
<a name="l00312"></a>00312             <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *ptr;
<a name="l00313"></a>00313             <span class="keywordtype">int</span> w = (plane ? (1 + img-&gt;<a class="code" href="structvpx__image.html#a806bf23143bf00a0b3fdbd6ba030c483">d_w</a>) / 2 : img-&gt;<a class="code" href="structvpx__image.html#a806bf23143bf00a0b3fdbd6ba030c483">d_w</a>);
<a name="l00314"></a>00314             <span class="keywordtype">int</span> h = (plane ? (1 + img-&gt;<a class="code" href="structvpx__image.html#a31bc5f045d4f3c2b6bb0f57bb53078e7">d_h</a>) / 2 : img-&gt;<a class="code" href="structvpx__image.html#a31bc5f045d4f3c2b6bb0f57bb53078e7">d_h</a>);
<a name="l00315"></a>00315             <span class="keywordtype">int</span> r;
<a name="l00316"></a>00316 
<a name="l00317"></a>00317             <span class="comment">/* Determine the correct plane based on the image format. The for-loop</span>
<a name="l00318"></a>00318 <span class="comment">             * always counts in Y,U,V order, but this may not match the order of</span>
<a name="l00319"></a>00319 <span class="comment">             * the data on disk.</span>
<a name="l00320"></a>00320 <span class="comment">             */</span>
<a name="l00321"></a>00321             <span class="keywordflow">switch</span> (plane)
<a name="l00322"></a>00322             {
<a name="l00323"></a>00323             <span class="keywordflow">case</span> 1:
<a name="l00324"></a>00324                 ptr = img-&gt;<a class="code" href="structvpx__image.html#ab6258308ba7a5f4a113348120e20e2ce">planes</a>[img-&gt;<a class="code" href="structvpx__image.html#a1d734f8afa9200a21c2d9f6bcf8c04d8">fmt</a>==<a class="code" href="vpx__image_8h.html#a7a30a7bff7400fb83ad45fede5077193a6e4e8961bbcf96478c300dc4c3e1dc18">VPX_IMG_FMT_YV12</a>? <a class="code" href="vpx__image_8h.html#aca9436ec761457cc6d2e356e0ac2fd23">VPX_PLANE_V</a> : <a class="code" href="vpx__image_8h.html#a4770fc8fa60021a2229f25553152cf81">VPX_PLANE_U</a>];
<a name="l00325"></a>00325                 <span class="keywordflow">break</span>;
<a name="l00326"></a>00326             <span class="keywordflow">case</span> 2:
<a name="l00327"></a>00327                 ptr = img-&gt;<a class="code" href="structvpx__image.html#ab6258308ba7a5f4a113348120e20e2ce">planes</a>[img-&gt;<a class="code" href="structvpx__image.html#a1d734f8afa9200a21c2d9f6bcf8c04d8">fmt</a>==<a class="code" href="vpx__image_8h.html#a7a30a7bff7400fb83ad45fede5077193a6e4e8961bbcf96478c300dc4c3e1dc18">VPX_IMG_FMT_YV12</a>?<a class="code" href="vpx__image_8h.html#a4770fc8fa60021a2229f25553152cf81">VPX_PLANE_U</a> : <a class="code" href="vpx__image_8h.html#aca9436ec761457cc6d2e356e0ac2fd23">VPX_PLANE_V</a>];
<a name="l00328"></a>00328                 <span class="keywordflow">break</span>;
<a name="l00329"></a>00329             <span class="keywordflow">default</span>:
<a name="l00330"></a>00330                 ptr = img-&gt;<a class="code" href="structvpx__image.html#ab6258308ba7a5f4a113348120e20e2ce">planes</a>[plane];
<a name="l00331"></a>00331             }
<a name="l00332"></a>00332 
<a name="l00333"></a>00333             <span class="keywordflow">for</span> (r = 0; r &lt; h; r++)
<a name="l00334"></a>00334             {
<a name="l00335"></a>00335                 <span class="keywordtype">size_t</span> needed = w;
<a name="l00336"></a>00336                 <span class="keywordtype">size_t</span> buf_position = 0;
<a name="l00337"></a>00337                 <span class="keyword">const</span> <span class="keywordtype">size_t</span> left = detect-&gt;buf_read - detect-&gt;position;
<a name="l00338"></a>00338                 <span class="keywordflow">if</span> (left &gt; 0)
<a name="l00339"></a>00339                 {
<a name="l00340"></a>00340                     <span class="keyword">const</span> <span class="keywordtype">size_t</span> more = (left &lt; needed) ? left : needed;
<a name="l00341"></a>00341                     memcpy(ptr, detect-&gt;buf + detect-&gt;position, more);
<a name="l00342"></a>00342                     buf_position = more;
<a name="l00343"></a>00343                     needed -= more;
<a name="l00344"></a>00344                     detect-&gt;position += more;
<a name="l00345"></a>00345                 }
<a name="l00346"></a>00346                 <span class="keywordflow">if</span> (needed &gt; 0)
<a name="l00347"></a>00347                 {
<a name="l00348"></a>00348                     shortread |= (fread(ptr + buf_position, 1, needed, f) &lt; needed);
<a name="l00349"></a>00349                 }
<a name="l00350"></a>00350 
<a name="l00351"></a>00351                 ptr += img-&gt;<a class="code" href="structvpx__image.html#ac9c7b83e3eea44cb680956f90dc789cf">stride</a>[plane];
<a name="l00352"></a>00352             }
<a name="l00353"></a>00353         }
<a name="l00354"></a>00354     }
<a name="l00355"></a>00355 
<a name="l00356"></a>00356     <span class="keywordflow">return</span> !shortread;
<a name="l00357"></a>00357 }
<a name="l00358"></a>00358 
<a name="l00359"></a>00359 
<a name="l00360"></a>00360 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> file_is_y4m(FILE      *infile,
<a name="l00361"></a>00361                          y4m_input *y4m,
<a name="l00362"></a>00362                          <span class="keywordtype">char</span>       detect[4])
<a name="l00363"></a>00363 {
<a name="l00364"></a>00364     <span class="keywordflow">if</span>(memcmp(detect, <span class="stringliteral">&quot;YUV4&quot;</span>, 4) == 0)
<a name="l00365"></a>00365     {
<a name="l00366"></a>00366         <span class="keywordflow">return</span> 1;
<a name="l00367"></a>00367     }
<a name="l00368"></a>00368     <span class="keywordflow">return</span> 0;
<a name="l00369"></a>00369 }
<a name="l00370"></a>00370 
<a name="l00371"></a>00371 <span class="preprocessor">#define IVF_FILE_HDR_SZ (32)</span>
<a name="l00372"></a>00372 <span class="preprocessor"></span><span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> file_is_ivf(FILE *infile,
<a name="l00373"></a>00373                          <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> *fourcc,
<a name="l00374"></a>00374                          <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> *width,
<a name="l00375"></a>00375                          <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> *height,
<a name="l00376"></a>00376                          <span class="keyword">struct</span> detect_buffer *detect)
<a name="l00377"></a>00377 {
<a name="l00378"></a>00378     <span class="keywordtype">char</span> raw_hdr[IVF_FILE_HDR_SZ];
<a name="l00379"></a>00379     <span class="keywordtype">int</span> is_ivf = 0;
<a name="l00380"></a>00380 
<a name="l00381"></a>00381     <span class="keywordflow">if</span>(memcmp(detect-&gt;buf, <span class="stringliteral">&quot;DKIF&quot;</span>, 4) != 0)
<a name="l00382"></a>00382         <span class="keywordflow">return</span> 0;
<a name="l00383"></a>00383 
<a name="l00384"></a>00384     <span class="comment">/* See write_ivf_file_header() for more documentation on the file header</span>
<a name="l00385"></a>00385 <span class="comment">     * layout.</span>
<a name="l00386"></a>00386 <span class="comment">     */</span>
<a name="l00387"></a>00387     <span class="keywordflow">if</span> (fread(raw_hdr + 4, 1, IVF_FILE_HDR_SZ - 4, infile)
<a name="l00388"></a>00388         == IVF_FILE_HDR_SZ - 4)
<a name="l00389"></a>00389     {
<a name="l00390"></a>00390         {
<a name="l00391"></a>00391             is_ivf = 1;
<a name="l00392"></a>00392 
<a name="l00393"></a>00393             <span class="keywordflow">if</span> (mem_get_le16(raw_hdr + 4) != 0)
<a name="l00394"></a>00394                 fprintf(stderr, <span class="stringliteral">&quot;Error: Unrecognized IVF version! This file may not&quot;</span>
<a name="l00395"></a>00395                         <span class="stringliteral">&quot; decode properly.&quot;</span>);
<a name="l00396"></a>00396 
<a name="l00397"></a>00397             *fourcc = mem_get_le32(raw_hdr + 8);
<a name="l00398"></a>00398         }
<a name="l00399"></a>00399     }
<a name="l00400"></a>00400 
<a name="l00401"></a>00401     <span class="keywordflow">if</span> (is_ivf)
<a name="l00402"></a>00402     {
<a name="l00403"></a>00403         *width = mem_get_le16(raw_hdr + 12);
<a name="l00404"></a>00404         *height = mem_get_le16(raw_hdr + 14);
<a name="l00405"></a>00405         detect-&gt;position = 4;
<a name="l00406"></a>00406     }
<a name="l00407"></a>00407 
<a name="l00408"></a>00408     <span class="keywordflow">return</span> is_ivf;
<a name="l00409"></a>00409 }
<a name="l00410"></a>00410 
<a name="l00411"></a>00411 
<a name="l00412"></a>00412 <span class="keyword">static</span> <span class="keywordtype">void</span> write_ivf_file_header(FILE *outfile,
<a name="l00413"></a>00413                                   <span class="keyword">const</span> <a class="code" href="structvpx__codec__enc__cfg.html" title="Encoder configuration structure.">vpx_codec_enc_cfg_t</a> *cfg,
<a name="l00414"></a>00414                                   <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> fourcc,
<a name="l00415"></a>00415                                   <span class="keywordtype">int</span> frame_cnt)
<a name="l00416"></a>00416 {
<a name="l00417"></a>00417     <span class="keywordtype">char</span> header[32];
<a name="l00418"></a>00418 
<a name="l00419"></a>00419     <span class="keywordflow">if</span> (cfg-&gt;<a class="code" href="structvpx__codec__enc__cfg.html#a70d62d87aae7d1168746577f14a6dccf" title="Multi-pass Encoding Mode.">g_pass</a> != <a class="code" href="group__encoder.html#gga476c5417f9c15a1dc5d3f68fa44c493fa7b6943a41868e8e26a77e9500f139ca1">VPX_RC_ONE_PASS</a> &amp;&amp; cfg-&gt;<a class="code" href="structvpx__codec__enc__cfg.html#a70d62d87aae7d1168746577f14a6dccf" title="Multi-pass Encoding Mode.">g_pass</a> != <a class="code" href="group__encoder.html#gga476c5417f9c15a1dc5d3f68fa44c493fa65da543b956d6a9b1f301ab8cc90d3a7">VPX_RC_LAST_PASS</a>)
<a name="l00420"></a>00420         <span class="keywordflow">return</span>;
<a name="l00421"></a>00421 
<a name="l00422"></a>00422     header[0] = <span class="charliteral">&#39;D&#39;</span>;
<a name="l00423"></a>00423     header[1] = <span class="charliteral">&#39;K&#39;</span>;
<a name="l00424"></a>00424     header[2] = <span class="charliteral">&#39;I&#39;</span>;
<a name="l00425"></a>00425     header[3] = <span class="charliteral">&#39;F&#39;</span>;
<a name="l00426"></a>00426     mem_put_le16(header + 4,  0);                 <span class="comment">/* version */</span>
<a name="l00427"></a>00427     mem_put_le16(header + 6,  32);                <span class="comment">/* headersize */</span>
<a name="l00428"></a>00428     mem_put_le32(header + 8,  fourcc);            <span class="comment">/* headersize */</span>
<a name="l00429"></a>00429     mem_put_le16(header + 12, cfg-&gt;<a class="code" href="structvpx__codec__enc__cfg.html#a5c165f5b41ca1158f2883983a2b7709c" title="Width of the frame.">g_w</a>);          <span class="comment">/* width */</span>
<a name="l00430"></a>00430     mem_put_le16(header + 14, cfg-&gt;<a class="code" href="structvpx__codec__enc__cfg.html#a4132bd89ce85bce7c08f2cc3b6f2b82e" title="Height of the frame.">g_h</a>);          <span class="comment">/* height */</span>
<a name="l00431"></a>00431     mem_put_le32(header + 16, cfg-&gt;<a class="code" href="structvpx__codec__enc__cfg.html#a6498d378e4c29ef3e22258289e481087" title="Stream timebase units.">g_timebase</a>.<a class="code" href="structvpx__rational.html#a29dd2ab4001377b3aa21885ef969759f">den</a>); <span class="comment">/* rate */</span>
<a name="l00432"></a>00432     mem_put_le32(header + 20, cfg-&gt;<a class="code" href="structvpx__codec__enc__cfg.html#a6498d378e4c29ef3e22258289e481087" title="Stream timebase units.">g_timebase</a>.<a class="code" href="structvpx__rational.html#ae7774f21a22c9bef3aa73156c79f4731">num</a>); <span class="comment">/* scale */</span>
<a name="l00433"></a>00433     mem_put_le32(header + 24, frame_cnt);         <span class="comment">/* length */</span>
<a name="l00434"></a>00434     mem_put_le32(header + 28, 0);                 <span class="comment">/* unused */</span>
<a name="l00435"></a>00435 
<a name="l00436"></a>00436     <span class="keywordflow">if</span>(fwrite(header, 1, 32, outfile));
<a name="l00437"></a>00437 }
<a name="l00438"></a>00438 
<a name="l00439"></a>00439 
<a name="l00440"></a>00440 <span class="keyword">static</span> <span class="keywordtype">void</span> write_ivf_frame_header(FILE *outfile,
<a name="l00441"></a>00441                                    <span class="keyword">const</span> <a class="code" href="structvpx__codec__cx__pkt.html" title="Encoder output packet.">vpx_codec_cx_pkt_t</a> *pkt)
<a name="l00442"></a>00442 {
<a name="l00443"></a>00443     <span class="keywordtype">char</span>             header[12];
<a name="l00444"></a>00444     <a class="code" href="group__encoder.html#ga7e711b0a71c65aef8f0faea8bd57b05f" title="Time Stamp Type.">vpx_codec_pts_t</a>  pts;
<a name="l00445"></a>00445 
<a name="l00446"></a>00446     <span class="keywordflow">if</span> (pkt-&gt;<a class="code" href="structvpx__codec__cx__pkt.html#a41f395b39516343c1329a4a85a0084f2">kind</a> != <a class="code" href="group__encoder.html#gga28a79375279536526552af3a83d2ed72a2261aae5594289400e812fb1e6b6b0cc">VPX_CODEC_CX_FRAME_PKT</a>)
<a name="l00447"></a>00447         <span class="keywordflow">return</span>;
<a name="l00448"></a>00448 
<a name="l00449"></a>00449     pts = pkt-&gt;<a class="code" href="structvpx__codec__cx__pkt.html#a7f97b060a23b7e89fe5b885c0074f696">data</a>.<a class="code" href="structvpx__codec__cx__pkt.html#a81e33bf4408a3983abb16492fee359ff">frame</a>.pts;
<a name="l00450"></a>00450     mem_put_le32(header, pkt-&gt;<a class="code" href="structvpx__codec__cx__pkt.html#a7f97b060a23b7e89fe5b885c0074f696">data</a>.<a class="code" href="structvpx__codec__cx__pkt.html#a81e33bf4408a3983abb16492fee359ff">frame</a>.sz);
<a name="l00451"></a>00451     mem_put_le32(header + 4, pts &amp; 0xFFFFFFFF);
<a name="l00452"></a>00452     mem_put_le32(header + 8, pts &gt;&gt; 32);
<a name="l00453"></a>00453 
<a name="l00454"></a>00454     <span class="keywordflow">if</span>(fwrite(header, 1, 12, outfile));
<a name="l00455"></a>00455 }
<a name="l00456"></a>00456 
<a name="l00457"></a>00457 
<a name="l00458"></a>00458 <span class="keyword">typedef</span> off_t EbmlLoc;
<a name="l00459"></a>00459 
<a name="l00460"></a>00460 
<a name="l00461"></a>00461 <span class="keyword">struct </span>cue_entry
<a name="l00462"></a>00462 {
<a name="l00463"></a>00463     <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> time;
<a name="l00464"></a>00464     uint64_t     loc;
<a name="l00465"></a>00465 };
<a name="l00466"></a>00466 
<a name="l00467"></a>00467 
<a name="l00468"></a>00468 <span class="keyword">struct </span>EbmlGlobal
<a name="l00469"></a>00469 {
<a name="l00470"></a>00470     <span class="keywordtype">int</span> debug;
<a name="l00471"></a>00471 
<a name="l00472"></a>00472     FILE    *stream;
<a name="l00473"></a>00473     int64_t last_pts_ms;
<a name="l00474"></a>00474     <a class="code" href="structvpx__rational.html" title="Rational Number.">vpx_rational_t</a>  framerate;
<a name="l00475"></a>00475 
<a name="l00476"></a>00476     <span class="comment">/* These pointers are to the start of an element */</span>
<a name="l00477"></a>00477     off_t    position_reference;
<a name="l00478"></a>00478     off_t    seek_info_pos;
<a name="l00479"></a>00479     off_t    segment_info_pos;
<a name="l00480"></a>00480     off_t    track_pos;
<a name="l00481"></a>00481     off_t    cue_pos;
<a name="l00482"></a>00482     off_t    cluster_pos;
<a name="l00483"></a>00483 
<a name="l00484"></a>00484     <span class="comment">/* This pointer is to a specific element to be serialized */</span>
<a name="l00485"></a>00485     off_t    track_id_pos;
<a name="l00486"></a>00486 
<a name="l00487"></a>00487     <span class="comment">/* These pointers are to the size field of the element */</span>
<a name="l00488"></a>00488     EbmlLoc  startSegment;
<a name="l00489"></a>00489     EbmlLoc  startCluster;
<a name="l00490"></a>00490 
<a name="l00491"></a>00491     uint32_t cluster_timecode;
<a name="l00492"></a>00492     <span class="keywordtype">int</span>      cluster_open;
<a name="l00493"></a>00493 
<a name="l00494"></a>00494     <span class="keyword">struct </span>cue_entry *cue_list;
<a name="l00495"></a>00495     <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>      cues;
<a name="l00496"></a>00496 
<a name="l00497"></a>00497 };
<a name="l00498"></a>00498 
<a name="l00499"></a>00499 
<a name="l00500"></a>00500 <span class="keywordtype">void</span> Ebml_Write(EbmlGlobal *glob, <span class="keyword">const</span> <span class="keywordtype">void</span> *buffer_in, <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> len)
<a name="l00501"></a>00501 {
<a name="l00502"></a>00502     <span class="keywordflow">if</span>(fwrite(buffer_in, 1, len, glob-&gt;stream));
<a name="l00503"></a>00503 }
<a name="l00504"></a>00504 
<a name="l00505"></a>00505 <span class="preprocessor">#define WRITE_BUFFER(s) \</span>
<a name="l00506"></a>00506 <span class="preprocessor">for(i = len-1; i&gt;=0; i--)\</span>
<a name="l00507"></a>00507 <span class="preprocessor">{ \</span>
<a name="l00508"></a>00508 <span class="preprocessor">    x = *(const s *)buffer_in &gt;&gt; (i * CHAR_BIT); \</span>
<a name="l00509"></a>00509 <span class="preprocessor">    Ebml_Write(glob, &amp;x, 1); \</span>
<a name="l00510"></a>00510 <span class="preprocessor">}</span>
<a name="l00511"></a>00511 <span class="preprocessor"></span><span class="keywordtype">void</span> Ebml_Serialize(EbmlGlobal *glob, <span class="keyword">const</span> <span class="keywordtype">void</span> *buffer_in, <span class="keywordtype">int</span> buffer_size, <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> len)
<a name="l00512"></a>00512 {
<a name="l00513"></a>00513     <span class="keywordtype">char</span> x;
<a name="l00514"></a>00514     <span class="keywordtype">int</span> i;
<a name="l00515"></a>00515 
<a name="l00516"></a>00516     <span class="comment">/* buffer_size:</span>
<a name="l00517"></a>00517 <span class="comment">     * 1 - int8_t;</span>
<a name="l00518"></a>00518 <span class="comment">     * 2 - int16_t;</span>
<a name="l00519"></a>00519 <span class="comment">     * 3 - int32_t;</span>
<a name="l00520"></a>00520 <span class="comment">     * 4 - int64_t;</span>
<a name="l00521"></a>00521 <span class="comment">     */</span>
<a name="l00522"></a>00522     <span class="keywordflow">switch</span> (buffer_size)
<a name="l00523"></a>00523     {
<a name="l00524"></a>00524         <span class="keywordflow">case</span> 1:
<a name="l00525"></a>00525             WRITE_BUFFER(int8_t)
<a name="l00526"></a>00526             break;
<a name="l00527"></a>00527         case 2:
<a name="l00528"></a>00528             WRITE_BUFFER(int16_t)
<a name="l00529"></a>00529             break;
<a name="l00530"></a>00530         case 4:
<a name="l00531"></a>00531             WRITE_BUFFER(int32_t)
<a name="l00532"></a>00532             break;
<a name="l00533"></a>00533         case 8:
<a name="l00534"></a>00534             WRITE_BUFFER(int64_t)
<a name="l00535"></a>00535             break;
<a name="l00536"></a>00536         default:
<a name="l00537"></a>00537             break;
<a name="l00538"></a>00538     }
<a name="l00539"></a>00539 }
<a name="l00540"></a>00540 <span class="preprocessor">#undef WRITE_BUFFER</span>
<a name="l00541"></a>00541 <span class="preprocessor"></span>
<a name="l00542"></a>00542 <span class="comment">/* Need a fixed size serializer for the track ID. libmkv provides a 64 bit</span>
<a name="l00543"></a>00543 <span class="comment"> * one, but not a 32 bit one.</span>
<a name="l00544"></a>00544 <span class="comment"> */</span>
<a name="l00545"></a>00545 <span class="keyword">static</span> <span class="keywordtype">void</span> Ebml_SerializeUnsigned32(EbmlGlobal *glob, <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> class_id, uint64_t ui)
<a name="l00546"></a>00546 {
<a name="l00547"></a>00547     <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> sizeSerialized = 4 | 0x80;
<a name="l00548"></a>00548     Ebml_WriteID(glob, class_id);
<a name="l00549"></a>00549     Ebml_Serialize(glob, &amp;sizeSerialized, <span class="keyword">sizeof</span>(sizeSerialized), 1);
<a name="l00550"></a>00550     Ebml_Serialize(glob, &amp;ui, <span class="keyword">sizeof</span>(ui), 4);
<a name="l00551"></a>00551 }
<a name="l00552"></a>00552 
<a name="l00553"></a>00553 
<a name="l00554"></a>00554 <span class="keyword">static</span> <span class="keywordtype">void</span>
<a name="l00555"></a>00555 Ebml_StartSubElement(EbmlGlobal *glob, EbmlLoc *ebmlLoc,
<a name="l00556"></a>00556                           <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> class_id)
<a name="l00557"></a>00557 {
<a name="l00558"></a>00558     <span class="comment">//todo this is always taking 8 bytes, this may need later optimization</span>
<a name="l00559"></a>00559     <span class="comment">//this is a key that says length unknown</span>
<a name="l00560"></a>00560     uint64_t unknownLen =  LITERALU64(0x01FFFFFFFFFFFFFF);
<a name="l00561"></a>00561 
<a name="l00562"></a>00562     Ebml_WriteID(glob, class_id);
<a name="l00563"></a>00563     *ebmlLoc = ftello(glob-&gt;stream);
<a name="l00564"></a>00564     Ebml_Serialize(glob, &amp;unknownLen, <span class="keyword">sizeof</span>(unknownLen), 8);
<a name="l00565"></a>00565 }
<a name="l00566"></a>00566 
<a name="l00567"></a>00567 <span class="keyword">static</span> <span class="keywordtype">void</span>
<a name="l00568"></a>00568 Ebml_EndSubElement(EbmlGlobal *glob, EbmlLoc *ebmlLoc)
<a name="l00569"></a>00569 {
<a name="l00570"></a>00570     off_t pos;
<a name="l00571"></a>00571     uint64_t size;
<a name="l00572"></a>00572 
<a name="l00573"></a>00573     <span class="comment">/* Save the current stream pointer */</span>
<a name="l00574"></a>00574     pos = ftello(glob-&gt;stream);
<a name="l00575"></a>00575 
<a name="l00576"></a>00576     <span class="comment">/* Calculate the size of this element */</span>
<a name="l00577"></a>00577     size = pos - *ebmlLoc - 8;
<a name="l00578"></a>00578     size |=  LITERALU64(0x0100000000000000);
<a name="l00579"></a>00579 
<a name="l00580"></a>00580     <span class="comment">/* Seek back to the beginning of the element and write the new size */</span>
<a name="l00581"></a>00581     fseeko(glob-&gt;stream, *ebmlLoc, SEEK_SET);
<a name="l00582"></a>00582     Ebml_Serialize(glob, &amp;size, <span class="keyword">sizeof</span>(size), 8);
<a name="l00583"></a>00583 
<a name="l00584"></a>00584     <span class="comment">/* Reset the stream pointer */</span>
<a name="l00585"></a>00585     fseeko(glob-&gt;stream, pos, SEEK_SET);
<a name="l00586"></a>00586 }
<a name="l00587"></a>00587 
<a name="l00588"></a>00588 
<a name="l00589"></a>00589 <span class="keyword">static</span> <span class="keywordtype">void</span>
<a name="l00590"></a>00590 write_webm_seek_element(EbmlGlobal *ebml, <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> <span class="keywordtype">id</span>, off_t pos)
<a name="l00591"></a>00591 {
<a name="l00592"></a>00592     uint64_t offset = pos - ebml-&gt;position_reference;
<a name="l00593"></a>00593     EbmlLoc start;
<a name="l00594"></a>00594     Ebml_StartSubElement(ebml, &amp;start, Seek);
<a name="l00595"></a>00595     Ebml_SerializeBinary(ebml, SeekID, <span class="keywordtype">id</span>);
<a name="l00596"></a>00596     Ebml_SerializeUnsigned64(ebml, SeekPosition, offset);
<a name="l00597"></a>00597     Ebml_EndSubElement(ebml, &amp;start);
<a name="l00598"></a>00598 }
<a name="l00599"></a>00599 
<a name="l00600"></a>00600 
<a name="l00601"></a>00601 <span class="keyword">static</span> <span class="keywordtype">void</span>
<a name="l00602"></a>00602 write_webm_seek_info(EbmlGlobal *ebml)
<a name="l00603"></a>00603 {
<a name="l00604"></a>00604 
<a name="l00605"></a>00605     off_t pos;
<a name="l00606"></a>00606 
<a name="l00607"></a>00607     <span class="comment">/* Save the current stream pointer */</span>
<a name="l00608"></a>00608     pos = ftello(ebml-&gt;stream);
<a name="l00609"></a>00609 
<a name="l00610"></a>00610     <span class="keywordflow">if</span>(ebml-&gt;seek_info_pos)
<a name="l00611"></a>00611         fseeko(ebml-&gt;stream, ebml-&gt;seek_info_pos, SEEK_SET);
<a name="l00612"></a>00612     <span class="keywordflow">else</span>
<a name="l00613"></a>00613         ebml-&gt;seek_info_pos = pos;
<a name="l00614"></a>00614 
<a name="l00615"></a>00615     {
<a name="l00616"></a>00616         EbmlLoc start;
<a name="l00617"></a>00617 
<a name="l00618"></a>00618         Ebml_StartSubElement(ebml, &amp;start, SeekHead);
<a name="l00619"></a>00619         write_webm_seek_element(ebml, Tracks, ebml-&gt;track_pos);
<a name="l00620"></a>00620         write_webm_seek_element(ebml, Cues,   ebml-&gt;cue_pos);
<a name="l00621"></a>00621         write_webm_seek_element(ebml, Info,   ebml-&gt;segment_info_pos);
<a name="l00622"></a>00622         Ebml_EndSubElement(ebml, &amp;start);
<a name="l00623"></a>00623     }
<a name="l00624"></a>00624     {
<a name="l00625"></a>00625         <span class="comment">//segment info</span>
<a name="l00626"></a>00626         EbmlLoc startInfo;
<a name="l00627"></a>00627         uint64_t frame_time;
<a name="l00628"></a>00628         <span class="keywordtype">char</span> version_string[64];
<a name="l00629"></a>00629 
<a name="l00630"></a>00630         <span class="comment">/* Assemble version string */</span>
<a name="l00631"></a>00631         <span class="keywordflow">if</span>(ebml-&gt;debug)
<a name="l00632"></a>00632             strcpy(version_string, <span class="stringliteral">&quot;vpxenc&quot;</span>);
<a name="l00633"></a>00633         <span class="keywordflow">else</span>
<a name="l00634"></a>00634         {
<a name="l00635"></a>00635             strcpy(version_string, <span class="stringliteral">&quot;vpxenc &quot;</span>);
<a name="l00636"></a>00636             strncat(version_string,
<a name="l00637"></a>00637                     <a class="code" href="group__codec.html#ga163fbcc6dd33827b28b9829a0a86cf59" title="Return the version information (as a string)">vpx_codec_version_str</a>(),
<a name="l00638"></a>00638                     <span class="keyword">sizeof</span>(version_string) - 1 - strlen(version_string));
<a name="l00639"></a>00639         }
<a name="l00640"></a>00640 
<a name="l00641"></a>00641         frame_time = (uint64_t)1000 * ebml-&gt;framerate.den
<a name="l00642"></a>00642                      / ebml-&gt;framerate.num;
<a name="l00643"></a>00643         ebml-&gt;segment_info_pos = ftello(ebml-&gt;stream);
<a name="l00644"></a>00644         Ebml_StartSubElement(ebml, &amp;startInfo, Info);
<a name="l00645"></a>00645         Ebml_SerializeUnsigned(ebml, TimecodeScale, 1000000);
<a name="l00646"></a>00646         Ebml_SerializeFloat(ebml, Segment_Duration,
<a name="l00647"></a>00647                             ebml-&gt;last_pts_ms + frame_time);
<a name="l00648"></a>00648         Ebml_SerializeString(ebml, 0x4D80, version_string);
<a name="l00649"></a>00649         Ebml_SerializeString(ebml, 0x5741, version_string);
<a name="l00650"></a>00650         Ebml_EndSubElement(ebml, &amp;startInfo);
<a name="l00651"></a>00651     }
<a name="l00652"></a>00652 }
<a name="l00653"></a>00653 
<a name="l00654"></a>00654 
<a name="l00655"></a>00655 <span class="keyword">static</span> <span class="keywordtype">void</span>
<a name="l00656"></a>00656 write_webm_file_header(EbmlGlobal                *glob,
<a name="l00657"></a>00657                        <span class="keyword">const</span> <a class="code" href="structvpx__codec__enc__cfg.html" title="Encoder configuration structure.">vpx_codec_enc_cfg_t</a> *cfg,
<a name="l00658"></a>00658                        <span class="keyword">const</span> <span class="keyword">struct</span> <a class="code" href="structvpx__rational.html" title="Rational Number.">vpx_rational</a> *fps,
<a name="l00659"></a>00659                        stereo_format_t            stereo_fmt)
<a name="l00660"></a>00660 {
<a name="l00661"></a>00661     {
<a name="l00662"></a>00662         EbmlLoc start;
<a name="l00663"></a>00663         Ebml_StartSubElement(glob, &amp;start, EBML);
<a name="l00664"></a>00664         Ebml_SerializeUnsigned(glob, EBMLVersion, 1);
<a name="l00665"></a>00665         Ebml_SerializeUnsigned(glob, EBMLReadVersion, 1); <span class="comment">//EBML Read Version</span>
<a name="l00666"></a>00666         Ebml_SerializeUnsigned(glob, EBMLMaxIDLength, 4); <span class="comment">//EBML Max ID Length</span>
<a name="l00667"></a>00667         Ebml_SerializeUnsigned(glob, EBMLMaxSizeLength, 8); <span class="comment">//EBML Max Size Length</span>
<a name="l00668"></a>00668         Ebml_SerializeString(glob, DocType, <span class="stringliteral">&quot;webm&quot;</span>); <span class="comment">//Doc Type</span>
<a name="l00669"></a>00669         Ebml_SerializeUnsigned(glob, DocTypeVersion, 2); <span class="comment">//Doc Type Version</span>
<a name="l00670"></a>00670         Ebml_SerializeUnsigned(glob, DocTypeReadVersion, 2); <span class="comment">//Doc Type Read Version</span>
<a name="l00671"></a>00671         Ebml_EndSubElement(glob, &amp;start);
<a name="l00672"></a>00672     }
<a name="l00673"></a>00673     {
<a name="l00674"></a>00674         Ebml_StartSubElement(glob, &amp;glob-&gt;startSegment, Segment); <span class="comment">//segment</span>
<a name="l00675"></a>00675         glob-&gt;position_reference = ftello(glob-&gt;stream);
<a name="l00676"></a>00676         glob-&gt;framerate = *fps;
<a name="l00677"></a>00677         write_webm_seek_info(glob);
<a name="l00678"></a>00678 
<a name="l00679"></a>00679         {
<a name="l00680"></a>00680             EbmlLoc trackStart;
<a name="l00681"></a>00681             glob-&gt;track_pos = ftello(glob-&gt;stream);
<a name="l00682"></a>00682             Ebml_StartSubElement(glob, &amp;trackStart, Tracks);
<a name="l00683"></a>00683             {
<a name="l00684"></a>00684                 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> trackNumber = 1;
<a name="l00685"></a>00685                 uint64_t     trackID = 0;
<a name="l00686"></a>00686 
<a name="l00687"></a>00687                 EbmlLoc start;
<a name="l00688"></a>00688                 Ebml_StartSubElement(glob, &amp;start, TrackEntry);
<a name="l00689"></a>00689                 Ebml_SerializeUnsigned(glob, TrackNumber, trackNumber);
<a name="l00690"></a>00690                 glob-&gt;track_id_pos = ftello(glob-&gt;stream);
<a name="l00691"></a>00691                 Ebml_SerializeUnsigned32(glob, TrackUID, trackID);
<a name="l00692"></a>00692                 Ebml_SerializeUnsigned(glob, TrackType, 1); <span class="comment">//video is always 1</span>
<a name="l00693"></a>00693                 Ebml_SerializeString(glob, CodecID, <span class="stringliteral">&quot;V_VP8&quot;</span>);
<a name="l00694"></a>00694                 {
<a name="l00695"></a>00695                     <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> pixelWidth = cfg-&gt;<a class="code" href="structvpx__codec__enc__cfg.html#a5c165f5b41ca1158f2883983a2b7709c" title="Width of the frame.">g_w</a>;
<a name="l00696"></a>00696                     <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> pixelHeight = cfg-&gt;<a class="code" href="structvpx__codec__enc__cfg.html#a4132bd89ce85bce7c08f2cc3b6f2b82e" title="Height of the frame.">g_h</a>;
<a name="l00697"></a>00697                     <span class="keywordtype">float</span>        frameRate   = (float)fps-&gt;<a class="code" href="structvpx__rational.html#ae7774f21a22c9bef3aa73156c79f4731">num</a>/(<span class="keywordtype">float</span>)fps-&gt;<a class="code" href="structvpx__rational.html#a29dd2ab4001377b3aa21885ef969759f">den</a>;
<a name="l00698"></a>00698 
<a name="l00699"></a>00699                     EbmlLoc videoStart;
<a name="l00700"></a>00700                     Ebml_StartSubElement(glob, &amp;videoStart, Video);
<a name="l00701"></a>00701                     Ebml_SerializeUnsigned(glob, PixelWidth, pixelWidth);
<a name="l00702"></a>00702                     Ebml_SerializeUnsigned(glob, PixelHeight, pixelHeight);
<a name="l00703"></a>00703                     Ebml_SerializeUnsigned(glob, StereoMode, stereo_fmt);
<a name="l00704"></a>00704                     Ebml_SerializeFloat(glob, FrameRate, frameRate);
<a name="l00705"></a>00705                     Ebml_EndSubElement(glob, &amp;videoStart); <span class="comment">//Video</span>
<a name="l00706"></a>00706                 }
<a name="l00707"></a>00707                 Ebml_EndSubElement(glob, &amp;start); <span class="comment">//Track Entry</span>
<a name="l00708"></a>00708             }
<a name="l00709"></a>00709             Ebml_EndSubElement(glob, &amp;trackStart);
<a name="l00710"></a>00710         }
<a name="l00711"></a>00711         <span class="comment">// segment element is open</span>
<a name="l00712"></a>00712     }
<a name="l00713"></a>00713 }
<a name="l00714"></a>00714 
<a name="l00715"></a>00715 
<a name="l00716"></a>00716 <span class="keyword">static</span> <span class="keywordtype">void</span>
<a name="l00717"></a>00717 write_webm_block(EbmlGlobal                *glob,
<a name="l00718"></a>00718                  <span class="keyword">const</span> <a class="code" href="structvpx__codec__enc__cfg.html" title="Encoder configuration structure.">vpx_codec_enc_cfg_t</a> *cfg,
<a name="l00719"></a>00719                  <span class="keyword">const</span> <a class="code" href="structvpx__codec__cx__pkt.html" title="Encoder output packet.">vpx_codec_cx_pkt_t</a>  *pkt)
<a name="l00720"></a>00720 {
<a name="l00721"></a>00721     <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>  block_length;
<a name="l00722"></a>00722     <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>  track_number;
<a name="l00723"></a>00723     <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> block_timecode = 0;
<a name="l00724"></a>00724     <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>  flags;
<a name="l00725"></a>00725     int64_t        pts_ms;
<a name="l00726"></a>00726     <span class="keywordtype">int</span>            start_cluster = 0, is_keyframe;
<a name="l00727"></a>00727 
<a name="l00728"></a>00728     <span class="comment">/* Calculate the PTS of this frame in milliseconds */</span>
<a name="l00729"></a>00729     pts_ms = pkt-&gt;<a class="code" href="structvpx__codec__cx__pkt.html#a7f97b060a23b7e89fe5b885c0074f696">data</a>.<a class="code" href="structvpx__codec__cx__pkt.html#a81e33bf4408a3983abb16492fee359ff">frame</a>.pts * 1000
<a name="l00730"></a>00730              * (uint64_t)cfg-&gt;<a class="code" href="structvpx__codec__enc__cfg.html#a6498d378e4c29ef3e22258289e481087" title="Stream timebase units.">g_timebase</a>.<a class="code" href="structvpx__rational.html#ae7774f21a22c9bef3aa73156c79f4731">num</a> / (uint64_t)cfg-&gt;<a class="code" href="structvpx__codec__enc__cfg.html#a6498d378e4c29ef3e22258289e481087" title="Stream timebase units.">g_timebase</a>.<a class="code" href="structvpx__rational.html#a29dd2ab4001377b3aa21885ef969759f">den</a>;
<a name="l00731"></a>00731     <span class="keywordflow">if</span>(pts_ms &lt;= glob-&gt;last_pts_ms)
<a name="l00732"></a>00732         pts_ms = glob-&gt;last_pts_ms + 1;
<a name="l00733"></a>00733     glob-&gt;last_pts_ms = pts_ms;
<a name="l00734"></a>00734 
<a name="l00735"></a>00735     <span class="comment">/* Calculate the relative time of this block */</span>
<a name="l00736"></a>00736     <span class="keywordflow">if</span>(pts_ms - glob-&gt;cluster_timecode &gt; SHRT_MAX)
<a name="l00737"></a>00737         start_cluster = 1;
<a name="l00738"></a>00738     <span class="keywordflow">else</span>
<a name="l00739"></a>00739         block_timecode = pts_ms - glob-&gt;cluster_timecode;
<a name="l00740"></a>00740 
<a name="l00741"></a>00741     is_keyframe = (pkt-&gt;<a class="code" href="structvpx__codec__cx__pkt.html#a7f97b060a23b7e89fe5b885c0074f696">data</a>.<a class="code" href="structvpx__codec__cx__pkt.html#a81e33bf4408a3983abb16492fee359ff">frame</a>.flags &amp; <a class="code" href="group__encoder.html#ga7a896eb3bc74f33419e6a9812c60e4c9">VPX_FRAME_IS_KEY</a>);
<a name="l00742"></a>00742     <span class="keywordflow">if</span>(start_cluster || is_keyframe)
<a name="l00743"></a>00743     {
<a name="l00744"></a>00744         <span class="keywordflow">if</span>(glob-&gt;cluster_open)
<a name="l00745"></a>00745             Ebml_EndSubElement(glob, &amp;glob-&gt;startCluster);
<a name="l00746"></a>00746 
<a name="l00747"></a>00747         <span class="comment">/* Open the new cluster */</span>
<a name="l00748"></a>00748         block_timecode = 0;
<a name="l00749"></a>00749         glob-&gt;cluster_open = 1;
<a name="l00750"></a>00750         glob-&gt;cluster_timecode = pts_ms;
<a name="l00751"></a>00751         glob-&gt;cluster_pos = ftello(glob-&gt;stream);
<a name="l00752"></a>00752         Ebml_StartSubElement(glob, &amp;glob-&gt;startCluster, Cluster); <span class="comment">//cluster</span>
<a name="l00753"></a>00753         Ebml_SerializeUnsigned(glob, Timecode, glob-&gt;cluster_timecode);
<a name="l00754"></a>00754 
<a name="l00755"></a>00755         <span class="comment">/* Save a cue point if this is a keyframe. */</span>
<a name="l00756"></a>00756         <span class="keywordflow">if</span>(is_keyframe)
<a name="l00757"></a>00757         {
<a name="l00758"></a>00758             <span class="keyword">struct </span>cue_entry *cue, *new_cue_list;
<a name="l00759"></a>00759 
<a name="l00760"></a>00760             new_cue_list = realloc(glob-&gt;cue_list,
<a name="l00761"></a>00761                                    (glob-&gt;cues+1) * <span class="keyword">sizeof</span>(<span class="keyword">struct</span> cue_entry));
<a name="l00762"></a>00762             <span class="keywordflow">if</span>(new_cue_list)
<a name="l00763"></a>00763                 glob-&gt;cue_list = new_cue_list;
<a name="l00764"></a>00764             <span class="keywordflow">else</span>
<a name="l00765"></a>00765             {
<a name="l00766"></a>00766                 fprintf(stderr, <span class="stringliteral">&quot;\nFailed to realloc cue list.\n&quot;</span>);
<a name="l00767"></a>00767                 exit(EXIT_FAILURE);
<a name="l00768"></a>00768             }
<a name="l00769"></a>00769 
<a name="l00770"></a>00770             cue = &amp;glob-&gt;cue_list[glob-&gt;cues];
<a name="l00771"></a>00771             cue-&gt;time = glob-&gt;cluster_timecode;
<a name="l00772"></a>00772             cue-&gt;loc = glob-&gt;cluster_pos;
<a name="l00773"></a>00773             glob-&gt;cues++;
<a name="l00774"></a>00774         }
<a name="l00775"></a>00775     }
<a name="l00776"></a>00776 
<a name="l00777"></a>00777     <span class="comment">/* Write the Simple Block */</span>
<a name="l00778"></a>00778     Ebml_WriteID(glob, SimpleBlock);
<a name="l00779"></a>00779 
<a name="l00780"></a>00780     block_length = pkt-&gt;<a class="code" href="structvpx__codec__cx__pkt.html#a7f97b060a23b7e89fe5b885c0074f696">data</a>.<a class="code" href="structvpx__codec__cx__pkt.html#a81e33bf4408a3983abb16492fee359ff">frame</a>.sz + 4;
<a name="l00781"></a>00781     block_length |= 0x10000000;
<a name="l00782"></a>00782     Ebml_Serialize(glob, &amp;block_length, <span class="keyword">sizeof</span>(block_length), 4);
<a name="l00783"></a>00783 
<a name="l00784"></a>00784     track_number = 1;
<a name="l00785"></a>00785     track_number |= 0x80;
<a name="l00786"></a>00786     Ebml_Write(glob, &amp;track_number, 1);
<a name="l00787"></a>00787 
<a name="l00788"></a>00788     Ebml_Serialize(glob, &amp;block_timecode, <span class="keyword">sizeof</span>(block_timecode), 2);
<a name="l00789"></a>00789 
<a name="l00790"></a>00790     flags = 0;
<a name="l00791"></a>00791     <span class="keywordflow">if</span>(is_keyframe)
<a name="l00792"></a>00792         flags |= 0x80;
<a name="l00793"></a>00793     <span class="keywordflow">if</span>(pkt-&gt;<a class="code" href="structvpx__codec__cx__pkt.html#a7f97b060a23b7e89fe5b885c0074f696">data</a>.<a class="code" href="structvpx__codec__cx__pkt.html#a81e33bf4408a3983abb16492fee359ff">frame</a>.flags &amp; <a class="code" href="group__encoder.html#ga060d7e881d249bdb6e1a29b42e559685">VPX_FRAME_IS_INVISIBLE</a>)
<a name="l00794"></a>00794         flags |= 0x08;
<a name="l00795"></a>00795     Ebml_Write(glob, &amp;flags, 1);
<a name="l00796"></a>00796 
<a name="l00797"></a>00797     Ebml_Write(glob, pkt-&gt;<a class="code" href="structvpx__codec__cx__pkt.html#a7f97b060a23b7e89fe5b885c0074f696">data</a>.<a class="code" href="structvpx__codec__cx__pkt.html#a81e33bf4408a3983abb16492fee359ff">frame</a>.buf, pkt-&gt;<a class="code" href="structvpx__codec__cx__pkt.html#a7f97b060a23b7e89fe5b885c0074f696">data</a>.<a class="code" href="structvpx__codec__cx__pkt.html#a81e33bf4408a3983abb16492fee359ff">frame</a>.sz);
<a name="l00798"></a>00798 }
<a name="l00799"></a>00799 
<a name="l00800"></a>00800 
<a name="l00801"></a>00801 <span class="keyword">static</span> <span class="keywordtype">void</span>
<a name="l00802"></a>00802 write_webm_file_footer(EbmlGlobal *glob, <span class="keywordtype">long</span> hash)
<a name="l00803"></a>00803 {
<a name="l00804"></a>00804 
<a name="l00805"></a>00805     <span class="keywordflow">if</span>(glob-&gt;cluster_open)
<a name="l00806"></a>00806         Ebml_EndSubElement(glob, &amp;glob-&gt;startCluster);
<a name="l00807"></a>00807 
<a name="l00808"></a>00808     {
<a name="l00809"></a>00809         EbmlLoc start;
<a name="l00810"></a>00810         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i;
<a name="l00811"></a>00811 
<a name="l00812"></a>00812         glob-&gt;cue_pos = ftello(glob-&gt;stream);
<a name="l00813"></a>00813         Ebml_StartSubElement(glob, &amp;start, Cues);
<a name="l00814"></a>00814         <span class="keywordflow">for</span>(i=0; i&lt;glob-&gt;cues; i++)
<a name="l00815"></a>00815         {
<a name="l00816"></a>00816             <span class="keyword">struct </span>cue_entry *cue = &amp;glob-&gt;cue_list[i];
<a name="l00817"></a>00817             EbmlLoc start;
<a name="l00818"></a>00818 
<a name="l00819"></a>00819             Ebml_StartSubElement(glob, &amp;start, CuePoint);
<a name="l00820"></a>00820             {
<a name="l00821"></a>00821                 EbmlLoc start;
<a name="l00822"></a>00822 
<a name="l00823"></a>00823                 Ebml_SerializeUnsigned(glob, CueTime, cue-&gt;time);
<a name="l00824"></a>00824 
<a name="l00825"></a>00825                 Ebml_StartSubElement(glob, &amp;start, CueTrackPositions);
<a name="l00826"></a>00826                 Ebml_SerializeUnsigned(glob, CueTrack, 1);
<a name="l00827"></a>00827                 Ebml_SerializeUnsigned64(glob, CueClusterPosition,
<a name="l00828"></a>00828                                          cue-&gt;loc - glob-&gt;position_reference);
<a name="l00829"></a>00829                 <span class="comment">//Ebml_SerializeUnsigned(glob, CueBlockNumber, cue-&gt;blockNumber);</span>
<a name="l00830"></a>00830                 Ebml_EndSubElement(glob, &amp;start);
<a name="l00831"></a>00831             }
<a name="l00832"></a>00832             Ebml_EndSubElement(glob, &amp;start);
<a name="l00833"></a>00833         }
<a name="l00834"></a>00834         Ebml_EndSubElement(glob, &amp;start);
<a name="l00835"></a>00835     }
<a name="l00836"></a>00836 
<a name="l00837"></a>00837     Ebml_EndSubElement(glob, &amp;glob-&gt;startSegment);
<a name="l00838"></a>00838 
<a name="l00839"></a>00839     <span class="comment">/* Patch up the seek info block */</span>
<a name="l00840"></a>00840     write_webm_seek_info(glob);
<a name="l00841"></a>00841 
<a name="l00842"></a>00842     <span class="comment">/* Patch up the track id */</span>
<a name="l00843"></a>00843     fseeko(glob-&gt;stream, glob-&gt;track_id_pos, SEEK_SET);
<a name="l00844"></a>00844     Ebml_SerializeUnsigned32(glob, TrackUID, glob-&gt;debug ? 0xDEADBEEF : hash);
<a name="l00845"></a>00845 
<a name="l00846"></a>00846     fseeko(glob-&gt;stream, 0, SEEK_END);
<a name="l00847"></a>00847 }
<a name="l00848"></a>00848 
<a name="l00849"></a>00849 
<a name="l00850"></a>00850 <span class="comment">/* Murmur hash derived from public domain reference implementation at</span>
<a name="l00851"></a>00851 <span class="comment"> *   http://sites.google.com/site/murmurhash/</span>
<a name="l00852"></a>00852 <span class="comment"> */</span>
<a name="l00853"></a>00853 <span class="keyword">static</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> murmur ( <span class="keyword">const</span> <span class="keywordtype">void</span> * key, <span class="keywordtype">int</span> len, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> seed )
<a name="l00854"></a>00854 {
<a name="l00855"></a>00855     <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> m = 0x5bd1e995;
<a name="l00856"></a>00856     <span class="keyword">const</span> <span class="keywordtype">int</span> r = 24;
<a name="l00857"></a>00857 
<a name="l00858"></a>00858     <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> h = seed ^ len;
<a name="l00859"></a>00859 
<a name="l00860"></a>00860     <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> * data = (<span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *)key;
<a name="l00861"></a>00861 
<a name="l00862"></a>00862     <span class="keywordflow">while</span>(len &gt;= 4)
<a name="l00863"></a>00863     {
<a name="l00864"></a>00864         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> k;
<a name="l00865"></a>00865 
<a name="l00866"></a>00866         k  = data[0];
<a name="l00867"></a>00867         k |= data[1] &lt;&lt; 8;
<a name="l00868"></a>00868         k |= data[2] &lt;&lt; 16;
<a name="l00869"></a>00869         k |= data[3] &lt;&lt; 24;
<a name="l00870"></a>00870 
<a name="l00871"></a>00871         k *= m;
<a name="l00872"></a>00872         k ^= k &gt;&gt; r;
<a name="l00873"></a>00873         k *= m;
<a name="l00874"></a>00874 
<a name="l00875"></a>00875         h *= m;
<a name="l00876"></a>00876         h ^= k;
<a name="l00877"></a>00877 
<a name="l00878"></a>00878         data += 4;
<a name="l00879"></a>00879         len -= 4;
<a name="l00880"></a>00880     }
<a name="l00881"></a>00881 
<a name="l00882"></a>00882     <span class="keywordflow">switch</span>(len)
<a name="l00883"></a>00883     {
<a name="l00884"></a>00884     <span class="keywordflow">case</span> 3: h ^= data[2] &lt;&lt; 16;
<a name="l00885"></a>00885     <span class="keywordflow">case</span> 2: h ^= data[1] &lt;&lt; 8;
<a name="l00886"></a>00886     <span class="keywordflow">case</span> 1: h ^= data[0];
<a name="l00887"></a>00887             h *= m;
<a name="l00888"></a>00888     };
<a name="l00889"></a>00889 
<a name="l00890"></a>00890     h ^= h &gt;&gt; 13;
<a name="l00891"></a>00891     h *= m;
<a name="l00892"></a>00892     h ^= h &gt;&gt; 15;
<a name="l00893"></a>00893 
<a name="l00894"></a>00894     <span class="keywordflow">return</span> h;
<a name="l00895"></a>00895 }
<a name="l00896"></a>00896 
<a name="l00897"></a>00897 <span class="preprocessor">#include &quot;math.h&quot;</span>
<a name="l00898"></a>00898 
<a name="l00899"></a>00899 <span class="keyword">static</span> <span class="keywordtype">double</span> vp8_mse2psnr(<span class="keywordtype">double</span> Samples, <span class="keywordtype">double</span> Peak, <span class="keywordtype">double</span> Mse)
<a name="l00900"></a>00900 {
<a name="l00901"></a>00901     <span class="keywordtype">double</span> psnr;
<a name="l00902"></a>00902 
<a name="l00903"></a>00903     <span class="keywordflow">if</span> ((<span class="keywordtype">double</span>)Mse &gt; 0.0)
<a name="l00904"></a>00904         psnr = 10.0 * log10(Peak * Peak * Samples / Mse);
<a name="l00905"></a>00905     <span class="keywordflow">else</span>
<a name="l00906"></a>00906         psnr = 60;      <span class="comment">// Limit to prevent / 0</span>
<a name="l00907"></a>00907 
<a name="l00908"></a>00908     <span class="keywordflow">if</span> (psnr &gt; 60)
<a name="l00909"></a>00909         psnr = 60;
<a name="l00910"></a>00910 
<a name="l00911"></a>00911     <span class="keywordflow">return</span> psnr;
<a name="l00912"></a>00912 }
<a name="l00913"></a>00913 
<a name="l00914"></a>00914 
<a name="l00915"></a>00915 <span class="preprocessor">#include &quot;args.h&quot;</span>
<a name="l00916"></a>00916 
<a name="l00917"></a>00917 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t debugmode = ARG_DEF(<span class="stringliteral">&quot;D&quot;</span>, <span class="stringliteral">&quot;debug&quot;</span>, 0,
<a name="l00918"></a>00918         <span class="stringliteral">&quot;Debug mode (makes output deterministic)&quot;</span>);
<a name="l00919"></a>00919 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t outputfile = ARG_DEF(<span class="stringliteral">&quot;o&quot;</span>, <span class="stringliteral">&quot;output&quot;</span>, 1,
<a name="l00920"></a>00920         <span class="stringliteral">&quot;Output filename&quot;</span>);
<a name="l00921"></a>00921 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t use_yv12 = ARG_DEF(NULL, <span class="stringliteral">&quot;yv12&quot;</span>, 0,
<a name="l00922"></a>00922                                   <span class="stringliteral">&quot;Input file is YV12 &quot;</span>);
<a name="l00923"></a>00923 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t use_i420 = ARG_DEF(NULL, <span class="stringliteral">&quot;i420&quot;</span>, 0,
<a name="l00924"></a>00924                                   <span class="stringliteral">&quot;Input file is I420 (default)&quot;</span>);
<a name="l00925"></a>00925 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t codecarg = ARG_DEF(NULL, <span class="stringliteral">&quot;codec&quot;</span>, 1,
<a name="l00926"></a>00926                                   <span class="stringliteral">&quot;Codec to use&quot;</span>);
<a name="l00927"></a>00927 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t passes           = ARG_DEF(<span class="stringliteral">&quot;p&quot;</span>, <span class="stringliteral">&quot;passes&quot;</span>, 1,
<a name="l00928"></a>00928         <span class="stringliteral">&quot;Number of passes (1/2)&quot;</span>);
<a name="l00929"></a>00929 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t pass_arg         = ARG_DEF(NULL, <span class="stringliteral">&quot;pass&quot;</span>, 1,
<a name="l00930"></a>00930         <span class="stringliteral">&quot;Pass to execute (1/2)&quot;</span>);
<a name="l00931"></a>00931 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t fpf_name         = ARG_DEF(NULL, <span class="stringliteral">&quot;fpf&quot;</span>, 1,
<a name="l00932"></a>00932         <span class="stringliteral">&quot;First pass statistics file name&quot;</span>);
<a name="l00933"></a>00933 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t limit = ARG_DEF(NULL, <span class="stringliteral">&quot;limit&quot;</span>, 1,
<a name="l00934"></a>00934                                        <span class="stringliteral">&quot;Stop encoding after n input frames&quot;</span>);
<a name="l00935"></a>00935 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t deadline         = ARG_DEF(<span class="stringliteral">&quot;d&quot;</span>, <span class="stringliteral">&quot;deadline&quot;</span>, 1,
<a name="l00936"></a>00936         <span class="stringliteral">&quot;Deadline per frame (usec)&quot;</span>);
<a name="l00937"></a>00937 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t best_dl          = ARG_DEF(NULL, <span class="stringliteral">&quot;best&quot;</span>, 0,
<a name="l00938"></a>00938         <span class="stringliteral">&quot;Use Best Quality Deadline&quot;</span>);
<a name="l00939"></a>00939 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t good_dl          = ARG_DEF(NULL, <span class="stringliteral">&quot;good&quot;</span>, 0,
<a name="l00940"></a>00940         <span class="stringliteral">&quot;Use Good Quality Deadline&quot;</span>);
<a name="l00941"></a>00941 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t rt_dl            = ARG_DEF(NULL, <span class="stringliteral">&quot;rt&quot;</span>, 0,
<a name="l00942"></a>00942         <span class="stringliteral">&quot;Use Realtime Quality Deadline&quot;</span>);
<a name="l00943"></a>00943 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t verbosearg       = ARG_DEF(<span class="stringliteral">&quot;v&quot;</span>, <span class="stringliteral">&quot;verbose&quot;</span>, 0,
<a name="l00944"></a>00944         <span class="stringliteral">&quot;Show encoder parameters&quot;</span>);
<a name="l00945"></a>00945 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t psnrarg          = ARG_DEF(NULL, <span class="stringliteral">&quot;psnr&quot;</span>, 0,
<a name="l00946"></a>00946         <span class="stringliteral">&quot;Show PSNR in status line&quot;</span>);
<a name="l00947"></a>00947 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t framerate        = ARG_DEF(NULL, <span class="stringliteral">&quot;fps&quot;</span>, 1,
<a name="l00948"></a>00948         <span class="stringliteral">&quot;Stream frame rate (rate/scale)&quot;</span>);
<a name="l00949"></a>00949 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t use_ivf          = ARG_DEF(NULL, <span class="stringliteral">&quot;ivf&quot;</span>, 0,
<a name="l00950"></a>00950         <span class="stringliteral">&quot;Output IVF (default is WebM)&quot;</span>);
<a name="l00951"></a>00951 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t q_hist_n         = ARG_DEF(NULL, <span class="stringliteral">&quot;q-hist&quot;</span>, 1,
<a name="l00952"></a>00952         <span class="stringliteral">&quot;Show quantizer histogram (n-buckets)&quot;</span>);
<a name="l00953"></a>00953 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t rate_hist_n         = ARG_DEF(NULL, <span class="stringliteral">&quot;rate-hist&quot;</span>, 1,
<a name="l00954"></a>00954         <span class="stringliteral">&quot;Show rate histogram (n-buckets)&quot;</span>);
<a name="l00955"></a>00955 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t *main_args[] =
<a name="l00956"></a>00956 {
<a name="l00957"></a>00957     &amp;debugmode,
<a name="l00958"></a>00958     &amp;outputfile, &amp;codecarg, &amp;passes, &amp;pass_arg, &amp;fpf_name, &amp;limit, &amp;deadline,
<a name="l00959"></a>00959     &amp;best_dl, &amp;good_dl, &amp;rt_dl,
<a name="l00960"></a>00960     &amp;verbosearg, &amp;psnrarg, &amp;use_ivf, &amp;q_hist_n, &amp;rate_hist_n,
<a name="l00961"></a>00961     NULL
<a name="l00962"></a>00962 };
<a name="l00963"></a>00963 
<a name="l00964"></a>00964 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t usage            = ARG_DEF(<span class="stringliteral">&quot;u&quot;</span>, <span class="stringliteral">&quot;usage&quot;</span>, 1,
<a name="l00965"></a>00965         <span class="stringliteral">&quot;Usage profile number to use&quot;</span>);
<a name="l00966"></a>00966 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t threads          = ARG_DEF(<span class="stringliteral">&quot;t&quot;</span>, <span class="stringliteral">&quot;threads&quot;</span>, 1,
<a name="l00967"></a>00967         <span class="stringliteral">&quot;Max number of threads to use&quot;</span>);
<a name="l00968"></a>00968 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t profile          = ARG_DEF(NULL, <span class="stringliteral">&quot;profile&quot;</span>, 1,
<a name="l00969"></a>00969         <span class="stringliteral">&quot;Bitstream profile number to use&quot;</span>);
<a name="l00970"></a>00970 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t width            = ARG_DEF(<span class="stringliteral">&quot;w&quot;</span>, <span class="stringliteral">&quot;width&quot;</span>, 1,
<a name="l00971"></a>00971         <span class="stringliteral">&quot;Frame width&quot;</span>);
<a name="l00972"></a>00972 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t height           = ARG_DEF(<span class="stringliteral">&quot;h&quot;</span>, <span class="stringliteral">&quot;height&quot;</span>, 1,
<a name="l00973"></a>00973         <span class="stringliteral">&quot;Frame height&quot;</span>);
<a name="l00974"></a>00974 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">struct </span>arg_enum_list stereo_mode_enum[] = {
<a name="l00975"></a>00975     {<span class="stringliteral">&quot;mono&quot;</span>      , STEREO_FORMAT_MONO},
<a name="l00976"></a>00976     {<span class="stringliteral">&quot;left-right&quot;</span>, STEREO_FORMAT_LEFT_RIGHT},
<a name="l00977"></a>00977     {<span class="stringliteral">&quot;bottom-top&quot;</span>, STEREO_FORMAT_BOTTOM_TOP},
<a name="l00978"></a>00978     {<span class="stringliteral">&quot;top-bottom&quot;</span>, STEREO_FORMAT_TOP_BOTTOM},
<a name="l00979"></a>00979     {<span class="stringliteral">&quot;right-left&quot;</span>, STEREO_FORMAT_RIGHT_LEFT},
<a name="l00980"></a>00980     {NULL, 0}
<a name="l00981"></a>00981 };
<a name="l00982"></a>00982 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t stereo_mode      = ARG_DEF_ENUM(NULL, <span class="stringliteral">&quot;stereo-mode&quot;</span>, 1,
<a name="l00983"></a>00983         <span class="stringliteral">&quot;Stereo 3D video format&quot;</span>, stereo_mode_enum);
<a name="l00984"></a>00984 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t timebase         = ARG_DEF(NULL, <span class="stringliteral">&quot;timebase&quot;</span>, 1,
<a name="l00985"></a>00985         <span class="stringliteral">&quot;Output timestamp precision (fractional seconds)&quot;</span>);
<a name="l00986"></a>00986 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t error_resilient  = ARG_DEF(NULL, <span class="stringliteral">&quot;error-resilient&quot;</span>, 1,
<a name="l00987"></a>00987         <span class="stringliteral">&quot;Enable error resiliency features&quot;</span>);
<a name="l00988"></a>00988 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t lag_in_frames    = ARG_DEF(NULL, <span class="stringliteral">&quot;lag-in-frames&quot;</span>, 1,
<a name="l00989"></a>00989         <span class="stringliteral">&quot;Max number of frames to lag&quot;</span>);
<a name="l00990"></a>00990 
<a name="l00991"></a>00991 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t *global_args[] =
<a name="l00992"></a>00992 {
<a name="l00993"></a>00993     &amp;use_yv12, &amp;use_i420, &amp;usage, &amp;threads, &amp;profile,
<a name="l00994"></a>00994     &amp;width, &amp;height, &amp;stereo_mode, &amp;timebase, &amp;framerate, &amp;error_resilient,
<a name="l00995"></a>00995     &amp;lag_in_frames, NULL
<a name="l00996"></a>00996 };
<a name="l00997"></a>00997 
<a name="l00998"></a>00998 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t dropframe_thresh   = ARG_DEF(NULL, <span class="stringliteral">&quot;drop-frame&quot;</span>, 1,
<a name="l00999"></a>00999         <span class="stringliteral">&quot;Temporal resampling threshold (buf %)&quot;</span>);
<a name="l01000"></a>01000 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t resize_allowed     = ARG_DEF(NULL, <span class="stringliteral">&quot;resize-allowed&quot;</span>, 1,
<a name="l01001"></a>01001         <span class="stringliteral">&quot;Spatial resampling enabled (bool)&quot;</span>);
<a name="l01002"></a>01002 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t resize_up_thresh   = ARG_DEF(NULL, <span class="stringliteral">&quot;resize-up&quot;</span>, 1,
<a name="l01003"></a>01003         <span class="stringliteral">&quot;Upscale threshold (buf %)&quot;</span>);
<a name="l01004"></a>01004 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t resize_down_thresh = ARG_DEF(NULL, <span class="stringliteral">&quot;resize-down&quot;</span>, 1,
<a name="l01005"></a>01005         <span class="stringliteral">&quot;Downscale threshold (buf %)&quot;</span>);
<a name="l01006"></a>01006 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">struct </span>arg_enum_list end_usage_enum[] = {
<a name="l01007"></a>01007     {<span class="stringliteral">&quot;vbr&quot;</span>, <a class="code" href="group__encoder.html#ggaf50e74d91be4cae6f70dfeba5b7410d2ab8fbe4441ed3f31a167c8194e8a64f87">VPX_VBR</a>},
<a name="l01008"></a>01008     {<span class="stringliteral">&quot;cbr&quot;</span>, <a class="code" href="group__encoder.html#ggaf50e74d91be4cae6f70dfeba5b7410d2a8b02853cb35790d60cc171a11f6c268a">VPX_CBR</a>},
<a name="l01009"></a>01009     {<span class="stringliteral">&quot;cq&quot;</span>,  <a class="code" href="group__encoder.html#ggaf50e74d91be4cae6f70dfeba5b7410d2a5f2fd02b55c67d62bfd79380bcb03f63">VPX_CQ</a>},
<a name="l01010"></a>01010     {NULL, 0}
<a name="l01011"></a>01011 };
<a name="l01012"></a>01012 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t end_usage          = ARG_DEF_ENUM(NULL, <span class="stringliteral">&quot;end-usage&quot;</span>, 1,
<a name="l01013"></a>01013         <span class="stringliteral">&quot;Rate control mode&quot;</span>, end_usage_enum);
<a name="l01014"></a>01014 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t target_bitrate     = ARG_DEF(NULL, <span class="stringliteral">&quot;target-bitrate&quot;</span>, 1,
<a name="l01015"></a>01015         <span class="stringliteral">&quot;Bitrate (kbps)&quot;</span>);
<a name="l01016"></a>01016 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t min_quantizer      = ARG_DEF(NULL, <span class="stringliteral">&quot;min-q&quot;</span>, 1,
<a name="l01017"></a>01017         <span class="stringliteral">&quot;Minimum (best) quantizer&quot;</span>);
<a name="l01018"></a>01018 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t max_quantizer      = ARG_DEF(NULL, <span class="stringliteral">&quot;max-q&quot;</span>, 1,
<a name="l01019"></a>01019         <span class="stringliteral">&quot;Maximum (worst) quantizer&quot;</span>);
<a name="l01020"></a>01020 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t undershoot_pct     = ARG_DEF(NULL, <span class="stringliteral">&quot;undershoot-pct&quot;</span>, 1,
<a name="l01021"></a>01021         <span class="stringliteral">&quot;Datarate undershoot (min) target (%)&quot;</span>);
<a name="l01022"></a>01022 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t overshoot_pct      = ARG_DEF(NULL, <span class="stringliteral">&quot;overshoot-pct&quot;</span>, 1,
<a name="l01023"></a>01023         <span class="stringliteral">&quot;Datarate overshoot (max) target (%)&quot;</span>);
<a name="l01024"></a>01024 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t buf_sz             = ARG_DEF(NULL, <span class="stringliteral">&quot;buf-sz&quot;</span>, 1,
<a name="l01025"></a>01025         <span class="stringliteral">&quot;Client buffer size (ms)&quot;</span>);
<a name="l01026"></a>01026 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t buf_initial_sz     = ARG_DEF(NULL, <span class="stringliteral">&quot;buf-initial-sz&quot;</span>, 1,
<a name="l01027"></a>01027         <span class="stringliteral">&quot;Client initial buffer size (ms)&quot;</span>);
<a name="l01028"></a>01028 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t buf_optimal_sz     = ARG_DEF(NULL, <span class="stringliteral">&quot;buf-optimal-sz&quot;</span>, 1,
<a name="l01029"></a>01029         <span class="stringliteral">&quot;Client optimal buffer size (ms)&quot;</span>);
<a name="l01030"></a>01030 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t *rc_args[] =
<a name="l01031"></a>01031 {
<a name="l01032"></a>01032     &amp;dropframe_thresh, &amp;resize_allowed, &amp;resize_up_thresh, &amp;resize_down_thresh,
<a name="l01033"></a>01033     &amp;end_usage, &amp;target_bitrate, &amp;min_quantizer, &amp;max_quantizer,
<a name="l01034"></a>01034     &amp;undershoot_pct, &amp;overshoot_pct, &amp;buf_sz, &amp;buf_initial_sz, &amp;buf_optimal_sz,
<a name="l01035"></a>01035     NULL
<a name="l01036"></a>01036 };
<a name="l01037"></a>01037 
<a name="l01038"></a>01038 
<a name="l01039"></a>01039 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t bias_pct = ARG_DEF(NULL, <span class="stringliteral">&quot;bias-pct&quot;</span>, 1,
<a name="l01040"></a>01040                                   <span class="stringliteral">&quot;CBR/VBR bias (0=CBR, 100=VBR)&quot;</span>);
<a name="l01041"></a>01041 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t minsection_pct = ARG_DEF(NULL, <span class="stringliteral">&quot;minsection-pct&quot;</span>, 1,
<a name="l01042"></a>01042                                         <span class="stringliteral">&quot;GOP min bitrate (% of target)&quot;</span>);
<a name="l01043"></a>01043 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t maxsection_pct = ARG_DEF(NULL, <span class="stringliteral">&quot;maxsection-pct&quot;</span>, 1,
<a name="l01044"></a>01044                                         <span class="stringliteral">&quot;GOP max bitrate (% of target)&quot;</span>);
<a name="l01045"></a>01045 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t *rc_twopass_args[] =
<a name="l01046"></a>01046 {
<a name="l01047"></a>01047     &amp;bias_pct, &amp;minsection_pct, &amp;maxsection_pct, NULL
<a name="l01048"></a>01048 };
<a name="l01049"></a>01049 
<a name="l01050"></a>01050 
<a name="l01051"></a>01051 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t kf_min_dist = ARG_DEF(NULL, <span class="stringliteral">&quot;kf-min-dist&quot;</span>, 1,
<a name="l01052"></a>01052                                      <span class="stringliteral">&quot;Minimum keyframe interval (frames)&quot;</span>);
<a name="l01053"></a>01053 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t kf_max_dist = ARG_DEF(NULL, <span class="stringliteral">&quot;kf-max-dist&quot;</span>, 1,
<a name="l01054"></a>01054                                      <span class="stringliteral">&quot;Maximum keyframe interval (frames)&quot;</span>);
<a name="l01055"></a>01055 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t kf_disabled = ARG_DEF(NULL, <span class="stringliteral">&quot;disable-kf&quot;</span>, 0,
<a name="l01056"></a>01056                                      <span class="stringliteral">&quot;Disable keyframe placement&quot;</span>);
<a name="l01057"></a>01057 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t *kf_args[] =
<a name="l01058"></a>01058 {
<a name="l01059"></a>01059     &amp;kf_min_dist, &amp;kf_max_dist, &amp;kf_disabled, NULL
<a name="l01060"></a>01060 };
<a name="l01061"></a>01061 
<a name="l01062"></a>01062 
<a name="l01063"></a>01063 <span class="preprocessor">#if CONFIG_VP8_ENCODER</span>
<a name="l01064"></a>01064 <span class="preprocessor"></span><span class="keyword">static</span> <span class="keyword">const</span> arg_def_t noise_sens = ARG_DEF(NULL, <span class="stringliteral">&quot;noise-sensitivity&quot;</span>, 1,
<a name="l01065"></a>01065                                     <span class="stringliteral">&quot;Noise sensitivity (frames to blur)&quot;</span>);
<a name="l01066"></a>01066 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t sharpness = ARG_DEF(NULL, <span class="stringliteral">&quot;sharpness&quot;</span>, 1,
<a name="l01067"></a>01067                                    <span class="stringliteral">&quot;Filter sharpness (0-7)&quot;</span>);
<a name="l01068"></a>01068 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t static_thresh = ARG_DEF(NULL, <span class="stringliteral">&quot;static-thresh&quot;</span>, 1,
<a name="l01069"></a>01069                                        <span class="stringliteral">&quot;Motion detection threshold&quot;</span>);
<a name="l01070"></a>01070 <span class="preprocessor">#endif</span>
<a name="l01071"></a>01071 <span class="preprocessor"></span>
<a name="l01072"></a>01072 <span class="preprocessor">#if CONFIG_VP8_ENCODER</span>
<a name="l01073"></a>01073 <span class="preprocessor"></span><span class="keyword">static</span> <span class="keyword">const</span> arg_def_t cpu_used = ARG_DEF(NULL, <span class="stringliteral">&quot;cpu-used&quot;</span>, 1,
<a name="l01074"></a>01074                                   <span class="stringliteral">&quot;CPU Used (-16..16)&quot;</span>);
<a name="l01075"></a>01075 <span class="preprocessor">#endif</span>
<a name="l01076"></a>01076 <span class="preprocessor"></span>
<a name="l01077"></a>01077 
<a name="l01078"></a>01078 <span class="preprocessor">#if CONFIG_VP8_ENCODER</span>
<a name="l01079"></a>01079 <span class="preprocessor"></span><span class="keyword">static</span> <span class="keyword">const</span> arg_def_t token_parts = ARG_DEF(NULL, <span class="stringliteral">&quot;token-parts&quot;</span>, 1,
<a name="l01080"></a>01080                                      <span class="stringliteral">&quot;Number of token partitions to use, log2&quot;</span>);
<a name="l01081"></a>01081 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t auto_altref = ARG_DEF(NULL, <span class="stringliteral">&quot;auto-alt-ref&quot;</span>, 1,
<a name="l01082"></a>01082                                      <span class="stringliteral">&quot;Enable automatic alt reference frames&quot;</span>);
<a name="l01083"></a>01083 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t arnr_maxframes = ARG_DEF(NULL, <span class="stringliteral">&quot;arnr-maxframes&quot;</span>, 1,
<a name="l01084"></a>01084                                         <span class="stringliteral">&quot;AltRef Max Frames&quot;</span>);
<a name="l01085"></a>01085 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t arnr_strength = ARG_DEF(NULL, <span class="stringliteral">&quot;arnr-strength&quot;</span>, 1,
<a name="l01086"></a>01086                                        <span class="stringliteral">&quot;AltRef Strength&quot;</span>);
<a name="l01087"></a>01087 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t arnr_type = ARG_DEF(NULL, <span class="stringliteral">&quot;arnr-type&quot;</span>, 1,
<a name="l01088"></a>01088                                    <span class="stringliteral">&quot;AltRef Type&quot;</span>);
<a name="l01089"></a>01089 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">struct </span>arg_enum_list tuning_enum[] = {
<a name="l01090"></a>01090     {<span class="stringliteral">&quot;psnr&quot;</span>, VP8_TUNE_PSNR},
<a name="l01091"></a>01091     {<span class="stringliteral">&quot;ssim&quot;</span>, VP8_TUNE_SSIM},
<a name="l01092"></a>01092     {NULL, 0}
<a name="l01093"></a>01093 };
<a name="l01094"></a>01094 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t tune_ssim = ARG_DEF_ENUM(NULL, <span class="stringliteral">&quot;tune&quot;</span>, 1,
<a name="l01095"></a>01095                                    <span class="stringliteral">&quot;Material to favor&quot;</span>, tuning_enum);
<a name="l01096"></a>01096 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t cq_level = ARG_DEF(NULL, <span class="stringliteral">&quot;cq-level&quot;</span>, 1,
<a name="l01097"></a>01097                                    <span class="stringliteral">&quot;Constrained Quality Level&quot;</span>);
<a name="l01098"></a>01098 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t max_intra_rate_pct = ARG_DEF(NULL, <span class="stringliteral">&quot;max-intra-rate&quot;</span>, 1,
<a name="l01099"></a>01099         <span class="stringliteral">&quot;Max I-frame bitrate (pct)&quot;</span>);
<a name="l01100"></a>01100 
<a name="l01101"></a>01101 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t *vp8_args[] =
<a name="l01102"></a>01102 {
<a name="l01103"></a>01103     &amp;cpu_used, &amp;auto_altref, &amp;noise_sens, &amp;sharpness, &amp;static_thresh,
<a name="l01104"></a>01104     &amp;token_parts, &amp;arnr_maxframes, &amp;arnr_strength, &amp;arnr_type,
<a name="l01105"></a>01105     &amp;tune_ssim, &amp;cq_level, &amp;max_intra_rate_pct, NULL
<a name="l01106"></a>01106 };
<a name="l01107"></a>01107 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">int</span> vp8_arg_ctrl_map[] =
<a name="l01108"></a>01108 {
<a name="l01109"></a>01109     <a class="code" href="group__vp8__encoder.html#gga6deae3d561c838952552c3d3756322eca953ff0eaa2fcdc2ecd627e449b026853" title="control function to set vp8 encoder cpuused">VP8E_SET_CPUUSED</a>, <a class="code" href="group__vp8__encoder.html#gga6deae3d561c838952552c3d3756322eca24a5530efabb8b4949d01622b1d72cb0">VP8E_SET_ENABLEAUTOALTREF</a>,
<a name="l01110"></a>01110     <a class="code" href="group__vp8__encoder.html#gga6deae3d561c838952552c3d3756322eca3fa90cb70bade72af3c2d8d91471a36c">VP8E_SET_NOISE_SENSITIVITY</a>, <a class="code" href="group__vp8__encoder.html#gga6deae3d561c838952552c3d3756322eca815930923fff388825ee3cc4ef69bb28">VP8E_SET_SHARPNESS</a>, <a class="code" href="group__vp8__encoder.html#gga6deae3d561c838952552c3d3756322ecab34559df04d3d662616300ed0682dcfd">VP8E_SET_STATIC_THRESHOLD</a>,
<a name="l01111"></a>01111     <a class="code" href="group__vp8__encoder.html#gga6deae3d561c838952552c3d3756322eca462a4f14f39a6eb5c4a4004fc8d0ad75">VP8E_SET_TOKEN_PARTITIONS</a>,
<a name="l01112"></a>01112     <a class="code" href="group__vp8__encoder.html#gga6deae3d561c838952552c3d3756322eca628d73f1a69fadd8aa57e0dfef578da8">VP8E_SET_ARNR_MAXFRAMES</a>, <a class="code" href="group__vp8__encoder.html#gga6deae3d561c838952552c3d3756322eca0a8c40a768af935ae73faa53355c3244">VP8E_SET_ARNR_STRENGTH</a> , <a class="code" href="group__vp8__encoder.html#gga6deae3d561c838952552c3d3756322eca4e0a0af58670012026c213083cd48f3a">VP8E_SET_ARNR_TYPE</a>,
<a name="l01113"></a>01113     <a class="code" href="group__vp8__encoder.html#gga6deae3d561c838952552c3d3756322eca126ccbe7bde63b59cec5ea68a82dd498">VP8E_SET_TUNING</a>, <a class="code" href="group__vp8__encoder.html#gga6deae3d561c838952552c3d3756322ecacd4f5b730bddb9788c3d0b82218ec503" title="control function to set constrained quality level">VP8E_SET_CQ_LEVEL</a>, <a class="code" href="group__vp8__encoder.html#gga6deae3d561c838952552c3d3756322eca09c69ff4a3aabdb307d4f24027dfc4c1" title="Max data rate for Intra frames.">VP8E_SET_MAX_INTRA_BITRATE_PCT</a>, 0
<a name="l01114"></a>01114 };
<a name="l01115"></a>01115 <span class="preprocessor">#endif</span>
<a name="l01116"></a>01116 <span class="preprocessor"></span>
<a name="l01117"></a>01117 <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t *no_args[] = { NULL };
<a name="l01118"></a>01118 
<a name="l01119"></a>01119 <span class="keyword">static</span> <span class="keywordtype">void</span> usage_exit()
<a name="l01120"></a>01120 {
<a name="l01121"></a>01121     <span class="keywordtype">int</span> i;
<a name="l01122"></a>01122 
<a name="l01123"></a>01123     fprintf(stderr, <span class="stringliteral">&quot;Usage: %s &lt;options&gt; -o dst_filename src_filename \n&quot;</span>,
<a name="l01124"></a>01124             exec_name);
<a name="l01125"></a>01125 
<a name="l01126"></a>01126     fprintf(stderr, <span class="stringliteral">&quot;\nOptions:\n&quot;</span>);
<a name="l01127"></a>01127     arg_show_usage(stdout, main_args);
<a name="l01128"></a>01128     fprintf(stderr, <span class="stringliteral">&quot;\nEncoder Global Options:\n&quot;</span>);
<a name="l01129"></a>01129     arg_show_usage(stdout, global_args);
<a name="l01130"></a>01130     fprintf(stderr, <span class="stringliteral">&quot;\nRate Control Options:\n&quot;</span>);
<a name="l01131"></a>01131     arg_show_usage(stdout, rc_args);
<a name="l01132"></a>01132     fprintf(stderr, <span class="stringliteral">&quot;\nTwopass Rate Control Options:\n&quot;</span>);
<a name="l01133"></a>01133     arg_show_usage(stdout, rc_twopass_args);
<a name="l01134"></a>01134     fprintf(stderr, <span class="stringliteral">&quot;\nKeyframe Placement Options:\n&quot;</span>);
<a name="l01135"></a>01135     arg_show_usage(stdout, kf_args);
<a name="l01136"></a>01136 <span class="preprocessor">#if CONFIG_VP8_ENCODER</span>
<a name="l01137"></a>01137 <span class="preprocessor"></span>    fprintf(stderr, <span class="stringliteral">&quot;\nVP8 Specific Options:\n&quot;</span>);
<a name="l01138"></a>01138     arg_show_usage(stdout, vp8_args);
<a name="l01139"></a>01139 <span class="preprocessor">#endif</span>
<a name="l01140"></a>01140 <span class="preprocessor"></span>    fprintf(stderr, <span class="stringliteral">&quot;\nStream timebase (--timebase):\n&quot;</span>
<a name="l01141"></a>01141             <span class="stringliteral">&quot;  The desired precision of timestamps in the output, expressed\n&quot;</span>
<a name="l01142"></a>01142             <span class="stringliteral">&quot;  in fractional seconds. Default is 1/1000.\n&quot;</span>);
<a name="l01143"></a>01143     fprintf(stderr, <span class="stringliteral">&quot;\n&quot;</span>
<a name="l01144"></a>01144            <span class="stringliteral">&quot;Included encoders:\n&quot;</span>
<a name="l01145"></a>01145            <span class="stringliteral">&quot;\n&quot;</span>);
<a name="l01146"></a>01146 
<a name="l01147"></a>01147     <span class="keywordflow">for</span> (i = 0; i &lt; <span class="keyword">sizeof</span>(codecs) / <span class="keyword">sizeof</span>(codecs[0]); i++)
<a name="l01148"></a>01148         fprintf(stderr, <span class="stringliteral">&quot;    %-6s - %s\n&quot;</span>,
<a name="l01149"></a>01149                codecs[i].name,
<a name="l01150"></a>01150                <a class="code" href="group__codec.html#ga9eee39f450d8cdcf5aba0e2bda6e5aa8" title="Return the name for a given interface.">vpx_codec_iface_name</a>(codecs[i].iface));
<a name="l01151"></a>01151 
<a name="l01152"></a>01152     exit(EXIT_FAILURE);
<a name="l01153"></a>01153 }
<a name="l01154"></a>01154 
<a name="l01155"></a>01155 
<a name="l01156"></a>01156 <span class="preprocessor">#define HIST_BAR_MAX 40</span>
<a name="l01157"></a>01157 <span class="preprocessor"></span><span class="keyword">struct </span>hist_bucket
<a name="l01158"></a>01158 {
<a name="l01159"></a>01159     <span class="keywordtype">int</span> low, high, count;
<a name="l01160"></a>01160 };
<a name="l01161"></a>01161 
<a name="l01162"></a>01162 
<a name="l01163"></a>01163 <span class="keyword">static</span> <span class="keywordtype">int</span> merge_hist_buckets(<span class="keyword">struct</span> hist_bucket *bucket,
<a name="l01164"></a>01164                               <span class="keywordtype">int</span> *buckets_,
<a name="l01165"></a>01165                               <span class="keywordtype">int</span> max_buckets)
<a name="l01166"></a>01166 {
<a name="l01167"></a>01167     <span class="keywordtype">int</span> small_bucket = 0, merge_bucket = INT_MAX, big_bucket=0;
<a name="l01168"></a>01168     <span class="keywordtype">int</span> buckets = *buckets_;
<a name="l01169"></a>01169     <span class="keywordtype">int</span> i;
<a name="l01170"></a>01170 
<a name="l01171"></a>01171     <span class="comment">/* Find the extrema for this list of buckets */</span>
<a name="l01172"></a>01172     big_bucket = small_bucket = 0;
<a name="l01173"></a>01173     <span class="keywordflow">for</span>(i=0; i &lt; buckets; i++)
<a name="l01174"></a>01174     {
<a name="l01175"></a>01175         <span class="keywordflow">if</span>(bucket[i].count &lt; bucket[small_bucket].count)
<a name="l01176"></a>01176             small_bucket = i;
<a name="l01177"></a>01177         <span class="keywordflow">if</span>(bucket[i].count &gt; bucket[big_bucket].count)
<a name="l01178"></a>01178             big_bucket = i;
<a name="l01179"></a>01179     }
<a name="l01180"></a>01180 
<a name="l01181"></a>01181     <span class="comment">/* If we have too many buckets, merge the smallest with an adjacent</span>
<a name="l01182"></a>01182 <span class="comment">     * bucket.</span>
<a name="l01183"></a>01183 <span class="comment">     */</span>
<a name="l01184"></a>01184     <span class="keywordflow">while</span>(buckets &gt; max_buckets)
<a name="l01185"></a>01185     {
<a name="l01186"></a>01186         <span class="keywordtype">int</span> last_bucket = buckets - 1;
<a name="l01187"></a>01187 
<a name="l01188"></a>01188         <span class="comment">// merge the small bucket with an adjacent one.</span>
<a name="l01189"></a>01189         <span class="keywordflow">if</span>(small_bucket == 0)
<a name="l01190"></a>01190             merge_bucket = 1;
<a name="l01191"></a>01191         <span class="keywordflow">else</span> <span class="keywordflow">if</span>(small_bucket == last_bucket)
<a name="l01192"></a>01192             merge_bucket = last_bucket - 1;
<a name="l01193"></a>01193         <span class="keywordflow">else</span> <span class="keywordflow">if</span>(bucket[small_bucket - 1].count &lt; bucket[small_bucket + 1].count)
<a name="l01194"></a>01194             merge_bucket = small_bucket - 1;
<a name="l01195"></a>01195         <span class="keywordflow">else</span>
<a name="l01196"></a>01196             merge_bucket = small_bucket + 1;
<a name="l01197"></a>01197 
<a name="l01198"></a>01198         assert(abs(merge_bucket - small_bucket) &lt;= 1);
<a name="l01199"></a>01199         assert(small_bucket &lt; buckets);
<a name="l01200"></a>01200         assert(big_bucket &lt; buckets);
<a name="l01201"></a>01201         assert(merge_bucket &lt; buckets);
<a name="l01202"></a>01202 
<a name="l01203"></a>01203         <span class="keywordflow">if</span>(merge_bucket &lt; small_bucket)
<a name="l01204"></a>01204         {
<a name="l01205"></a>01205             bucket[merge_bucket].high = bucket[small_bucket].high;
<a name="l01206"></a>01206             bucket[merge_bucket].count += bucket[small_bucket].count;
<a name="l01207"></a>01207         }
<a name="l01208"></a>01208         <span class="keywordflow">else</span>
<a name="l01209"></a>01209         {
<a name="l01210"></a>01210             bucket[small_bucket].high = bucket[merge_bucket].high;
<a name="l01211"></a>01211             bucket[small_bucket].count += bucket[merge_bucket].count;
<a name="l01212"></a>01212             merge_bucket = small_bucket;
<a name="l01213"></a>01213         }
<a name="l01214"></a>01214 
<a name="l01215"></a>01215         assert(bucket[merge_bucket].low != bucket[merge_bucket].high);
<a name="l01216"></a>01216 
<a name="l01217"></a>01217         buckets--;
<a name="l01218"></a>01218 
<a name="l01219"></a>01219         <span class="comment">/* Remove the merge_bucket from the list, and find the new small</span>
<a name="l01220"></a>01220 <span class="comment">         * and big buckets while we&#39;re at it</span>
<a name="l01221"></a>01221 <span class="comment">         */</span>
<a name="l01222"></a>01222         big_bucket = small_bucket = 0;
<a name="l01223"></a>01223         <span class="keywordflow">for</span>(i=0; i &lt; buckets; i++)
<a name="l01224"></a>01224         {
<a name="l01225"></a>01225             <span class="keywordflow">if</span>(i &gt; merge_bucket)
<a name="l01226"></a>01226                 bucket[i] = bucket[i+1];
<a name="l01227"></a>01227 
<a name="l01228"></a>01228             <span class="keywordflow">if</span>(bucket[i].count &lt; bucket[small_bucket].count)
<a name="l01229"></a>01229                 small_bucket = i;
<a name="l01230"></a>01230             <span class="keywordflow">if</span>(bucket[i].count &gt; bucket[big_bucket].count)
<a name="l01231"></a>01231                 big_bucket = i;
<a name="l01232"></a>01232         }
<a name="l01233"></a>01233 
<a name="l01234"></a>01234     }
<a name="l01235"></a>01235 
<a name="l01236"></a>01236     *buckets_ = buckets;
<a name="l01237"></a>01237     <span class="keywordflow">return</span> bucket[big_bucket].count;
<a name="l01238"></a>01238 }
<a name="l01239"></a>01239 
<a name="l01240"></a>01240 
<a name="l01241"></a>01241 <span class="keyword">static</span> <span class="keywordtype">void</span> show_histogram(<span class="keyword">const</span> <span class="keyword">struct</span> hist_bucket *bucket,
<a name="l01242"></a>01242                            <span class="keywordtype">int</span>                       buckets,
<a name="l01243"></a>01243                            <span class="keywordtype">int</span>                       total,
<a name="l01244"></a>01244                            <span class="keywordtype">int</span>                       scale)
<a name="l01245"></a>01245 {
<a name="l01246"></a>01246     <span class="keyword">const</span> <span class="keywordtype">char</span> *pat1, *pat2;
<a name="l01247"></a>01247     <span class="keywordtype">int</span> i;
<a name="l01248"></a>01248 
<a name="l01249"></a>01249     <span class="keywordflow">switch</span>((<span class="keywordtype">int</span>)(log(bucket[buckets-1].high)/log(10))+1)
<a name="l01250"></a>01250     {
<a name="l01251"></a>01251         <span class="keywordflow">case</span> 1:
<a name="l01252"></a>01252         <span class="keywordflow">case</span> 2:
<a name="l01253"></a>01253             pat1 = <span class="stringliteral">&quot;%4d %2s: &quot;</span>;
<a name="l01254"></a>01254             pat2 = <span class="stringliteral">&quot;%4d-%2d: &quot;</span>;
<a name="l01255"></a>01255             <span class="keywordflow">break</span>;
<a name="l01256"></a>01256         <span class="keywordflow">case</span> 3:
<a name="l01257"></a>01257             pat1 = <span class="stringliteral">&quot;%5d %3s: &quot;</span>;
<a name="l01258"></a>01258             pat2 = <span class="stringliteral">&quot;%5d-%3d: &quot;</span>;
<a name="l01259"></a>01259             <span class="keywordflow">break</span>;
<a name="l01260"></a>01260         <span class="keywordflow">case</span> 4:
<a name="l01261"></a>01261             pat1 = <span class="stringliteral">&quot;%6d %4s: &quot;</span>;
<a name="l01262"></a>01262             pat2 = <span class="stringliteral">&quot;%6d-%4d: &quot;</span>;
<a name="l01263"></a>01263             <span class="keywordflow">break</span>;
<a name="l01264"></a>01264         <span class="keywordflow">case</span> 5:
<a name="l01265"></a>01265             pat1 = <span class="stringliteral">&quot;%7d %5s: &quot;</span>;
<a name="l01266"></a>01266             pat2 = <span class="stringliteral">&quot;%7d-%5d: &quot;</span>;
<a name="l01267"></a>01267             <span class="keywordflow">break</span>;
<a name="l01268"></a>01268         <span class="keywordflow">case</span> 6:
<a name="l01269"></a>01269             pat1 = <span class="stringliteral">&quot;%8d %6s: &quot;</span>;
<a name="l01270"></a>01270             pat2 = <span class="stringliteral">&quot;%8d-%6d: &quot;</span>;
<a name="l01271"></a>01271             <span class="keywordflow">break</span>;
<a name="l01272"></a>01272         <span class="keywordflow">case</span> 7:
<a name="l01273"></a>01273             pat1 = <span class="stringliteral">&quot;%9d %7s: &quot;</span>;
<a name="l01274"></a>01274             pat2 = <span class="stringliteral">&quot;%9d-%7d: &quot;</span>;
<a name="l01275"></a>01275             <span class="keywordflow">break</span>;
<a name="l01276"></a>01276         <span class="keywordflow">default</span>:
<a name="l01277"></a>01277             pat1 = <span class="stringliteral">&quot;%12d %10s: &quot;</span>;
<a name="l01278"></a>01278             pat2 = <span class="stringliteral">&quot;%12d-%10d: &quot;</span>;
<a name="l01279"></a>01279             <span class="keywordflow">break</span>;
<a name="l01280"></a>01280     }
<a name="l01281"></a>01281 
<a name="l01282"></a>01282     <span class="keywordflow">for</span>(i=0; i&lt;buckets; i++)
<a name="l01283"></a>01283     {
<a name="l01284"></a>01284         <span class="keywordtype">int</span> len;
<a name="l01285"></a>01285         <span class="keywordtype">int</span> j;
<a name="l01286"></a>01286         <span class="keywordtype">float</span> pct;
<a name="l01287"></a>01287 
<a name="l01288"></a>01288         pct = 100.0 * (float)bucket[i].count / (<span class="keywordtype">float</span>)total;
<a name="l01289"></a>01289         len = HIST_BAR_MAX * bucket[i].count / scale;
<a name="l01290"></a>01290         <span class="keywordflow">if</span>(len &lt; 1)
<a name="l01291"></a>01291             len = 1;
<a name="l01292"></a>01292         assert(len &lt;= HIST_BAR_MAX);
<a name="l01293"></a>01293 
<a name="l01294"></a>01294         <span class="keywordflow">if</span>(bucket[i].low == bucket[i].high)
<a name="l01295"></a>01295             fprintf(stderr, pat1, bucket[i].low, <span class="stringliteral">&quot;&quot;</span>);
<a name="l01296"></a>01296         <span class="keywordflow">else</span>
<a name="l01297"></a>01297             fprintf(stderr, pat2, bucket[i].low, bucket[i].high);
<a name="l01298"></a>01298 
<a name="l01299"></a>01299         <span class="keywordflow">for</span>(j=0; j&lt;HIST_BAR_MAX; j++)
<a name="l01300"></a>01300             fprintf(stderr, j&lt;len?<span class="stringliteral">&quot;=&quot;</span>:<span class="stringliteral">&quot; &quot;</span>);
<a name="l01301"></a>01301         fprintf(stderr, <span class="stringliteral">&quot;\t%5d (%6.2f%%)\n&quot;</span>,bucket[i].count,pct);
<a name="l01302"></a>01302     }
<a name="l01303"></a>01303 }
<a name="l01304"></a>01304 
<a name="l01305"></a>01305 
<a name="l01306"></a>01306 <span class="keyword">static</span> <span class="keywordtype">void</span> show_q_histogram(<span class="keyword">const</span> <span class="keywordtype">int</span> counts[64], <span class="keywordtype">int</span> max_buckets)
<a name="l01307"></a>01307 {
<a name="l01308"></a>01308     <span class="keyword">struct </span>hist_bucket bucket[64];
<a name="l01309"></a>01309     <span class="keywordtype">int</span> buckets = 0;
<a name="l01310"></a>01310     <span class="keywordtype">int</span> total = 0;
<a name="l01311"></a>01311     <span class="keywordtype">int</span> scale;
<a name="l01312"></a>01312     <span class="keywordtype">int</span> i;
<a name="l01313"></a>01313 
<a name="l01314"></a>01314 
<a name="l01315"></a>01315     <span class="keywordflow">for</span>(i=0; i&lt;64; i++)
<a name="l01316"></a>01316     {
<a name="l01317"></a>01317         <span class="keywordflow">if</span>(counts[i])
<a name="l01318"></a>01318         {
<a name="l01319"></a>01319             bucket[buckets].low = bucket[buckets].high = i;
<a name="l01320"></a>01320             bucket[buckets].count = counts[i];
<a name="l01321"></a>01321             buckets++;
<a name="l01322"></a>01322             total += counts[i];
<a name="l01323"></a>01323         }
<a name="l01324"></a>01324     }
<a name="l01325"></a>01325 
<a name="l01326"></a>01326     fprintf(stderr, <span class="stringliteral">&quot;\nQuantizer Selection:\n&quot;</span>);
<a name="l01327"></a>01327     scale = merge_hist_buckets(bucket, &amp;buckets, max_buckets);
<a name="l01328"></a>01328     show_histogram(bucket, buckets, total, scale);
<a name="l01329"></a>01329 }
<a name="l01330"></a>01330 
<a name="l01331"></a>01331 
<a name="l01332"></a>01332 <span class="preprocessor">#define RATE_BINS (100)</span>
<a name="l01333"></a>01333 <span class="preprocessor"></span><span class="keyword">struct </span>rate_hist
<a name="l01334"></a>01334 {
<a name="l01335"></a>01335     int64_t            *pts;
<a name="l01336"></a>01336     <span class="keywordtype">int</span>                *sz;
<a name="l01337"></a>01337     <span class="keywordtype">int</span>                 samples;
<a name="l01338"></a>01338     <span class="keywordtype">int</span>                 frames;
<a name="l01339"></a>01339     <span class="keyword">struct </span>hist_bucket  bucket[RATE_BINS];
<a name="l01340"></a>01340     <span class="keywordtype">int</span>                 total;
<a name="l01341"></a>01341 };
<a name="l01342"></a>01342 
<a name="l01343"></a>01343 
<a name="l01344"></a>01344 <span class="keyword">static</span> <span class="keywordtype">void</span> init_rate_histogram(<span class="keyword">struct</span> rate_hist          *hist,
<a name="l01345"></a>01345                                 <span class="keyword">const</span> <a class="code" href="structvpx__codec__enc__cfg.html" title="Encoder configuration structure.">vpx_codec_enc_cfg_t</a> *cfg,
<a name="l01346"></a>01346                                 <span class="keyword">const</span> <a class="code" href="structvpx__rational.html" title="Rational Number.">vpx_rational_t</a>      *fps)
<a name="l01347"></a>01347 {
<a name="l01348"></a>01348     <span class="keywordtype">int</span> i;
<a name="l01349"></a>01349 
<a name="l01350"></a>01350     <span class="comment">/* Determine the number of samples in the buffer. Use the file&#39;s framerate</span>
<a name="l01351"></a>01351 <span class="comment">     * to determine the number of frames in rc_buf_sz milliseconds, with an</span>
<a name="l01352"></a>01352 <span class="comment">     * adjustment (5/4) to account for alt-refs</span>
<a name="l01353"></a>01353 <span class="comment">     */</span>
<a name="l01354"></a>01354     hist-&gt;samples = cfg-&gt;<a class="code" href="structvpx__codec__enc__cfg.html#a61866272bb588cd86d28834f420430f0" title="Decoder Buffer Size.">rc_buf_sz</a> * 5 / 4 * fps-&gt;<a class="code" href="structvpx__rational.html#ae7774f21a22c9bef3aa73156c79f4731">num</a> / fps-&gt;<a class="code" href="structvpx__rational.html#a29dd2ab4001377b3aa21885ef969759f">den</a> / 1000;
<a name="l01355"></a>01355 
<a name="l01356"></a>01356     <span class="comment">// prevent division by zero</span>
<a name="l01357"></a>01357     <span class="keywordflow">if</span> (hist-&gt;samples == 0)
<a name="l01358"></a>01358       hist-&gt;samples=1;
<a name="l01359"></a>01359 
<a name="l01360"></a>01360     hist-&gt;pts = calloc(hist-&gt;samples, <span class="keyword">sizeof</span>(*hist-&gt;pts));
<a name="l01361"></a>01361     hist-&gt;sz = calloc(hist-&gt;samples, <span class="keyword">sizeof</span>(*hist-&gt;sz));
<a name="l01362"></a>01362     <span class="keywordflow">for</span>(i=0; i&lt;RATE_BINS; i++)
<a name="l01363"></a>01363     {
<a name="l01364"></a>01364         hist-&gt;bucket[i].low = INT_MAX;
<a name="l01365"></a>01365         hist-&gt;bucket[i].high = 0;
<a name="l01366"></a>01366         hist-&gt;bucket[i].count = 0;
<a name="l01367"></a>01367     }
<a name="l01368"></a>01368 }
<a name="l01369"></a>01369 
<a name="l01370"></a>01370 
<a name="l01371"></a>01371 <span class="keyword">static</span> <span class="keywordtype">void</span> destroy_rate_histogram(<span class="keyword">struct</span> rate_hist *hist)
<a name="l01372"></a>01372 {
<a name="l01373"></a>01373     free(hist-&gt;pts);
<a name="l01374"></a>01374     free(hist-&gt;sz);
<a name="l01375"></a>01375 }
<a name="l01376"></a>01376 
<a name="l01377"></a>01377 
<a name="l01378"></a>01378 <span class="keyword">static</span> <span class="keywordtype">void</span> update_rate_histogram(<span class="keyword">struct</span> rate_hist          *hist,
<a name="l01379"></a>01379                                   <span class="keyword">const</span> <a class="code" href="structvpx__codec__enc__cfg.html" title="Encoder configuration structure.">vpx_codec_enc_cfg_t</a> *cfg,
<a name="l01380"></a>01380                                   <span class="keyword">const</span> <a class="code" href="structvpx__codec__cx__pkt.html" title="Encoder output packet.">vpx_codec_cx_pkt_t</a>  *pkt)
<a name="l01381"></a>01381 {
<a name="l01382"></a>01382     <span class="keywordtype">int</span> i, idx;
<a name="l01383"></a>01383     int64_t now, then, sum_sz = 0, avg_bitrate;
<a name="l01384"></a>01384 
<a name="l01385"></a>01385     now = pkt-&gt;<a class="code" href="structvpx__codec__cx__pkt.html#a7f97b060a23b7e89fe5b885c0074f696">data</a>.<a class="code" href="structvpx__codec__cx__pkt.html#a81e33bf4408a3983abb16492fee359ff">frame</a>.pts * 1000
<a name="l01386"></a>01386           * (uint64_t)cfg-&gt;<a class="code" href="structvpx__codec__enc__cfg.html#a6498d378e4c29ef3e22258289e481087" title="Stream timebase units.">g_timebase</a>.<a class="code" href="structvpx__rational.html#ae7774f21a22c9bef3aa73156c79f4731">num</a> / (uint64_t)cfg-&gt;<a class="code" href="structvpx__codec__enc__cfg.html#a6498d378e4c29ef3e22258289e481087" title="Stream timebase units.">g_timebase</a>.<a class="code" href="structvpx__rational.html#a29dd2ab4001377b3aa21885ef969759f">den</a>;
<a name="l01387"></a>01387 
<a name="l01388"></a>01388     idx = hist-&gt;frames++ % hist-&gt;samples;
<a name="l01389"></a>01389     hist-&gt;pts[idx] = now;
<a name="l01390"></a>01390     hist-&gt;sz[idx] = pkt-&gt;<a class="code" href="structvpx__codec__cx__pkt.html#a7f97b060a23b7e89fe5b885c0074f696">data</a>.<a class="code" href="structvpx__codec__cx__pkt.html#a81e33bf4408a3983abb16492fee359ff">frame</a>.sz;
<a name="l01391"></a>01391 
<a name="l01392"></a>01392     <span class="keywordflow">if</span>(now &lt; cfg-&gt;rc_buf_initial_sz)
<a name="l01393"></a>01393         <span class="keywordflow">return</span>;
<a name="l01394"></a>01394 
<a name="l01395"></a>01395     then = now;
<a name="l01396"></a>01396 
<a name="l01397"></a>01397     <span class="comment">/* Sum the size over the past rc_buf_sz ms */</span>
<a name="l01398"></a>01398     <span class="keywordflow">for</span>(i = hist-&gt;frames; i &gt; 0 &amp;&amp; hist-&gt;frames - i &lt; hist-&gt;samples; i--)
<a name="l01399"></a>01399     {
<a name="l01400"></a>01400         <span class="keywordtype">int</span> i_idx = (i-1) % hist-&gt;samples;
<a name="l01401"></a>01401 
<a name="l01402"></a>01402         then = hist-&gt;pts[i_idx];
<a name="l01403"></a>01403         <span class="keywordflow">if</span>(now - then &gt; cfg-&gt;<a class="code" href="structvpx__codec__enc__cfg.html#a61866272bb588cd86d28834f420430f0" title="Decoder Buffer Size.">rc_buf_sz</a>)
<a name="l01404"></a>01404             <span class="keywordflow">break</span>;
<a name="l01405"></a>01405         sum_sz += hist-&gt;sz[i_idx];
<a name="l01406"></a>01406     }
<a name="l01407"></a>01407 
<a name="l01408"></a>01408     <span class="keywordflow">if</span> (now == then)
<a name="l01409"></a>01409         <span class="keywordflow">return</span>;
<a name="l01410"></a>01410 
<a name="l01411"></a>01411     avg_bitrate = sum_sz * 8 * 1000 / (now - then);
<a name="l01412"></a>01412     idx = avg_bitrate * (RATE_BINS/2) / (cfg-&gt;<a class="code" href="structvpx__codec__enc__cfg.html#ab8339685175d66710f482706cc9f0aed" title="Target data rate.">rc_target_bitrate</a> * 1000);
<a name="l01413"></a>01413     <span class="keywordflow">if</span>(idx &lt; 0)
<a name="l01414"></a>01414         idx = 0;
<a name="l01415"></a>01415     <span class="keywordflow">if</span>(idx &gt; RATE_BINS-1)
<a name="l01416"></a>01416         idx = RATE_BINS-1;
<a name="l01417"></a>01417     <span class="keywordflow">if</span>(hist-&gt;bucket[idx].low &gt; avg_bitrate)
<a name="l01418"></a>01418         hist-&gt;bucket[idx].low = avg_bitrate;
<a name="l01419"></a>01419     <span class="keywordflow">if</span>(hist-&gt;bucket[idx].high &lt; avg_bitrate)
<a name="l01420"></a>01420         hist-&gt;bucket[idx].high = avg_bitrate;
<a name="l01421"></a>01421     hist-&gt;bucket[idx].count++;
<a name="l01422"></a>01422     hist-&gt;total++;
<a name="l01423"></a>01423 }
<a name="l01424"></a>01424 
<a name="l01425"></a>01425 
<a name="l01426"></a>01426 <span class="keyword">static</span> <span class="keywordtype">void</span> show_rate_histogram(<span class="keyword">struct</span> rate_hist          *hist,
<a name="l01427"></a>01427                                 <span class="keyword">const</span> <a class="code" href="structvpx__codec__enc__cfg.html" title="Encoder configuration structure.">vpx_codec_enc_cfg_t</a> *cfg,
<a name="l01428"></a>01428                                 <span class="keywordtype">int</span>                        max_buckets)
<a name="l01429"></a>01429 {
<a name="l01430"></a>01430     <span class="keywordtype">int</span> i, scale;
<a name="l01431"></a>01431     <span class="keywordtype">int</span> buckets = 0;
<a name="l01432"></a>01432 
<a name="l01433"></a>01433     <span class="keywordflow">for</span>(i = 0; i &lt; RATE_BINS; i++)
<a name="l01434"></a>01434     {
<a name="l01435"></a>01435         <span class="keywordflow">if</span>(hist-&gt;bucket[i].low == INT_MAX)
<a name="l01436"></a>01436             <span class="keywordflow">continue</span>;
<a name="l01437"></a>01437         hist-&gt;bucket[buckets++] = hist-&gt;bucket[i];
<a name="l01438"></a>01438     }
<a name="l01439"></a>01439 
<a name="l01440"></a>01440     fprintf(stderr, <span class="stringliteral">&quot;\nRate (over %dms window):\n&quot;</span>, cfg-&gt;<a class="code" href="structvpx__codec__enc__cfg.html#a61866272bb588cd86d28834f420430f0" title="Decoder Buffer Size.">rc_buf_sz</a>);
<a name="l01441"></a>01441     scale = merge_hist_buckets(hist-&gt;bucket, &amp;buckets, max_buckets);
<a name="l01442"></a>01442     show_histogram(hist-&gt;bucket, buckets, hist-&gt;total, scale);
<a name="l01443"></a>01443 }
<a name="l01444"></a>01444 
<a name="l01445"></a>01445 <span class="preprocessor">#define NELEMENTS(x) (sizeof(x)/sizeof(x[0]))</span>
<a name="l01446"></a>01446 <span class="preprocessor"></span><span class="preprocessor">#define ARG_CTRL_CNT_MAX NELEMENTS(vp8_arg_ctrl_map)</span>
<a name="l01447"></a>01447 <span class="preprocessor"></span>
<a name="l01448"></a>01448 <span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keyword">const</span> <span class="keywordtype">char</span> **argv_)
<a name="l01449"></a>01449 {
<a name="l01450"></a>01450     <a class="code" href="structvpx__codec__ctx.html" title="Codec context structure.">vpx_codec_ctx_t</a>        encoder;
<a name="l01451"></a>01451     <span class="keyword">const</span> <span class="keywordtype">char</span>                  *in_fn = NULL, *out_fn = NULL, *stats_fn = NULL;
<a name="l01452"></a>01452     <span class="keywordtype">int</span>                    i;
<a name="l01453"></a>01453     FILE                  *infile, *outfile;
<a name="l01454"></a>01454     <a class="code" href="structvpx__codec__enc__cfg.html" title="Encoder configuration structure.">vpx_codec_enc_cfg_t</a>    cfg;
<a name="l01455"></a>01455     <a class="code" href="group__codec.html#gada1084710837ad363b92f2379dd2b8d2" title="Algorithm return codes.">vpx_codec_err_t</a>        res;
<a name="l01456"></a>01456     <span class="keywordtype">int</span>                    pass, one_pass_only = 0;
<a name="l01457"></a>01457     stats_io_t             stats;
<a name="l01458"></a>01458     <a class="code" href="structvpx__image.html" title="Image Descriptor.">vpx_image_t</a>            raw;
<a name="l01459"></a>01459     <span class="keyword">const</span> <span class="keyword">struct </span>codec_item  *codec = codecs;
<a name="l01460"></a>01460     <span class="keywordtype">int</span>                    frame_avail, got_data;
<a name="l01461"></a>01461 
<a name="l01462"></a>01462     <span class="keyword">struct </span>arg               arg;
<a name="l01463"></a>01463     <span class="keywordtype">char</span>                   **argv, **argi, **argj;
<a name="l01464"></a>01464     <span class="keywordtype">int</span>                      arg_usage = 0, arg_passes = 1, arg_deadline = 0;
<a name="l01465"></a>01465     <span class="keywordtype">int</span>                      arg_ctrls[ARG_CTRL_CNT_MAX][2], arg_ctrl_cnt = 0;
<a name="l01466"></a>01466     <span class="keywordtype">int</span>                      arg_limit = 0;
<a name="l01467"></a>01467     <span class="keyword">static</span> <span class="keyword">const</span> arg_def_t **ctrl_args = no_args;
<a name="l01468"></a>01468     <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">int</span>        *ctrl_args_map = NULL;
<a name="l01469"></a>01469     <span class="keywordtype">int</span>                      verbose = 0, show_psnr = 0;
<a name="l01470"></a>01470     <span class="keywordtype">int</span>                      arg_use_i420 = 1;
<a name="l01471"></a>01471     <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>            cx_time = 0;
<a name="l01472"></a>01472     <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>             file_type, fourcc;
<a name="l01473"></a>01473     y4m_input                y4m;
<a name="l01474"></a>01474     <span class="keyword">struct </span><a class="code" href="structvpx__rational.html" title="Rational Number.">vpx_rational</a>      arg_framerate = {30, 1};
<a name="l01475"></a>01475     <span class="keywordtype">int</span>                      arg_have_framerate = 0;
<a name="l01476"></a>01476     <span class="keywordtype">int</span>                      write_webm = 1;
<a name="l01477"></a>01477     EbmlGlobal               ebml = {0};
<a name="l01478"></a>01478     uint32_t                 hash = 0;
<a name="l01479"></a>01479     uint64_t                 psnr_sse_total = 0;
<a name="l01480"></a>01480     uint64_t                 psnr_samples_total = 0;
<a name="l01481"></a>01481     <span class="keywordtype">double</span>                   psnr_totals[4] = {0, 0, 0, 0};
<a name="l01482"></a>01482     <span class="keywordtype">int</span>                      psnr_count = 0;
<a name="l01483"></a>01483     stereo_format_t          stereo_fmt = STEREO_FORMAT_MONO;
<a name="l01484"></a>01484     <span class="keywordtype">int</span>                      counts[64]={0};
<a name="l01485"></a>01485     <span class="keywordtype">int</span>                      show_q_hist_buckets=0;
<a name="l01486"></a>01486     <span class="keywordtype">int</span>                      show_rate_hist_buckets=0;
<a name="l01487"></a>01487     <span class="keyword">struct </span>rate_hist         rate_hist={0};
<a name="l01488"></a>01488 
<a name="l01489"></a>01489     exec_name = argv_[0];
<a name="l01490"></a>01490     ebml.last_pts_ms = -1;
<a name="l01491"></a>01491 
<a name="l01492"></a>01492     <span class="keywordflow">if</span> (argc &lt; 3)
<a name="l01493"></a>01493         usage_exit();
<a name="l01494"></a>01494 
<a name="l01495"></a>01495 
<a name="l01496"></a>01496     <span class="comment">/* First parse the codec and usage values, because we want to apply other</span>
<a name="l01497"></a>01497 <span class="comment">     * parameters on top of the default configuration provided by the codec.</span>
<a name="l01498"></a>01498 <span class="comment">     */</span>
<a name="l01499"></a>01499     argv = argv_dup(argc - 1, argv_ + 1);
<a name="l01500"></a>01500 
<a name="l01501"></a>01501     <span class="keywordflow">for</span> (argi = argj = argv; (*argj = *argi); argi += arg.argv_step)
<a name="l01502"></a>01502     {
<a name="l01503"></a>01503         arg.argv_step = 1;
<a name="l01504"></a>01504 
<a name="l01505"></a>01505         <span class="keywordflow">if</span> (arg_match(&amp;arg, &amp;codecarg, argi))
<a name="l01506"></a>01506         {
<a name="l01507"></a>01507             <span class="keywordtype">int</span> j, k = -1;
<a name="l01508"></a>01508 
<a name="l01509"></a>01509             <span class="keywordflow">for</span> (j = 0; j &lt; <span class="keyword">sizeof</span>(codecs) / <span class="keyword">sizeof</span>(codecs[0]); j++)
<a name="l01510"></a>01510                 <span class="keywordflow">if</span> (!strcmp(codecs[j].name, arg.val))
<a name="l01511"></a>01511                     k = j;
<a name="l01512"></a>01512 
<a name="l01513"></a>01513             <span class="keywordflow">if</span> (k &gt;= 0)
<a name="l01514"></a>01514                 codec = codecs + k;
<a name="l01515"></a>01515             <span class="keywordflow">else</span>
<a name="l01516"></a>01516                 die(<span class="stringliteral">&quot;Error: Unrecognized argument (%s) to --codec\n&quot;</span>,
<a name="l01517"></a>01517                     arg.val);
<a name="l01518"></a>01518 
<a name="l01519"></a>01519         }
<a name="l01520"></a>01520         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (arg_match(&amp;arg, &amp;passes, argi))
<a name="l01521"></a>01521         {
<a name="l01522"></a>01522             arg_passes = arg_parse_uint(&amp;arg);
<a name="l01523"></a>01523 
<a name="l01524"></a>01524             <span class="keywordflow">if</span> (arg_passes &lt; 1 || arg_passes &gt; 2)
<a name="l01525"></a>01525                 die(<span class="stringliteral">&quot;Error: Invalid number of passes (%d)\n&quot;</span>, arg_passes);
<a name="l01526"></a>01526         }
<a name="l01527"></a>01527         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (arg_match(&amp;arg, &amp;pass_arg, argi))
<a name="l01528"></a>01528         {
<a name="l01529"></a>01529             one_pass_only = arg_parse_uint(&amp;arg);
<a name="l01530"></a>01530 
<a name="l01531"></a>01531             <span class="keywordflow">if</span> (one_pass_only &lt; 1 || one_pass_only &gt; 2)
<a name="l01532"></a>01532                 die(<span class="stringliteral">&quot;Error: Invalid pass selected (%d)\n&quot;</span>, one_pass_only);
<a name="l01533"></a>01533         }
<a name="l01534"></a>01534         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (arg_match(&amp;arg, &amp;fpf_name, argi))
<a name="l01535"></a>01535             stats_fn = arg.val;
<a name="l01536"></a>01536         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (arg_match(&amp;arg, &amp;usage, argi))
<a name="l01537"></a>01537             arg_usage = arg_parse_uint(&amp;arg);
<a name="l01538"></a>01538         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (arg_match(&amp;arg, &amp;deadline, argi))
<a name="l01539"></a>01539             arg_deadline = arg_parse_uint(&amp;arg);
<a name="l01540"></a>01540         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (arg_match(&amp;arg, &amp;best_dl, argi))
<a name="l01541"></a>01541             arg_deadline = <a class="code" href="group__encoder.html#gab350573bea112f2fdf8e5677db3ac0da">VPX_DL_BEST_QUALITY</a>;
<a name="l01542"></a>01542         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (arg_match(&amp;arg, &amp;good_dl, argi))
<a name="l01543"></a>01543             arg_deadline = <a class="code" href="group__encoder.html#ga5d00a9f9e10b9f49ca91e72c1f01c9fd">VPX_DL_GOOD_QUALITY</a>;
<a name="l01544"></a>01544         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (arg_match(&amp;arg, &amp;rt_dl, argi))
<a name="l01545"></a>01545             arg_deadline = <a class="code" href="group__encoder.html#ga04253cc9ec1146d72fa8bb86bcf32144">VPX_DL_REALTIME</a>;
<a name="l01546"></a>01546         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (arg_match(&amp;arg, &amp;use_yv12, argi))
<a name="l01547"></a>01547         {
<a name="l01548"></a>01548             arg_use_i420 = 0;
<a name="l01549"></a>01549         }
<a name="l01550"></a>01550         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (arg_match(&amp;arg, &amp;use_i420, argi))
<a name="l01551"></a>01551         {
<a name="l01552"></a>01552             arg_use_i420 = 1;
<a name="l01553"></a>01553         }
<a name="l01554"></a>01554         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (arg_match(&amp;arg, &amp;verbosearg, argi))
<a name="l01555"></a>01555             verbose = 1;
<a name="l01556"></a>01556         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (arg_match(&amp;arg, &amp;limit, argi))
<a name="l01557"></a>01557             arg_limit = arg_parse_uint(&amp;arg);
<a name="l01558"></a>01558         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (arg_match(&amp;arg, &amp;psnrarg, argi))
<a name="l01559"></a>01559             show_psnr = 1;
<a name="l01560"></a>01560         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (arg_match(&amp;arg, &amp;framerate, argi))
<a name="l01561"></a>01561         {
<a name="l01562"></a>01562             arg_framerate = arg_parse_rational(&amp;arg);
<a name="l01563"></a>01563             arg_have_framerate = 1;
<a name="l01564"></a>01564         }
<a name="l01565"></a>01565         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (arg_match(&amp;arg, &amp;use_ivf, argi))
<a name="l01566"></a>01566             write_webm = 0;
<a name="l01567"></a>01567         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (arg_match(&amp;arg, &amp;outputfile, argi))
<a name="l01568"></a>01568             out_fn = arg.val;
<a name="l01569"></a>01569         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (arg_match(&amp;arg, &amp;debugmode, argi))
<a name="l01570"></a>01570             ebml.debug = 1;
<a name="l01571"></a>01571         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (arg_match(&amp;arg, &amp;q_hist_n, argi))
<a name="l01572"></a>01572             show_q_hist_buckets = arg_parse_uint(&amp;arg);
<a name="l01573"></a>01573         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (arg_match(&amp;arg, &amp;rate_hist_n, argi))
<a name="l01574"></a>01574             show_rate_hist_buckets = arg_parse_uint(&amp;arg);
<a name="l01575"></a>01575         <span class="keywordflow">else</span>
<a name="l01576"></a>01576             argj++;
<a name="l01577"></a>01577     }
<a name="l01578"></a>01578 
<a name="l01579"></a>01579     <span class="comment">/* Ensure that --passes and --pass are consistent. If --pass is set and --passes=2,</span>
<a name="l01580"></a>01580 <span class="comment">     * ensure --fpf was set.</span>
<a name="l01581"></a>01581 <span class="comment">     */</span>
<a name="l01582"></a>01582     <span class="keywordflow">if</span> (one_pass_only)
<a name="l01583"></a>01583     {
<a name="l01584"></a>01584         <span class="comment">/* DWIM: Assume the user meant passes=2 if pass=2 is specified */</span>
<a name="l01585"></a>01585         <span class="keywordflow">if</span> (one_pass_only &gt; arg_passes)
<a name="l01586"></a>01586         {
<a name="l01587"></a>01587             fprintf(stderr, <span class="stringliteral">&quot;Warning: Assuming --pass=%d implies --passes=%d\n&quot;</span>,
<a name="l01588"></a>01588                    one_pass_only, one_pass_only);
<a name="l01589"></a>01589             arg_passes = one_pass_only;
<a name="l01590"></a>01590         }
<a name="l01591"></a>01591 
<a name="l01592"></a>01592         <span class="keywordflow">if</span> (arg_passes == 2 &amp;&amp; !stats_fn)
<a name="l01593"></a>01593             die(<span class="stringliteral">&quot;Must specify --fpf when --pass=%d and --passes=2\n&quot;</span>, one_pass_only);
<a name="l01594"></a>01594     }
<a name="l01595"></a>01595 
<a name="l01596"></a>01596     <span class="comment">/* Populate encoder configuration */</span>
<a name="l01597"></a>01597     res = <a class="code" href="group__encoder.html#ga9ab8c79623312e9c5d5405d66a788f59" title="Get a default configuration.">vpx_codec_enc_config_default</a>(codec-&gt;iface, &amp;cfg, arg_usage);
<a name="l01598"></a>01598 
<a name="l01599"></a>01599     <span class="keywordflow">if</span> (res)
<a name="l01600"></a>01600     {
<a name="l01601"></a>01601         fprintf(stderr, <span class="stringliteral">&quot;Failed to get config: %s\n&quot;</span>,
<a name="l01602"></a>01602                 <a class="code" href="group__codec.html#gaaddf5c1f609ef18c7c8800d102fcefa6" title="Convert error number to printable string.">vpx_codec_err_to_string</a>(res));
<a name="l01603"></a>01603         <span class="keywordflow">return</span> EXIT_FAILURE;
<a name="l01604"></a>01604     }
<a name="l01605"></a>01605 
<a name="l01606"></a>01606     <span class="comment">/* Change the default timebase to a high enough value so that the encoder</span>
<a name="l01607"></a>01607 <span class="comment">     * will always create strictly increasing timestamps.</span>
<a name="l01608"></a>01608 <span class="comment">     */</span>
<a name="l01609"></a>01609     cfg.<a class="code" href="structvpx__codec__enc__cfg.html#a6498d378e4c29ef3e22258289e481087" title="Stream timebase units.">g_timebase</a>.<a class="code" href="structvpx__rational.html#a29dd2ab4001377b3aa21885ef969759f">den</a> = 1000;
<a name="l01610"></a>01610 
<a name="l01611"></a>01611     <span class="comment">/* Never use the library&#39;s default resolution, require it be parsed</span>
<a name="l01612"></a>01612 <span class="comment">     * from the file or set on the command line.</span>
<a name="l01613"></a>01613 <span class="comment">     */</span>
<a name="l01614"></a>01614     cfg.<a class="code" href="structvpx__codec__enc__cfg.html#a5c165f5b41ca1158f2883983a2b7709c" title="Width of the frame.">g_w</a> = 0;
<a name="l01615"></a>01615     cfg.<a class="code" href="structvpx__codec__enc__cfg.html#a4132bd89ce85bce7c08f2cc3b6f2b82e" title="Height of the frame.">g_h</a> = 0;
<a name="l01616"></a>01616 
<a name="l01617"></a>01617     <span class="comment">/* Now parse the remainder of the parameters. */</span>
<a name="l01618"></a>01618     <span class="keywordflow">for</span> (argi = argj = argv; (*argj = *argi); argi += arg.argv_step)
<a name="l01619"></a>01619     {
<a name="l01620"></a>01620         arg.argv_step = 1;
<a name="l01621"></a>01621 
<a name="l01622"></a>01622         <span class="keywordflow">if</span> (0);
<a name="l01623"></a>01623         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (arg_match(&amp;arg, &amp;threads, argi))
<a name="l01624"></a>01624             cfg.<a class="code" href="structvpx__codec__enc__cfg.html#aff9d8d458c45c95dd542603210ba2b8b" title="Maximum number of threads to use.">g_threads</a> = arg_parse_uint(&amp;arg);
<a name="l01625"></a>01625         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (arg_match(&amp;arg, &amp;profile, argi))
<a name="l01626"></a>01626             cfg.<a class="code" href="structvpx__codec__enc__cfg.html#a3d7fe3a8b237338c094d5a956a41804d" title="Bitstream profile to use.">g_profile</a> = arg_parse_uint(&amp;arg);
<a name="l01627"></a>01627         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (arg_match(&amp;arg, &amp;width, argi))
<a name="l01628"></a>01628             cfg.<a class="code" href="structvpx__codec__enc__cfg.html#a5c165f5b41ca1158f2883983a2b7709c" title="Width of the frame.">g_w</a> = arg_parse_uint(&amp;arg);
<a name="l01629"></a>01629         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (arg_match(&amp;arg, &amp;height, argi))
<a name="l01630"></a>01630             cfg.<a class="code" href="structvpx__codec__enc__cfg.html#a4132bd89ce85bce7c08f2cc3b6f2b82e" title="Height of the frame.">g_h</a> = arg_parse_uint(&amp;arg);
<a name="l01631"></a>01631         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (arg_match(&amp;arg, &amp;stereo_mode, argi))
<a name="l01632"></a>01632             stereo_fmt = arg_parse_enum_or_int(&amp;arg);
<a name="l01633"></a>01633         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (arg_match(&amp;arg, &amp;timebase, argi))
<a name="l01634"></a>01634             cfg.<a class="code" href="structvpx__codec__enc__cfg.html#a6498d378e4c29ef3e22258289e481087" title="Stream timebase units.">g_timebase</a> = arg_parse_rational(&amp;arg);
<a name="l01635"></a>01635         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (arg_match(&amp;arg, &amp;error_resilient, argi))
<a name="l01636"></a>01636             cfg.<a class="code" href="structvpx__codec__enc__cfg.html#a4e17173b66ca0d7dfba9978625d7ba76" title="Enable error resilient modes.">g_error_resilient</a> = arg_parse_uint(&amp;arg);
<a name="l01637"></a>01637         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (arg_match(&amp;arg, &amp;lag_in_frames, argi))
<a name="l01638"></a>01638             cfg.<a class="code" href="structvpx__codec__enc__cfg.html#a992668d9e30305f3f7ab2672ea31a890" title="Allow lagged encoding.">g_lag_in_frames</a> = arg_parse_uint(&amp;arg);
<a name="l01639"></a>01639         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (arg_match(&amp;arg, &amp;dropframe_thresh, argi))
<a name="l01640"></a>01640             cfg.<a class="code" href="structvpx__codec__enc__cfg.html#a619269f9a6904de58c4790e6806a3905" title="Temporal resampling configuration, if supported by the codec.">rc_dropframe_thresh</a> = arg_parse_uint(&amp;arg);
<a name="l01641"></a>01641         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (arg_match(&amp;arg, &amp;resize_allowed, argi))
<a name="l01642"></a>01642             cfg.<a class="code" href="structvpx__codec__enc__cfg.html#a02a4e2f18fb0fdfff44df8b0d9a99d6c" title="Enable/disable spatial resampling, if supported by the codec.">rc_resize_allowed</a> = arg_parse_uint(&amp;arg);
<a name="l01643"></a>01643         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (arg_match(&amp;arg, &amp;resize_up_thresh, argi))
<a name="l01644"></a>01644             cfg.<a class="code" href="structvpx__codec__enc__cfg.html#a855599c0660f31dfcab4a64996b4f6ad" title="Spatial resampling up watermark.">rc_resize_up_thresh</a> = arg_parse_uint(&amp;arg);
<a name="l01645"></a>01645         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (arg_match(&amp;arg, &amp;resize_down_thresh, argi))
<a name="l01646"></a>01646             cfg.<a class="code" href="structvpx__codec__enc__cfg.html#a1be7bd7b0eaf1e99b5e4028c37c65488" title="Spatial resampling down watermark.">rc_resize_down_thresh</a> = arg_parse_uint(&amp;arg);
<a name="l01647"></a>01647         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (arg_match(&amp;arg, &amp;end_usage, argi))
<a name="l01648"></a>01648             cfg.<a class="code" href="structvpx__codec__enc__cfg.html#a99c415edb6c6f909a095a57c3430a116" title="Rate control algorithm to use.">rc_end_usage</a> = arg_parse_enum_or_int(&amp;arg);
<a name="l01649"></a>01649         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (arg_match(&amp;arg, &amp;target_bitrate, argi))
<a name="l01650"></a>01650             cfg.<a class="code" href="structvpx__codec__enc__cfg.html#ab8339685175d66710f482706cc9f0aed" title="Target data rate.">rc_target_bitrate</a> = arg_parse_uint(&amp;arg);
<a name="l01651"></a>01651         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (arg_match(&amp;arg, &amp;min_quantizer, argi))
<a name="l01652"></a>01652             cfg.<a class="code" href="structvpx__codec__enc__cfg.html#a1324600e3c63faaa7717e85cf6509dd9" title="Minimum (Best Quality) Quantizer.">rc_min_quantizer</a> = arg_parse_uint(&amp;arg);
<a name="l01653"></a>01653         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (arg_match(&amp;arg, &amp;max_quantizer, argi))
<a name="l01654"></a>01654             cfg.<a class="code" href="structvpx__codec__enc__cfg.html#a8abdd985d317b720e142335887d737df" title="Maximum (Worst Quality) Quantizer.">rc_max_quantizer</a> = arg_parse_uint(&amp;arg);
<a name="l01655"></a>01655         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (arg_match(&amp;arg, &amp;undershoot_pct, argi))
<a name="l01656"></a>01656             cfg.<a class="code" href="structvpx__codec__enc__cfg.html#ad279fbb0a9fe9395340913161e28651a" title="Rate control adaptation undershoot control.">rc_undershoot_pct</a> = arg_parse_uint(&amp;arg);
<a name="l01657"></a>01657         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (arg_match(&amp;arg, &amp;overshoot_pct, argi))
<a name="l01658"></a>01658             cfg.<a class="code" href="structvpx__codec__enc__cfg.html#a4f2fbd015c1b1f395cc4a4b03d4ead5f" title="Rate control adaptation overshoot control.">rc_overshoot_pct</a> = arg_parse_uint(&amp;arg);
<a name="l01659"></a>01659         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (arg_match(&amp;arg, &amp;buf_sz, argi))
<a name="l01660"></a>01660             cfg.<a class="code" href="structvpx__codec__enc__cfg.html#a61866272bb588cd86d28834f420430f0" title="Decoder Buffer Size.">rc_buf_sz</a> = arg_parse_uint(&amp;arg);
<a name="l01661"></a>01661         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (arg_match(&amp;arg, &amp;buf_initial_sz, argi))
<a name="l01662"></a>01662             cfg.<a class="code" href="structvpx__codec__enc__cfg.html#aa9e4d6405994ef42d61d478cf6e0d5e0" title="Decoder Buffer Initial Size.">rc_buf_initial_sz</a> = arg_parse_uint(&amp;arg);
<a name="l01663"></a>01663         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (arg_match(&amp;arg, &amp;buf_optimal_sz, argi))
<a name="l01664"></a>01664             cfg.<a class="code" href="structvpx__codec__enc__cfg.html#aafde485867e040a58504ad796e79e47f" title="Decoder Buffer Optimal Size.">rc_buf_optimal_sz</a> = arg_parse_uint(&amp;arg);
<a name="l01665"></a>01665         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (arg_match(&amp;arg, &amp;bias_pct, argi))
<a name="l01666"></a>01666         {
<a name="l01667"></a>01667             cfg.<a class="code" href="structvpx__codec__enc__cfg.html#a21c21ff097890dc3a450731c9b504cf4" title="Two-pass mode CBR/VBR bias.">rc_2pass_vbr_bias_pct</a> = arg_parse_uint(&amp;arg);
<a name="l01668"></a>01668 
<a name="l01669"></a>01669             <span class="keywordflow">if</span> (arg_passes &lt; 2)
<a name="l01670"></a>01670                 fprintf(stderr,
<a name="l01671"></a>01671                         <span class="stringliteral">&quot;Warning: option %s ignored in one-pass mode.\n&quot;</span>,
<a name="l01672"></a>01672                         arg.name);
<a name="l01673"></a>01673         }
<a name="l01674"></a>01674         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (arg_match(&amp;arg, &amp;minsection_pct, argi))
<a name="l01675"></a>01675         {
<a name="l01676"></a>01676             cfg.<a class="code" href="structvpx__codec__enc__cfg.html#a21eb9fce0844ae07b617bf3f0a25f5a5" title="Two-pass mode per-GOP minimum bitrate.">rc_2pass_vbr_minsection_pct</a> = arg_parse_uint(&amp;arg);
<a name="l01677"></a>01677 
<a name="l01678"></a>01678             <span class="keywordflow">if</span> (arg_passes &lt; 2)
<a name="l01679"></a>01679                 fprintf(stderr,
<a name="l01680"></a>01680                         <span class="stringliteral">&quot;Warning: option %s ignored in one-pass mode.\n&quot;</span>,
<a name="l01681"></a>01681                         arg.name);
<a name="l01682"></a>01682         }
<a name="l01683"></a>01683         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (arg_match(&amp;arg, &amp;maxsection_pct, argi))
<a name="l01684"></a>01684         {
<a name="l01685"></a>01685             cfg.<a class="code" href="structvpx__codec__enc__cfg.html#ab5212050b71b2d9f4dc663caa496949e" title="Two-pass mode per-GOP maximum bitrate.">rc_2pass_vbr_maxsection_pct</a> = arg_parse_uint(&amp;arg);
<a name="l01686"></a>01686 
<a name="l01687"></a>01687             <span class="keywordflow">if</span> (arg_passes &lt; 2)
<a name="l01688"></a>01688                 fprintf(stderr,
<a name="l01689"></a>01689                         <span class="stringliteral">&quot;Warning: option %s ignored in one-pass mode.\n&quot;</span>,
<a name="l01690"></a>01690                         arg.name);
<a name="l01691"></a>01691         }
<a name="l01692"></a>01692         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (arg_match(&amp;arg, &amp;kf_min_dist, argi))
<a name="l01693"></a>01693             cfg.<a class="code" href="structvpx__codec__enc__cfg.html#a0a7b5444ecb09745cbe8d5af17553846" title="Keyframe minimum interval.">kf_min_dist</a> = arg_parse_uint(&amp;arg);
<a name="l01694"></a>01694         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (arg_match(&amp;arg, &amp;kf_max_dist, argi))
<a name="l01695"></a>01695             cfg.<a class="code" href="structvpx__codec__enc__cfg.html#ae018440136e271743376730413d25a9b" title="Keyframe maximum interval.">kf_max_dist</a> = arg_parse_uint(&amp;arg);
<a name="l01696"></a>01696         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (arg_match(&amp;arg, &amp;kf_disabled, argi))
<a name="l01697"></a>01697             cfg.<a class="code" href="structvpx__codec__enc__cfg.html#a491d67f061dcdb13f60c017563e9d788" title="Keyframe placement mode.">kf_mode</a> = <a class="code" href="group__encoder.html#gga9f461802aa4db35c04a8b23837987f40a56513f60cbf3434ca0092173005d0ab2">VPX_KF_DISABLED</a>;
<a name="l01698"></a>01698         <span class="keywordflow">else</span>
<a name="l01699"></a>01699             argj++;
<a name="l01700"></a>01700     }
<a name="l01701"></a>01701 
<a name="l01702"></a>01702     <span class="comment">/* Handle codec specific options */</span>
<a name="l01703"></a>01703 <span class="preprocessor">#if CONFIG_VP8_ENCODER</span>
<a name="l01704"></a>01704 <span class="preprocessor"></span>
<a name="l01705"></a>01705     <span class="keywordflow">if</span> (codec-&gt;iface == &amp;vpx_codec_vp8_cx_algo)
<a name="l01706"></a>01706     {
<a name="l01707"></a>01707         ctrl_args = vp8_args;
<a name="l01708"></a>01708         ctrl_args_map = vp8_arg_ctrl_map;
<a name="l01709"></a>01709     }
<a name="l01710"></a>01710 
<a name="l01711"></a>01711 <span class="preprocessor">#endif</span>
<a name="l01712"></a>01712 <span class="preprocessor"></span>
<a name="l01713"></a>01713     <span class="keywordflow">for</span> (argi = argj = argv; (*argj = *argi); argi += arg.argv_step)
<a name="l01714"></a>01714     {
<a name="l01715"></a>01715         <span class="keywordtype">int</span> match = 0;
<a name="l01716"></a>01716 
<a name="l01717"></a>01717         arg.argv_step = 1;
<a name="l01718"></a>01718 
<a name="l01719"></a>01719         <span class="keywordflow">for</span> (i = 0; ctrl_args[i]; i++)
<a name="l01720"></a>01720         {
<a name="l01721"></a>01721             <span class="keywordflow">if</span> (arg_match(&amp;arg, ctrl_args[i], argi))
<a name="l01722"></a>01722             {
<a name="l01723"></a>01723                 <span class="keywordtype">int</span> j;
<a name="l01724"></a>01724                 match = 1;
<a name="l01725"></a>01725 
<a name="l01726"></a>01726                 <span class="comment">/* Point either to the next free element or the first</span>
<a name="l01727"></a>01727 <span class="comment">                * instance of this control.</span>
<a name="l01728"></a>01728 <span class="comment">                */</span>
<a name="l01729"></a>01729                 <span class="keywordflow">for</span>(j=0; j&lt;arg_ctrl_cnt; j++)
<a name="l01730"></a>01730                     <span class="keywordflow">if</span>(arg_ctrls[j][0] == ctrl_args_map[i])
<a name="l01731"></a>01731                         <span class="keywordflow">break</span>;
<a name="l01732"></a>01732 
<a name="l01733"></a>01733                 <span class="comment">/* Update/insert */</span>
<a name="l01734"></a>01734                 assert(j &lt; ARG_CTRL_CNT_MAX);
<a name="l01735"></a>01735                 <span class="keywordflow">if</span> (j &lt; ARG_CTRL_CNT_MAX)
<a name="l01736"></a>01736                 {
<a name="l01737"></a>01737                     arg_ctrls[j][0] = ctrl_args_map[i];
<a name="l01738"></a>01738                     arg_ctrls[j][1] = arg_parse_enum_or_int(&amp;arg);
<a name="l01739"></a>01739                     <span class="keywordflow">if</span>(j == arg_ctrl_cnt)
<a name="l01740"></a>01740                         arg_ctrl_cnt++;
<a name="l01741"></a>01741                 }
<a name="l01742"></a>01742 
<a name="l01743"></a>01743             }
<a name="l01744"></a>01744         }
<a name="l01745"></a>01745 
<a name="l01746"></a>01746         <span class="keywordflow">if</span> (!match)
<a name="l01747"></a>01747             argj++;
<a name="l01748"></a>01748     }
<a name="l01749"></a>01749 
<a name="l01750"></a>01750     <span class="comment">/* Check for unrecognized options */</span>
<a name="l01751"></a>01751     <span class="keywordflow">for</span> (argi = argv; *argi; argi++)
<a name="l01752"></a>01752         <span class="keywordflow">if</span> (argi[0][0] == <span class="charliteral">&#39;-&#39;</span> &amp;&amp; argi[0][1])
<a name="l01753"></a>01753             die(<span class="stringliteral">&quot;Error: Unrecognized option %s\n&quot;</span>, *argi);
<a name="l01754"></a>01754 
<a name="l01755"></a>01755     <span class="comment">/* Handle non-option arguments */</span>
<a name="l01756"></a>01756     in_fn = argv[0];
<a name="l01757"></a>01757 
<a name="l01758"></a>01758     <span class="keywordflow">if</span> (!in_fn)
<a name="l01759"></a>01759         usage_exit();
<a name="l01760"></a>01760 
<a name="l01761"></a>01761     <span class="keywordflow">if</span>(!out_fn)
<a name="l01762"></a>01762         die(<span class="stringliteral">&quot;Error: Output file is required (specify with -o)\n&quot;</span>);
<a name="l01763"></a>01763 
<a name="l01764"></a>01764     memset(&amp;stats, 0, <span class="keyword">sizeof</span>(stats));
<a name="l01765"></a>01765 
<a name="l01766"></a>01766     <span class="keywordflow">for</span> (pass = one_pass_only ? one_pass_only - 1 : 0; pass &lt; arg_passes; pass++)
<a name="l01767"></a>01767     {
<a name="l01768"></a>01768         <span class="keywordtype">int</span> frames_in = 0, frames_out = 0;
<a name="l01769"></a>01769         int64_t nbytes = 0;
<a name="l01770"></a>01770         <span class="keyword">struct </span>detect_buffer detect;
<a name="l01771"></a>01771 
<a name="l01772"></a>01772         <span class="comment">/* Parse certain options from the input file, if possible */</span>
<a name="l01773"></a>01773         infile = strcmp(in_fn, <span class="stringliteral">&quot;-&quot;</span>) ? fopen(in_fn, <span class="stringliteral">&quot;rb&quot;</span>)
<a name="l01774"></a>01774                                     : set_binary_mode(stdin);
<a name="l01775"></a>01775 
<a name="l01776"></a>01776         <span class="keywordflow">if</span> (!infile)
<a name="l01777"></a>01777         {
<a name="l01778"></a>01778             fprintf(stderr, <span class="stringliteral">&quot;Failed to open input file\n&quot;</span>);
<a name="l01779"></a>01779             <span class="keywordflow">return</span> EXIT_FAILURE;
<a name="l01780"></a>01780         }
<a name="l01781"></a>01781 
<a name="l01782"></a>01782         <span class="comment">/* For RAW input sources, these bytes will applied on the first frame</span>
<a name="l01783"></a>01783 <span class="comment">         *  in read_frame().</span>
<a name="l01784"></a>01784 <span class="comment">         */</span>
<a name="l01785"></a>01785         detect.buf_read = fread(detect.buf, 1, 4, infile);
<a name="l01786"></a>01786         detect.position = 0;
<a name="l01787"></a>01787 
<a name="l01788"></a>01788         <span class="keywordflow">if</span> (detect.buf_read == 4 &amp;&amp; file_is_y4m(infile, &amp;y4m, detect.buf))
<a name="l01789"></a>01789         {
<a name="l01790"></a>01790             <span class="keywordflow">if</span> (y4m_input_open(&amp;y4m, infile, detect.buf, 4) &gt;= 0)
<a name="l01791"></a>01791             {
<a name="l01792"></a>01792                 file_type = FILE_TYPE_Y4M;
<a name="l01793"></a>01793                 cfg.<a class="code" href="structvpx__codec__enc__cfg.html#a5c165f5b41ca1158f2883983a2b7709c" title="Width of the frame.">g_w</a> = y4m.pic_w;
<a name="l01794"></a>01794                 cfg.<a class="code" href="structvpx__codec__enc__cfg.html#a4132bd89ce85bce7c08f2cc3b6f2b82e" title="Height of the frame.">g_h</a> = y4m.pic_h;
<a name="l01795"></a>01795 
<a name="l01796"></a>01796                 <span class="comment">/* Use the frame rate from the file only if none was specified</span>
<a name="l01797"></a>01797 <span class="comment">                 * on the command-line.</span>
<a name="l01798"></a>01798 <span class="comment">                 */</span>
<a name="l01799"></a>01799                 <span class="keywordflow">if</span> (!arg_have_framerate)
<a name="l01800"></a>01800                 {
<a name="l01801"></a>01801                     arg_framerate.<a class="code" href="structvpx__rational.html#ae7774f21a22c9bef3aa73156c79f4731">num</a> = y4m.fps_n;
<a name="l01802"></a>01802                     arg_framerate.<a class="code" href="structvpx__rational.html#a29dd2ab4001377b3aa21885ef969759f">den</a> = y4m.fps_d;
<a name="l01803"></a>01803                 }
<a name="l01804"></a>01804 
<a name="l01805"></a>01805                 arg_use_i420 = 0;
<a name="l01806"></a>01806             }
<a name="l01807"></a>01807             <span class="keywordflow">else</span>
<a name="l01808"></a>01808             {
<a name="l01809"></a>01809                 fprintf(stderr, <span class="stringliteral">&quot;Unsupported Y4M stream.\n&quot;</span>);
<a name="l01810"></a>01810                 <span class="keywordflow">return</span> EXIT_FAILURE;
<a name="l01811"></a>01811             }
<a name="l01812"></a>01812         }
<a name="l01813"></a>01813         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (detect.buf_read == 4 &amp;&amp;
<a name="l01814"></a>01814                  file_is_ivf(infile, &amp;fourcc, &amp;cfg.<a class="code" href="structvpx__codec__enc__cfg.html#a5c165f5b41ca1158f2883983a2b7709c" title="Width of the frame.">g_w</a>, &amp;cfg.<a class="code" href="structvpx__codec__enc__cfg.html#a4132bd89ce85bce7c08f2cc3b6f2b82e" title="Height of the frame.">g_h</a>, &amp;detect))
<a name="l01815"></a>01815         {
<a name="l01816"></a>01816             file_type = FILE_TYPE_IVF;
<a name="l01817"></a>01817             <span class="keywordflow">switch</span> (fourcc)
<a name="l01818"></a>01818             {
<a name="l01819"></a>01819             <span class="keywordflow">case</span> 0x32315659:
<a name="l01820"></a>01820                 arg_use_i420 = 0;
<a name="l01821"></a>01821                 <span class="keywordflow">break</span>;
<a name="l01822"></a>01822             <span class="keywordflow">case</span> 0x30323449:
<a name="l01823"></a>01823                 arg_use_i420 = 1;
<a name="l01824"></a>01824                 <span class="keywordflow">break</span>;
<a name="l01825"></a>01825             <span class="keywordflow">default</span>:
<a name="l01826"></a>01826                 fprintf(stderr, <span class="stringliteral">&quot;Unsupported fourcc (%08x) in IVF\n&quot;</span>, fourcc);
<a name="l01827"></a>01827                 <span class="keywordflow">return</span> EXIT_FAILURE;
<a name="l01828"></a>01828             }
<a name="l01829"></a>01829         }
<a name="l01830"></a>01830         <span class="keywordflow">else</span>
<a name="l01831"></a>01831         {
<a name="l01832"></a>01832             file_type = FILE_TYPE_RAW;
<a name="l01833"></a>01833         }
<a name="l01834"></a>01834 
<a name="l01835"></a>01835         <span class="keywordflow">if</span>(!cfg.<a class="code" href="structvpx__codec__enc__cfg.html#a5c165f5b41ca1158f2883983a2b7709c" title="Width of the frame.">g_w</a> || !cfg.<a class="code" href="structvpx__codec__enc__cfg.html#a4132bd89ce85bce7c08f2cc3b6f2b82e" title="Height of the frame.">g_h</a>)
<a name="l01836"></a>01836         {
<a name="l01837"></a>01837             fprintf(stderr, <span class="stringliteral">&quot;Specify stream dimensions with --width (-w) &quot;</span>
<a name="l01838"></a>01838                             <span class="stringliteral">&quot; and --height (-h).\n&quot;</span>);
<a name="l01839"></a>01839             <span class="keywordflow">return</span> EXIT_FAILURE;
<a name="l01840"></a>01840         }
<a name="l01841"></a>01841 
<a name="l01842"></a>01842 <span class="preprocessor">#define SHOW(field) fprintf(stderr, &quot;    %-28s = %d\n&quot;, #field, cfg.field)</span>
<a name="l01843"></a>01843 <span class="preprocessor"></span>
<a name="l01844"></a>01844         <span class="keywordflow">if</span> (verbose &amp;&amp; pass == 0)
<a name="l01845"></a>01845         {
<a name="l01846"></a>01846             fprintf(stderr, <span class="stringliteral">&quot;Codec: %s\n&quot;</span>, <a class="code" href="group__codec.html#ga9eee39f450d8cdcf5aba0e2bda6e5aa8" title="Return the name for a given interface.">vpx_codec_iface_name</a>(codec-&gt;iface));
<a name="l01847"></a>01847             fprintf(stderr, <span class="stringliteral">&quot;Source file: %s Format: %s\n&quot;</span>, in_fn,
<a name="l01848"></a>01848                     arg_use_i420 ? <span class="stringliteral">&quot;I420&quot;</span> : <span class="stringliteral">&quot;YV12&quot;</span>);
<a name="l01849"></a>01849             fprintf(stderr, <span class="stringliteral">&quot;Destination file: %s\n&quot;</span>, out_fn);
<a name="l01850"></a>01850             fprintf(stderr, <span class="stringliteral">&quot;Encoder parameters:\n&quot;</span>);
<a name="l01851"></a>01851 
<a name="l01852"></a>01852             SHOW(g_usage);
<a name="l01853"></a>01853             SHOW(g_threads);
<a name="l01854"></a>01854             SHOW(g_profile);
<a name="l01855"></a>01855             SHOW(g_w);
<a name="l01856"></a>01856             SHOW(g_h);
<a name="l01857"></a>01857             SHOW(g_timebase.num);
<a name="l01858"></a>01858             SHOW(g_timebase.den);
<a name="l01859"></a>01859             SHOW(g_error_resilient);
<a name="l01860"></a>01860             SHOW(g_pass);
<a name="l01861"></a>01861             SHOW(g_lag_in_frames);
<a name="l01862"></a>01862             SHOW(rc_dropframe_thresh);
<a name="l01863"></a>01863             SHOW(rc_resize_allowed);
<a name="l01864"></a>01864             SHOW(rc_resize_up_thresh);
<a name="l01865"></a>01865             SHOW(rc_resize_down_thresh);
<a name="l01866"></a>01866             SHOW(rc_end_usage);
<a name="l01867"></a>01867             SHOW(rc_target_bitrate);
<a name="l01868"></a>01868             SHOW(rc_min_quantizer);
<a name="l01869"></a>01869             SHOW(rc_max_quantizer);
<a name="l01870"></a>01870             SHOW(rc_undershoot_pct);
<a name="l01871"></a>01871             SHOW(rc_overshoot_pct);
<a name="l01872"></a>01872             SHOW(rc_buf_sz);
<a name="l01873"></a>01873             SHOW(rc_buf_initial_sz);
<a name="l01874"></a>01874             SHOW(rc_buf_optimal_sz);
<a name="l01875"></a>01875             SHOW(rc_2pass_vbr_bias_pct);
<a name="l01876"></a>01876             SHOW(rc_2pass_vbr_minsection_pct);
<a name="l01877"></a>01877             SHOW(rc_2pass_vbr_maxsection_pct);
<a name="l01878"></a>01878             SHOW(kf_mode);
<a name="l01879"></a>01879             SHOW(kf_min_dist);
<a name="l01880"></a>01880             SHOW(kf_max_dist);
<a name="l01881"></a>01881         }
<a name="l01882"></a>01882 
<a name="l01883"></a>01883         <span class="keywordflow">if</span>(pass == (one_pass_only ? one_pass_only - 1 : 0)) {
<a name="l01884"></a>01884             <span class="keywordflow">if</span> (file_type == FILE_TYPE_Y4M)
<a name="l01885"></a>01885                 <span class="comment">/*The Y4M reader does its own allocation.</span>
<a name="l01886"></a>01886 <span class="comment">                  Just initialize this here to avoid problems if we never read any</span>
<a name="l01887"></a>01887 <span class="comment">                   frames.*/</span>
<a name="l01888"></a>01888                 memset(&amp;raw, 0, <span class="keyword">sizeof</span>(raw));
<a name="l01889"></a>01889             <span class="keywordflow">else</span>
<a name="l01890"></a>01890                 <a class="code" href="vpx__image_8h.html#ab80398f28ca880368a922fa979eb66c1" title="Open a descriptor, allocating storage for the underlying image.">vpx_img_alloc</a>(&amp;raw, arg_use_i420 ? <a class="code" href="vpx__image_8h.html#a7a30a7bff7400fb83ad45fede5077193af17ce49c9a6efd7c8c8ea8928d4ce26c">VPX_IMG_FMT_I420</a> : <a class="code" href="vpx__image_8h.html#a7a30a7bff7400fb83ad45fede5077193a6e4e8961bbcf96478c300dc4c3e1dc18">VPX_IMG_FMT_YV12</a>,
<a name="l01891"></a>01891                               cfg.<a class="code" href="structvpx__codec__enc__cfg.html#a5c165f5b41ca1158f2883983a2b7709c" title="Width of the frame.">g_w</a>, cfg.<a class="code" href="structvpx__codec__enc__cfg.html#a4132bd89ce85bce7c08f2cc3b6f2b82e" title="Height of the frame.">g_h</a>, 1);
<a name="l01892"></a>01892 
<a name="l01893"></a>01893             init_rate_histogram(&amp;rate_hist, &amp;cfg, &amp;arg_framerate);
<a name="l01894"></a>01894         }
<a name="l01895"></a>01895 
<a name="l01896"></a>01896         outfile = strcmp(out_fn, <span class="stringliteral">&quot;-&quot;</span>) ? fopen(out_fn, <span class="stringliteral">&quot;wb&quot;</span>)
<a name="l01897"></a>01897                                       : set_binary_mode(stdout);
<a name="l01898"></a>01898 
<a name="l01899"></a>01899         <span class="keywordflow">if</span> (!outfile)
<a name="l01900"></a>01900         {
<a name="l01901"></a>01901             fprintf(stderr, <span class="stringliteral">&quot;Failed to open output file\n&quot;</span>);
<a name="l01902"></a>01902             <span class="keywordflow">return</span> EXIT_FAILURE;
<a name="l01903"></a>01903         }
<a name="l01904"></a>01904 
<a name="l01905"></a>01905         <span class="keywordflow">if</span>(write_webm &amp;&amp; fseek(outfile, 0, SEEK_CUR))
<a name="l01906"></a>01906         {
<a name="l01907"></a>01907             fprintf(stderr, <span class="stringliteral">&quot;WebM output to pipes not supported.\n&quot;</span>);
<a name="l01908"></a>01908             <span class="keywordflow">return</span> EXIT_FAILURE;
<a name="l01909"></a>01909         }
<a name="l01910"></a>01910 
<a name="l01911"></a>01911         <span class="keywordflow">if</span> (stats_fn)
<a name="l01912"></a>01912         {
<a name="l01913"></a>01913             <span class="keywordflow">if</span> (!stats_open_file(&amp;stats, stats_fn, pass))
<a name="l01914"></a>01914             {
<a name="l01915"></a>01915                 fprintf(stderr, <span class="stringliteral">&quot;Failed to open statistics store\n&quot;</span>);
<a name="l01916"></a>01916                 <span class="keywordflow">return</span> EXIT_FAILURE;
<a name="l01917"></a>01917             }
<a name="l01918"></a>01918         }
<a name="l01919"></a>01919         <span class="keywordflow">else</span>
<a name="l01920"></a>01920         {
<a name="l01921"></a>01921             <span class="keywordflow">if</span> (!stats_open_mem(&amp;stats, pass))
<a name="l01922"></a>01922             {
<a name="l01923"></a>01923                 fprintf(stderr, <span class="stringliteral">&quot;Failed to open statistics store\n&quot;</span>);
<a name="l01924"></a>01924                 <span class="keywordflow">return</span> EXIT_FAILURE;
<a name="l01925"></a>01925             }
<a name="l01926"></a>01926         }
<a name="l01927"></a>01927 
<a name="l01928"></a>01928         cfg.<a class="code" href="structvpx__codec__enc__cfg.html#a70d62d87aae7d1168746577f14a6dccf" title="Multi-pass Encoding Mode.">g_pass</a> = arg_passes == 2
<a name="l01929"></a>01929                      ? pass ? <a class="code" href="group__encoder.html#gga476c5417f9c15a1dc5d3f68fa44c493fa65da543b956d6a9b1f301ab8cc90d3a7">VPX_RC_LAST_PASS</a> : <a class="code" href="group__encoder.html#gga476c5417f9c15a1dc5d3f68fa44c493faa0765945345b160905f3b762986dae3b">VPX_RC_FIRST_PASS</a>
<a name="l01930"></a>01930                  : <a class="code" href="group__encoder.html#gga476c5417f9c15a1dc5d3f68fa44c493fa7b6943a41868e8e26a77e9500f139ca1">VPX_RC_ONE_PASS</a>;
<a name="l01931"></a>01931 <span class="preprocessor">#if VPX_ENCODER_ABI_VERSION &gt; (1 + VPX_CODEC_ABI_VERSION)</span>
<a name="l01932"></a>01932 <span class="preprocessor"></span>
<a name="l01933"></a>01933         <span class="keywordflow">if</span> (pass)
<a name="l01934"></a>01934         {
<a name="l01935"></a>01935             cfg.<a class="code" href="structvpx__codec__enc__cfg.html#a618616a07d9d8883c544731957b56f3c" title="Two-pass stats buffer.">rc_twopass_stats_in</a> = stats_get(&amp;stats);
<a name="l01936"></a>01936         }
<a name="l01937"></a>01937 
<a name="l01938"></a>01938 <span class="preprocessor">#endif</span>
<a name="l01939"></a>01939 <span class="preprocessor"></span>
<a name="l01940"></a>01940         <span class="keywordflow">if</span>(write_webm)
<a name="l01941"></a>01941         {
<a name="l01942"></a>01942             ebml.stream = outfile;
<a name="l01943"></a>01943             write_webm_file_header(&amp;ebml, &amp;cfg, &amp;arg_framerate, stereo_fmt);
<a name="l01944"></a>01944         }
<a name="l01945"></a>01945         <span class="keywordflow">else</span>
<a name="l01946"></a>01946             write_ivf_file_header(outfile, &amp;cfg, codec-&gt;fourcc, 0);
<a name="l01947"></a>01947 
<a name="l01948"></a>01948 
<a name="l01949"></a>01949         <span class="comment">/* Construct Encoder Context */</span>
<a name="l01950"></a>01950         <a class="code" href="group__encoder.html#ga3d490a2a9a6acd7c9ef82a603155f3cf" title="Convenience macro for vpx_codec_enc_init_ver()">vpx_codec_enc_init</a>(&amp;encoder, codec-&gt;iface, &amp;cfg,
<a name="l01951"></a>01951                            show_psnr ? <a class="code" href="group__encoder.html#ga57bb9eb1881c7e4bf86580660a5e40a0" title="Initialization-time Feature Enabling.">VPX_CODEC_USE_PSNR</a> : 0);
<a name="l01952"></a>01952         ctx_exit_on_error(&amp;encoder, <span class="stringliteral">&quot;Failed to initialize encoder&quot;</span>);
<a name="l01953"></a>01953 
<a name="l01954"></a>01954         <span class="comment">/* Note that we bypass the vpx_codec_control wrapper macro because</span>
<a name="l01955"></a>01955 <span class="comment">         * we&#39;re being clever to store the control IDs in an array. Real</span>
<a name="l01956"></a>01956 <span class="comment">         * applications will want to make use of the enumerations directly</span>
<a name="l01957"></a>01957 <span class="comment">         */</span>
<a name="l01958"></a>01958         <span class="keywordflow">for</span> (i = 0; i &lt; arg_ctrl_cnt; i++)
<a name="l01959"></a>01959         {
<a name="l01960"></a>01960             <span class="keywordflow">if</span> (<a class="code" href="group__codec.html#gaf7849b69cc390b21d889c8c71f69ec14" title="Control algorithm.">vpx_codec_control_</a>(&amp;encoder, arg_ctrls[i][0], arg_ctrls[i][1]))
<a name="l01961"></a>01961                 fprintf(stderr, <span class="stringliteral">&quot;Error: Tried to set control %d = %d\n&quot;</span>,
<a name="l01962"></a>01962                         arg_ctrls[i][0], arg_ctrls[i][1]);
<a name="l01963"></a>01963 
<a name="l01964"></a>01964             ctx_exit_on_error(&amp;encoder, <span class="stringliteral">&quot;Failed to control codec&quot;</span>);
<a name="l01965"></a>01965         }
<a name="l01966"></a>01966 
<a name="l01967"></a>01967         frame_avail = 1;
<a name="l01968"></a>01968         got_data = 0;
<a name="l01969"></a>01969 
<a name="l01970"></a>01970         <span class="keywordflow">while</span> (frame_avail || got_data)
<a name="l01971"></a>01971         {
<a name="l01972"></a>01972             <a class="code" href="group__codec.html#ga6ea348f76b1f8a1fe50e14db684146c6" title="Iterator.">vpx_codec_iter_t</a> iter = NULL;
<a name="l01973"></a>01973             <span class="keyword">const</span> <a class="code" href="structvpx__codec__cx__pkt.html" title="Encoder output packet.">vpx_codec_cx_pkt_t</a> *pkt;
<a name="l01974"></a>01974             <span class="keyword">struct </span>vpx_usec_timer timer;
<a name="l01975"></a>01975             int64_t frame_start, next_frame_start;
<a name="l01976"></a>01976 
<a name="l01977"></a>01977             <span class="keywordflow">if</span> (!arg_limit || frames_in &lt; arg_limit)
<a name="l01978"></a>01978             {
<a name="l01979"></a>01979                 frame_avail = read_frame(infile, &amp;raw, file_type, &amp;y4m,
<a name="l01980"></a>01980                                          &amp;detect);
<a name="l01981"></a>01981 
<a name="l01982"></a>01982                 <span class="keywordflow">if</span> (frame_avail)
<a name="l01983"></a>01983                     frames_in++;
<a name="l01984"></a>01984 
<a name="l01985"></a>01985                 fprintf(stderr,
<a name="l01986"></a>01986                         <span class="stringliteral">&quot;\rPass %d/%d frame %4d/%-4d %7&quot;</span>PRId64<span class="stringliteral">&quot;B \033[K&quot;</span>,
<a name="l01987"></a>01987                         pass + 1, arg_passes, frames_in, frames_out, nbytes);
<a name="l01988"></a>01988             }
<a name="l01989"></a>01989             <span class="keywordflow">else</span>
<a name="l01990"></a>01990                 frame_avail = 0;
<a name="l01991"></a>01991 
<a name="l01992"></a>01992             vpx_usec_timer_start(&amp;timer);
<a name="l01993"></a>01993 
<a name="l01994"></a>01994             frame_start = (cfg.<a class="code" href="structvpx__codec__enc__cfg.html#a6498d378e4c29ef3e22258289e481087" title="Stream timebase units.">g_timebase</a>.<a class="code" href="structvpx__rational.html#a29dd2ab4001377b3aa21885ef969759f">den</a> * (int64_t)(frames_in - 1)
<a name="l01995"></a>01995                           * arg_framerate.<a class="code" href="structvpx__rational.html#a29dd2ab4001377b3aa21885ef969759f">den</a>) / cfg.<a class="code" href="structvpx__codec__enc__cfg.html#a6498d378e4c29ef3e22258289e481087" title="Stream timebase units.">g_timebase</a>.<a class="code" href="structvpx__rational.html#ae7774f21a22c9bef3aa73156c79f4731">num</a> / arg_framerate.<a class="code" href="structvpx__rational.html#ae7774f21a22c9bef3aa73156c79f4731">num</a>;
<a name="l01996"></a>01996             next_frame_start = (cfg.<a class="code" href="structvpx__codec__enc__cfg.html#a6498d378e4c29ef3e22258289e481087" title="Stream timebase units.">g_timebase</a>.<a class="code" href="structvpx__rational.html#a29dd2ab4001377b3aa21885ef969759f">den</a> * (int64_t)(frames_in)
<a name="l01997"></a>01997                                 * arg_framerate.<a class="code" href="structvpx__rational.html#a29dd2ab4001377b3aa21885ef969759f">den</a>)
<a name="l01998"></a>01998                                 / cfg.<a class="code" href="structvpx__codec__enc__cfg.html#a6498d378e4c29ef3e22258289e481087" title="Stream timebase units.">g_timebase</a>.<a class="code" href="structvpx__rational.html#ae7774f21a22c9bef3aa73156c79f4731">num</a> / arg_framerate.<a class="code" href="structvpx__rational.html#ae7774f21a22c9bef3aa73156c79f4731">num</a>;
<a name="l01999"></a>01999             <a class="code" href="group__encoder.html#gaf990542e2aeb389f05fae3e9c7803639" title="Encode a frame.">vpx_codec_encode</a>(&amp;encoder, frame_avail ? &amp;raw : NULL, frame_start,
<a name="l02000"></a>02000                              next_frame_start - frame_start,
<a name="l02001"></a>02001                              0, arg_deadline);
<a name="l02002"></a>02002             vpx_usec_timer_mark(&amp;timer);
<a name="l02003"></a>02003             cx_time += vpx_usec_timer_elapsed(&amp;timer);
<a name="l02004"></a>02004             ctx_exit_on_error(&amp;encoder, <span class="stringliteral">&quot;Failed to encode frame&quot;</span>);
<a name="l02005"></a>02005 
<a name="l02006"></a>02006             <span class="keywordflow">if</span>(cfg.<a class="code" href="structvpx__codec__enc__cfg.html#a70d62d87aae7d1168746577f14a6dccf" title="Multi-pass Encoding Mode.">g_pass</a> != <a class="code" href="group__encoder.html#gga476c5417f9c15a1dc5d3f68fa44c493faa0765945345b160905f3b762986dae3b">VPX_RC_FIRST_PASS</a>)
<a name="l02007"></a>02007             {
<a name="l02008"></a>02008                 <span class="keywordtype">int</span> q;
<a name="l02009"></a>02009 
<a name="l02010"></a>02010                 <a class="code" href="group__codec.html#gac1b91e04698c1bd4c0a2b8aa85b08cd2" title="vpx_codec_control wrapper macro">vpx_codec_control</a>(&amp;encoder, <a class="code" href="group__vp8__encoder.html#gga6deae3d561c838952552c3d3756322ecad2cfc9712d2eab30b5a59a60d0daaade">VP8E_GET_LAST_QUANTIZER_64</a>, &amp;q);
<a name="l02011"></a>02011                 ctx_exit_on_error(&amp;encoder, <span class="stringliteral">&quot;Failed to read quantizer&quot;</span>);
<a name="l02012"></a>02012                 counts[q]++;
<a name="l02013"></a>02013             }
<a name="l02014"></a>02014 
<a name="l02015"></a>02015             got_data = 0;
<a name="l02016"></a>02016 
<a name="l02017"></a>02017             <span class="keywordflow">while</span> ((pkt = <a class="code" href="group__encoder.html#gae81cab25d66cf3bc59f1f75f8a5af720" title="Encoded data iterator.">vpx_codec_get_cx_data</a>(&amp;encoder, &amp;iter)))
<a name="l02018"></a>02018             {
<a name="l02019"></a>02019                 got_data = 1;
<a name="l02020"></a>02020 
<a name="l02021"></a>02021                 <span class="keywordflow">switch</span> (pkt-&gt;<a class="code" href="structvpx__codec__cx__pkt.html#a41f395b39516343c1329a4a85a0084f2">kind</a>)
<a name="l02022"></a>02022                 {
<a name="l02023"></a>02023                 <span class="keywordflow">case</span> <a class="code" href="group__encoder.html#gga28a79375279536526552af3a83d2ed72a2261aae5594289400e812fb1e6b6b0cc">VPX_CODEC_CX_FRAME_PKT</a>:
<a name="l02024"></a>02024                     frames_out++;
<a name="l02025"></a>02025                     fprintf(stderr, <span class="stringliteral">&quot; %6luF&quot;</span>,
<a name="l02026"></a>02026                             (<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>)pkt-&gt;<a class="code" href="structvpx__codec__cx__pkt.html#a7f97b060a23b7e89fe5b885c0074f696">data</a>.<a class="code" href="structvpx__codec__cx__pkt.html#a81e33bf4408a3983abb16492fee359ff">frame</a>.sz);
<a name="l02027"></a>02027 
<a name="l02028"></a>02028                     update_rate_histogram(&amp;rate_hist, &amp;cfg, pkt);
<a name="l02029"></a>02029                     <span class="keywordflow">if</span>(write_webm)
<a name="l02030"></a>02030                     {
<a name="l02031"></a>02031                         <span class="comment">/* Update the hash */</span>
<a name="l02032"></a>02032                         <span class="keywordflow">if</span>(!ebml.debug)
<a name="l02033"></a>02033                             hash = murmur(pkt-&gt;<a class="code" href="structvpx__codec__cx__pkt.html#a7f97b060a23b7e89fe5b885c0074f696">data</a>.<a class="code" href="structvpx__codec__cx__pkt.html#a81e33bf4408a3983abb16492fee359ff">frame</a>.buf,
<a name="l02034"></a>02034                                           pkt-&gt;<a class="code" href="structvpx__codec__cx__pkt.html#a7f97b060a23b7e89fe5b885c0074f696">data</a>.<a class="code" href="structvpx__codec__cx__pkt.html#a81e33bf4408a3983abb16492fee359ff">frame</a>.sz, hash);
<a name="l02035"></a>02035 
<a name="l02036"></a>02036                         write_webm_block(&amp;ebml, &amp;cfg, pkt);
<a name="l02037"></a>02037                     }
<a name="l02038"></a>02038                     <span class="keywordflow">else</span>
<a name="l02039"></a>02039                     {
<a name="l02040"></a>02040                         write_ivf_frame_header(outfile, pkt);
<a name="l02041"></a>02041                         <span class="keywordflow">if</span>(fwrite(pkt-&gt;<a class="code" href="structvpx__codec__cx__pkt.html#a7f97b060a23b7e89fe5b885c0074f696">data</a>.<a class="code" href="structvpx__codec__cx__pkt.html#a81e33bf4408a3983abb16492fee359ff">frame</a>.buf, 1,
<a name="l02042"></a>02042                                   pkt-&gt;<a class="code" href="structvpx__codec__cx__pkt.html#a7f97b060a23b7e89fe5b885c0074f696">data</a>.<a class="code" href="structvpx__codec__cx__pkt.html#a81e33bf4408a3983abb16492fee359ff">frame</a>.sz, outfile));
<a name="l02043"></a>02043                     }
<a name="l02044"></a>02044                     nbytes += pkt-&gt;<a class="code" href="structvpx__codec__cx__pkt.html#a7f97b060a23b7e89fe5b885c0074f696">data</a>.<a class="code" href="structvpx__codec__cx__pkt.html#acc7ee91ea9c907aea7c3b953324f7c26">raw</a>.<a class="code" href="structvpx__fixed__buf.html#a43d7f8247ed9752f65f0a7639817ae84">sz</a>;
<a name="l02045"></a>02045                     <span class="keywordflow">break</span>;
<a name="l02046"></a>02046                 <span class="keywordflow">case</span> <a class="code" href="group__encoder.html#gga28a79375279536526552af3a83d2ed72a77cd8b95d9891bcce36117f5f31994fd">VPX_CODEC_STATS_PKT</a>:
<a name="l02047"></a>02047                     frames_out++;
<a name="l02048"></a>02048                     fprintf(stderr, <span class="stringliteral">&quot; %6luS&quot;</span>,
<a name="l02049"></a>02049                            (<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>)pkt-&gt;<a class="code" href="structvpx__codec__cx__pkt.html#a7f97b060a23b7e89fe5b885c0074f696">data</a>.<a class="code" href="structvpx__codec__cx__pkt.html#a53db8576979fa7335e478eb849b256f1">twopass_stats</a>.<a class="code" href="structvpx__fixed__buf.html#a43d7f8247ed9752f65f0a7639817ae84">sz</a>);
<a name="l02050"></a>02050                     stats_write(&amp;stats,
<a name="l02051"></a>02051                                 pkt-&gt;<a class="code" href="structvpx__codec__cx__pkt.html#a7f97b060a23b7e89fe5b885c0074f696">data</a>.<a class="code" href="structvpx__codec__cx__pkt.html#a53db8576979fa7335e478eb849b256f1">twopass_stats</a>.<a class="code" href="structvpx__fixed__buf.html#ac93e43ae3fcc1023dca86d37016ae3f0">buf</a>,
<a name="l02052"></a>02052                                 pkt-&gt;<a class="code" href="structvpx__codec__cx__pkt.html#a7f97b060a23b7e89fe5b885c0074f696">data</a>.<a class="code" href="structvpx__codec__cx__pkt.html#a53db8576979fa7335e478eb849b256f1">twopass_stats</a>.<a class="code" href="structvpx__fixed__buf.html#a43d7f8247ed9752f65f0a7639817ae84">sz</a>);
<a name="l02053"></a>02053                     nbytes += pkt-&gt;<a class="code" href="structvpx__codec__cx__pkt.html#a7f97b060a23b7e89fe5b885c0074f696">data</a>.<a class="code" href="structvpx__codec__cx__pkt.html#acc7ee91ea9c907aea7c3b953324f7c26">raw</a>.<a class="code" href="structvpx__fixed__buf.html#a43d7f8247ed9752f65f0a7639817ae84">sz</a>;
<a name="l02054"></a>02054                     <span class="keywordflow">break</span>;
<a name="l02055"></a>02055                 <span class="keywordflow">case</span> <a class="code" href="group__encoder.html#gga28a79375279536526552af3a83d2ed72a11eefa1328e6d22eb7c844645a260628">VPX_CODEC_PSNR_PKT</a>:
<a name="l02056"></a>02056 
<a name="l02057"></a>02057                     <span class="keywordflow">if</span> (show_psnr)
<a name="l02058"></a>02058                     {
<a name="l02059"></a>02059                         <span class="keywordtype">int</span> i;
<a name="l02060"></a>02060 
<a name="l02061"></a>02061                         psnr_sse_total += pkt-&gt;<a class="code" href="structvpx__codec__cx__pkt.html#a7f97b060a23b7e89fe5b885c0074f696">data</a>.<a class="code" href="structvpx__codec__cx__pkt.html#a63744aeceb50355d6402d55309c151b6">psnr</a>.sse[0];
<a name="l02062"></a>02062                         psnr_samples_total += pkt-&gt;<a class="code" href="structvpx__codec__cx__pkt.html#a7f97b060a23b7e89fe5b885c0074f696">data</a>.<a class="code" href="structvpx__codec__cx__pkt.html#a63744aeceb50355d6402d55309c151b6">psnr</a>.samples[0];
<a name="l02063"></a>02063                         <span class="keywordflow">for</span> (i = 0; i &lt; 4; i++)
<a name="l02064"></a>02064                         {
<a name="l02065"></a>02065                             fprintf(stderr, <span class="stringliteral">&quot;%.3lf &quot;</span>, pkt-&gt;<a class="code" href="structvpx__codec__cx__pkt.html#a7f97b060a23b7e89fe5b885c0074f696">data</a>.<a class="code" href="structvpx__codec__cx__pkt.html#a63744aeceb50355d6402d55309c151b6">psnr</a>.psnr[i]);
<a name="l02066"></a>02066                             psnr_totals[i] += pkt-&gt;<a class="code" href="structvpx__codec__cx__pkt.html#a7f97b060a23b7e89fe5b885c0074f696">data</a>.<a class="code" href="structvpx__codec__cx__pkt.html#a63744aeceb50355d6402d55309c151b6">psnr</a>.psnr[i];
<a name="l02067"></a>02067                         }
<a name="l02068"></a>02068                         psnr_count++;
<a name="l02069"></a>02069                     }
<a name="l02070"></a>02070 
<a name="l02071"></a>02071                     <span class="keywordflow">break</span>;
<a name="l02072"></a>02072                 <span class="keywordflow">default</span>:
<a name="l02073"></a>02073                     <span class="keywordflow">break</span>;
<a name="l02074"></a>02074                 }
<a name="l02075"></a>02075             }
<a name="l02076"></a>02076 
<a name="l02077"></a>02077             fflush(stdout);
<a name="l02078"></a>02078         }
<a name="l02079"></a>02079 
<a name="l02080"></a>02080         fprintf(stderr,
<a name="l02081"></a>02081                <span class="stringliteral">&quot;\rPass %d/%d frame %4d/%-4d %7&quot;</span>PRId64<span class="stringliteral">&quot;B %7lub/f %7&quot;</span>PRId64<span class="stringliteral">&quot;b/s&quot;</span>
<a name="l02082"></a>02082                <span class="stringliteral">&quot; %7lu %s (%.2f fps)\033[K&quot;</span>, pass + 1,
<a name="l02083"></a>02083                arg_passes, frames_in, frames_out, nbytes,
<a name="l02084"></a>02084                frames_in ? (<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>)(nbytes * 8 / frames_in) : 0,
<a name="l02085"></a>02085                frames_in ? nbytes * 8 *(int64_t)arg_framerate.<a class="code" href="structvpx__rational.html#ae7774f21a22c9bef3aa73156c79f4731">num</a> / arg_framerate.<a class="code" href="structvpx__rational.html#a29dd2ab4001377b3aa21885ef969759f">den</a> / frames_in : 0,
<a name="l02086"></a>02086                cx_time &gt; 9999999 ? cx_time / 1000 : cx_time,
<a name="l02087"></a>02087                cx_time &gt; 9999999 ? <span class="stringliteral">&quot;ms&quot;</span> : <span class="stringliteral">&quot;us&quot;</span>,
<a name="l02088"></a>02088                cx_time &gt; 0 ? (<span class="keywordtype">float</span>)frames_in * 1000000.0 / (<span class="keywordtype">float</span>)cx_time : 0);
<a name="l02089"></a>02089 
<a name="l02090"></a>02090         <span class="keywordflow">if</span> ( (show_psnr) &amp;&amp; (psnr_count&gt;0) )
<a name="l02091"></a>02091         {
<a name="l02092"></a>02092             <span class="keywordtype">int</span> i;
<a name="l02093"></a>02093             <span class="keywordtype">double</span> ovpsnr = vp8_mse2psnr(psnr_samples_total, 255.0,
<a name="l02094"></a>02094                                          psnr_sse_total);
<a name="l02095"></a>02095 
<a name="l02096"></a>02096             fprintf(stderr, <span class="stringliteral">&quot;\nPSNR (Overall/Avg/Y/U/V)&quot;</span>);
<a name="l02097"></a>02097 
<a name="l02098"></a>02098             fprintf(stderr, <span class="stringliteral">&quot; %.3lf&quot;</span>, ovpsnr);
<a name="l02099"></a>02099             <span class="keywordflow">for</span> (i = 0; i &lt; 4; i++)
<a name="l02100"></a>02100             {
<a name="l02101"></a>02101                 fprintf(stderr, <span class="stringliteral">&quot; %.3lf&quot;</span>, psnr_totals[i]/psnr_count);
<a name="l02102"></a>02102             }
<a name="l02103"></a>02103         }
<a name="l02104"></a>02104 
<a name="l02105"></a>02105         <a class="code" href="group__codec.html#ga6ae21d96909660d0ac978b59a863f53b" title="Destroy a codec instance.">vpx_codec_destroy</a>(&amp;encoder);
<a name="l02106"></a>02106 
<a name="l02107"></a>02107         fclose(infile);
<a name="l02108"></a>02108         <span class="keywordflow">if</span> (file_type == FILE_TYPE_Y4M)
<a name="l02109"></a>02109             y4m_input_close(&amp;y4m);
<a name="l02110"></a>02110 
<a name="l02111"></a>02111         <span class="keywordflow">if</span>(write_webm)
<a name="l02112"></a>02112         {
<a name="l02113"></a>02113             write_webm_file_footer(&amp;ebml, hash);
<a name="l02114"></a>02114             free(ebml.cue_list);
<a name="l02115"></a>02115             ebml.cue_list = NULL;
<a name="l02116"></a>02116         }
<a name="l02117"></a>02117         <span class="keywordflow">else</span>
<a name="l02118"></a>02118         {
<a name="l02119"></a>02119             <span class="keywordflow">if</span> (!fseek(outfile, 0, SEEK_SET))
<a name="l02120"></a>02120                 write_ivf_file_header(outfile, &amp;cfg, codec-&gt;fourcc, frames_out);
<a name="l02121"></a>02121         }
<a name="l02122"></a>02122 
<a name="l02123"></a>02123         fclose(outfile);
<a name="l02124"></a>02124         stats_close(&amp;stats, arg_passes-1);
<a name="l02125"></a>02125         fprintf(stderr, <span class="stringliteral">&quot;\n&quot;</span>);
<a name="l02126"></a>02126 
<a name="l02127"></a>02127         <span class="keywordflow">if</span> (one_pass_only)
<a name="l02128"></a>02128             <span class="keywordflow">break</span>;
<a name="l02129"></a>02129     }
<a name="l02130"></a>02130 
<a name="l02131"></a>02131     <span class="keywordflow">if</span> (show_q_hist_buckets)
<a name="l02132"></a>02132         show_q_histogram(counts, show_q_hist_buckets);
<a name="l02133"></a>02133 
<a name="l02134"></a>02134     <span class="keywordflow">if</span> (show_rate_hist_buckets)
<a name="l02135"></a>02135         show_rate_histogram(&amp;rate_hist, &amp;cfg, show_rate_hist_buckets);
<a name="l02136"></a>02136     destroy_rate_histogram(&amp;rate_hist);
<a name="l02137"></a>02137 
<a name="l02138"></a>02138     <a class="code" href="vpx__image_8h.html#af47ebaf286812d037425d41990d48a17" title="Close an image descriptor.">vpx_img_free</a>(&amp;raw);
<a name="l02139"></a>02139     free(argv);
<a name="l02140"></a>02140     <span class="keywordflow">return</span> EXIT_SUCCESS;
<a name="l02141"></a>02141 }
</pre></div> </div></div>
<hr class="footer"/><address class="footer"><small>Generated on Mon Jan 30 2012 for WebM VP8 Codec SDK by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
</body>
</html>