blob: 94498b075907112a89d2c670183473ad83babdc9 [file] [log] [blame]
<!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"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>VA-API: Video Acceleration (VA) API</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">VA-API
&#160;<span id="projectnumber">2.13.0.pre1</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
initMenu('',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div class="header">
<div class="headertitle">
<div class="title">Video Acceleration (VA) API </div> </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><h1><a class="anchor" id="intro"></a>
Introduction</h1>
<p>The main motivation for VA-API (Video Acceleration API) is to enable hardware accelerated video decode and encode at various entry-points (VLD, IDCT, Motion Compensation etc.) for the prevailing coding standards today (MPEG-2, MPEG-4 ASP/H.263, MPEG-4 AVC/H.264, VC-1/VMW3, and JPEG, HEVC/H265, VP8, VP9) and video pre/post processing</p>
<p>VA-API is split into several modules:</p><ul>
<li><a class="el" href="group__api__core.html">Core API</a></li>
<li>Encoder (H264, HEVC, JPEG, MPEG2, VP8, VP9)<ul>
<li><a class="el" href="group__api__enc__h264.html">H.264 encoding API</a></li>
<li><a class="el" href="group__api__enc__hevc.html">HEVC encoding API</a></li>
<li><a class="el" href="group__api__enc__jpeg.html">JPEG encoding API</a></li>
<li><a class="el" href="group__api__enc__mpeg2.html">MPEG-2 encoding API</a></li>
<li><a class="el" href="group__api__enc__vp8.html">VP8 encoding API</a></li>
<li><a class="el" href="group__api__enc__vp9.html">VP9 encoding API</a></li>
</ul>
</li>
<li>Decoder (HEVC, JPEG, VP8, VP9, AV1)<ul>
<li><a class="el" href="group__api__dec__hevc.html">HEVC decoding API</a></li>
<li><a class="el" href="group__api__dec__jpeg.html">JPEG decoding API</a></li>
<li><a class="el" href="group__api__dec__vp8.html">VP8 decoding API</a></li>
<li><a class="el" href="group__api__dec__vp9.html">VP9 decoding API</a></li>
<li><a class="el" href="group__api__dec__av1.html">AV1 decoding API</a></li>
</ul>
</li>
<li><a class="el" href="group__api__vpp.html">Video processing API</a></li>
<li><a class="el" href="group__api__prot.html">Protected content API</a></li>
<li>FEI (H264, HEVC)<ul>
<li><a class="el" href="group__api__fei.html">FEI encoding common API</a></li>
<li><a class="el" href="group__api__fei__h264.html">H.264 FEI encoding API</a></li>
<li><a class="el" href="group__api__fei__hevc.html">HEVC FEI encoding API</a></li>
</ul>
</li>
</ul>
<h1><a class="anchor" id="threading"></a>
Multithreading Guide</h1>
<p>All VAAPI functions implemented in libva are thread-safe. For any VAAPI function that requires the implementation of a backend (e.g. hardware driver), the backend must ensure that its implementation is also thread-safe. If the backend implementation of a VAAPI function is not thread-safe then this should be considered as a bug against the backend implementation.</p>
<p>It is assumed that none of the VAAPI functions will be called from signal handlers.</p>
<p>Thread-safety in this context means that when VAAPI is being called by multiple concurrent threads, it will not crash or hang the OS, and VAAPI internal data structures will not be corrupted. When multiple threads are operating on the same VAAPI objects, it is the application's responsibility to synchronize these operations in order to generate the expected results. For example, using a single VAContext from multiple threads may generate unexpected results.</p>
<p>Following pseudo code illustrates a multithreaded transcoding scenario, where one thread is handling the decoding operation and another thread is handling the encoding operation, while synchronizing the use of a common pool of surfaces.</p>
<div class="fragment"><div class="line"><span class="comment">// Initialization</span></div><div class="line">dpy = vaGetDisplayDRM(fd);</div><div class="line"><a class="code" href="group__api__core.html#ga266154ed3b1f38e873caa0af680d733e">vaInitialize</a>(dpy, ...); </div><div class="line"></div><div class="line"><span class="comment">// Create surfaces required for decoding and subsequence encoding</span></div><div class="line"><a class="code" href="group__api__core.html#gac970ea0eec412326667549f58c44129b">vaCreateSurfaces</a>(dpy, <a class="code" href="group__api__core.html#gaff38bc6c01b65c6e9d473e40bdde9df6">VA_RT_FORMAT_YUV420</a>, width, height, &amp;surfaces[0], ...);</div><div class="line"></div><div class="line"><span class="comment">// Set up a queue for the surfaces shared between decode and encode threads</span></div><div class="line">surface_queue = queue_create();</div><div class="line"></div><div class="line"><span class="comment">// Create decode_thread</span></div><div class="line">pthread_create(&amp;decode_thread, NULL, decode, ...);</div><div class="line"></div><div class="line"><span class="comment">// Create encode_thread</span></div><div class="line">pthread_create(&amp;encode_thread, NULL, encode, ...);</div><div class="line"></div><div class="line"><span class="comment">// Decode thread function</span></div><div class="line">decode() {</div><div class="line"> <span class="comment">// Find the decode entrypoint for H.264 </span></div><div class="line"> <a class="code" href="group__api__core.html#ga7c6ec979697dafc172123c5d3ad80d8e">vaQueryConfigEntrypoints</a>(dpy, h264_profile, entrypoints, ...);</div><div class="line"></div><div class="line"> <span class="comment">// Create a config for H.264 decode</span></div><div class="line"> <a class="code" href="group__api__core.html#ga9ff7833d425406cb1834c783b0a47652">vaCreateConfig</a>(dpy, h264_profile, VAEntrypointVLD, ...);</div><div class="line"></div><div class="line"> <span class="comment">// Create a context for decode</span></div><div class="line"> <a class="code" href="group__api__core.html#ga7a0e774a793545058d1a311bed9bb8cf">vaCreateContext</a>(dpy, config, width, height, VA_PROGRESSIVE, surfaces, </div><div class="line"> num_surfaces, &amp;decode_context); </div><div class="line"></div><div class="line"> <span class="comment">// Decode frames in the bitstream</span></div><div class="line"> <span class="keywordflow">for</span> (;;) {</div><div class="line"> <span class="comment">// Parse one frame and decode </span></div><div class="line"> <a class="code" href="group__api__core.html#gacf031b9aaf39365bf8d79d92372f2ec8">vaBeginPicture</a>(dpy, decode_context, surfaces[surface_index]); </div><div class="line"> <a class="code" href="group__api__core.html#ga3facc622a14fc901d5d44dcda845cb6f">vaRenderPicture</a>(dpy, decode_context, buf, ...);</div><div class="line"> <a class="code" href="group__api__core.html#gaffbd38af17b5f061707010287e7d4c97">vaEndPicture</a>(dpy, decode_context);</div><div class="line"> <span class="comment">// Poll the decoding status and enqueue the surface in display order after </span></div><div class="line"> <span class="comment">// decoding is complete</span></div><div class="line"> <a class="code" href="group__api__core.html#ga59e5c937c8554f1bab043f80427c2fa8">vaQuerySurfaceStatus</a>();</div><div class="line"> enqueue(surface_queue, surface_index);</div><div class="line"> }</div><div class="line">}</div><div class="line"></div><div class="line"><span class="comment">// Encode thread function</span></div><div class="line">encode() {</div><div class="line"> <span class="comment">// Find the encode entrypoint for HEVC</span></div><div class="line"> <a class="code" href="group__api__core.html#ga7c6ec979697dafc172123c5d3ad80d8e">vaQueryConfigEntrypoints</a>(dpy, hevc_profile, entrypoints, ...);</div><div class="line"></div><div class="line"> <span class="comment">// Create a config for HEVC encode</span></div><div class="line"> <a class="code" href="group__api__core.html#ga9ff7833d425406cb1834c783b0a47652">vaCreateConfig</a>(dpy, hevc_profile, VAEntrypointEncSlice, ...);</div><div class="line"></div><div class="line"> <span class="comment">// Create a context for encode</span></div><div class="line"> <a class="code" href="group__api__core.html#ga7a0e774a793545058d1a311bed9bb8cf">vaCreateContext</a>(dpy, config, width, height, VA_PROGRESSIVE, surfaces,</div><div class="line"> num_surfaces, &amp;encode_context); </div><div class="line"></div><div class="line"> <span class="comment">// Encode frames produced by the decoder</span></div><div class="line"> <span class="keywordflow">for</span> (;;) {</div><div class="line"> <span class="comment">// Dequeue the surface enqueued by the decoder </span></div><div class="line"> surface_index = dequeue(surface_queue);</div><div class="line"> <span class="comment">// Encode using this surface as the source</span></div><div class="line"> <a class="code" href="group__api__core.html#gacf031b9aaf39365bf8d79d92372f2ec8">vaBeginPicture</a>(dpy, encode_context, surfaces[surface_index]);</div><div class="line"> <a class="code" href="group__api__core.html#ga3facc622a14fc901d5d44dcda845cb6f">vaRenderPicture</a>(dpy, encode_context, buf, ...);</div><div class="line"> <a class="code" href="group__api__core.html#gaffbd38af17b5f061707010287e7d4c97">vaEndPicture</a>(dpy, encode_context);</div><div class="line"> }</div><div class="line">}</div></div><!-- fragment --> </div></div><!-- contents -->
<hr class="footer"/><address class="footer"><small>
Generated for VA-API by&#160;<a href="http://www.doxygen.org/index.html"><img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.13</small></address>
</body>
</html>