hwcontext.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * FFmpeg is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with FFmpeg; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef AVUTIL_HWCONTEXT_H
  19. #define AVUTIL_HWCONTEXT_H
  20. #include "buffer.h"
  21. #include "frame.h"
  22. #include "log.h"
  23. #include "pixfmt.h"
  24. enum AVHWDeviceType {
  25. AV_HWDEVICE_TYPE_NONE,
  26. AV_HWDEVICE_TYPE_VDPAU,
  27. AV_HWDEVICE_TYPE_CUDA,
  28. AV_HWDEVICE_TYPE_VAAPI,
  29. AV_HWDEVICE_TYPE_DXVA2,
  30. AV_HWDEVICE_TYPE_QSV,
  31. AV_HWDEVICE_TYPE_VIDEOTOOLBOX,
  32. AV_HWDEVICE_TYPE_D3D11VA,
  33. AV_HWDEVICE_TYPE_DRM,
  34. AV_HWDEVICE_TYPE_OPENCL,
  35. AV_HWDEVICE_TYPE_MEDIACODEC,
  36. AV_HWDEVICE_TYPE_VULKAN,
  37. };
  38. typedef struct AVHWDeviceInternal AVHWDeviceInternal;
  39. /**
  40. * This struct aggregates all the (hardware/vendor-specific) "high-level" state,
  41. * i.e. state that is not tied to a concrete processing configuration.
  42. * E.g., in an API that supports hardware-accelerated encoding and decoding,
  43. * this struct will (if possible) wrap the state that is common to both encoding
  44. * and decoding and from which specific instances of encoders or decoders can be
  45. * derived.
  46. *
  47. * This struct is reference-counted with the AVBuffer mechanism. The
  48. * av_hwdevice_ctx_alloc() constructor yields a reference, whose data field
  49. * points to the actual AVHWDeviceContext. Further objects derived from
  50. * AVHWDeviceContext (such as AVHWFramesContext, describing a frame pool with
  51. * specific properties) will hold an internal reference to it. After all the
  52. * references are released, the AVHWDeviceContext itself will be freed,
  53. * optionally invoking a user-specified callback for uninitializing the hardware
  54. * state.
  55. */
  56. typedef struct AVHWDeviceContext {
  57. /**
  58. * A class for logging. Set by av_hwdevice_ctx_alloc().
  59. */
  60. const AVClass *av_class;
  61. /**
  62. * Private data used internally by libavutil. Must not be accessed in any
  63. * way by the caller.
  64. */
  65. AVHWDeviceInternal *internal;
  66. /**
  67. * This field identifies the underlying API used for hardware access.
  68. *
  69. * This field is set when this struct is allocated and never changed
  70. * afterwards.
  71. */
  72. enum AVHWDeviceType type;
  73. /**
  74. * The format-specific data, allocated and freed by libavutil along with
  75. * this context.
  76. *
  77. * Should be cast by the user to the format-specific context defined in the
  78. * corresponding header (hwcontext_*.h) and filled as described in the
  79. * documentation before calling av_hwdevice_ctx_init().
  80. *
  81. * After calling av_hwdevice_ctx_init() this struct should not be modified
  82. * by the caller.
  83. */
  84. void *hwctx;
  85. /**
  86. * This field may be set by the caller before calling av_hwdevice_ctx_init().
  87. *
  88. * If non-NULL, this callback will be called when the last reference to
  89. * this context is unreferenced, immediately before it is freed.
  90. *
  91. * @note when other objects (e.g an AVHWFramesContext) are derived from this
  92. * struct, this callback will be invoked after all such child objects
  93. * are fully uninitialized and their respective destructors invoked.
  94. */
  95. void (*free)(struct AVHWDeviceContext *ctx);
  96. /**
  97. * Arbitrary user data, to be used e.g. by the free() callback.
  98. */
  99. void *user_opaque;
  100. } AVHWDeviceContext;
  101. typedef struct AVHWFramesInternal AVHWFramesInternal;
  102. /**
  103. * This struct describes a set or pool of "hardware" frames (i.e. those with
  104. * data not located in normal system memory). All the frames in the pool are
  105. * assumed to be allocated in the same way and interchangeable.
  106. *
  107. * This struct is reference-counted with the AVBuffer mechanism and tied to a
  108. * given AVHWDeviceContext instance. The av_hwframe_ctx_alloc() constructor
  109. * yields a reference, whose data field points to the actual AVHWFramesContext
  110. * struct.
  111. */
  112. typedef struct AVHWFramesContext {
  113. /**
  114. * A class for logging.
  115. */
  116. const AVClass *av_class;
  117. /**
  118. * Private data used internally by libavutil. Must not be accessed in any
  119. * way by the caller.
  120. */
  121. AVHWFramesInternal *internal;
  122. /**
  123. * A reference to the parent AVHWDeviceContext. This reference is owned and
  124. * managed by the enclosing AVHWFramesContext, but the caller may derive
  125. * additional references from it.
  126. */
  127. AVBufferRef *device_ref;
  128. /**
  129. * The parent AVHWDeviceContext. This is simply a pointer to
  130. * device_ref->data provided for convenience.
  131. *
  132. * Set by libavutil in av_hwframe_ctx_init().
  133. */
  134. AVHWDeviceContext *device_ctx;
  135. /**
  136. * The format-specific data, allocated and freed automatically along with
  137. * this context.
  138. *
  139. * Should be cast by the user to the format-specific context defined in the
  140. * corresponding header (hwframe_*.h) and filled as described in the
  141. * documentation before calling av_hwframe_ctx_init().
  142. *
  143. * After any frames using this context are created, the contents of this
  144. * struct should not be modified by the caller.
  145. */
  146. void *hwctx;
  147. /**
  148. * This field may be set by the caller before calling av_hwframe_ctx_init().
  149. *
  150. * If non-NULL, this callback will be called when the last reference to
  151. * this context is unreferenced, immediately before it is freed.
  152. */
  153. void (*free)(struct AVHWFramesContext *ctx);
  154. /**
  155. * Arbitrary user data, to be used e.g. by the free() callback.
  156. */
  157. void *user_opaque;
  158. /**
  159. * A pool from which the frames are allocated by av_hwframe_get_buffer().
  160. * This field may be set by the caller before calling av_hwframe_ctx_init().
  161. * The buffers returned by calling av_buffer_pool_get() on this pool must
  162. * have the properties described in the documentation in the corresponding hw
  163. * type's header (hwcontext_*.h). The pool will be freed strictly before
  164. * this struct's free() callback is invoked.
  165. *
  166. * This field may be NULL, then libavutil will attempt to allocate a pool
  167. * internally. Note that certain device types enforce pools allocated at
  168. * fixed size (frame count), which cannot be extended dynamically. In such a
  169. * case, initial_pool_size must be set appropriately.
  170. */
  171. AVBufferPool *pool;
  172. /**
  173. * Initial size of the frame pool. If a device type does not support
  174. * dynamically resizing the pool, then this is also the maximum pool size.
  175. *
  176. * May be set by the caller before calling av_hwframe_ctx_init(). Must be
  177. * set if pool is NULL and the device type does not support dynamic pools.
  178. */
  179. int initial_pool_size;
  180. /**
  181. * The pixel format identifying the underlying HW surface type.
  182. *
  183. * Must be a hwaccel format, i.e. the corresponding descriptor must have the
  184. * AV_PIX_FMT_FLAG_HWACCEL flag set.
  185. *
  186. * Must be set by the user before calling av_hwframe_ctx_init().
  187. */
  188. enum AVPixelFormat format;
  189. /**
  190. * The pixel format identifying the actual data layout of the hardware
  191. * frames.
  192. *
  193. * Must be set by the caller before calling av_hwframe_ctx_init().
  194. *
  195. * @note when the underlying API does not provide the exact data layout, but
  196. * only the colorspace/bit depth, this field should be set to the fully
  197. * planar version of that format (e.g. for 8-bit 420 YUV it should be
  198. * AV_PIX_FMT_YUV420P, not AV_PIX_FMT_NV12 or anything else).
  199. */
  200. enum AVPixelFormat sw_format;
  201. /**
  202. * The allocated dimensions of the frames in this pool.
  203. *
  204. * Must be set by the user before calling av_hwframe_ctx_init().
  205. */
  206. int width, height;
  207. } AVHWFramesContext;
  208. /**
  209. * Look up an AVHWDeviceType by name.
  210. *
  211. * @param name String name of the device type (case-insensitive).
  212. * @return The type from enum AVHWDeviceType, or AV_HWDEVICE_TYPE_NONE if
  213. * not found.
  214. */
  215. enum AVHWDeviceType av_hwdevice_find_type_by_name(const char *name);
  216. /** 获取AVHWDeviceType的字符串名称。
  217. *
  218. * @param 枚举AVHWDeviceType中的type类型。
  219. * @return 指向包含名称的静态字符串的指针,如果类型无效,则为NULL。
  220. */
  221. const char *av_hwdevice_get_type_name(enum AVHWDeviceType type);
  222. /**
  223. * 遍历支持的设备类型。
  224. *
  225. * @param type 首先是AV_HWDEVICE_TYPE_NONE,然后是该函数在后续迭代中返回的前一个类型。
  226. * @return 枚举中下一个可用的设备类型为AVHWDeviceType,如果没有,则为AV_HWDEVICE_TYPE_NONE。
  227. */
  228. enum AVHWDeviceType av_hwdevice_iterate_types(enum AVHWDeviceType prev);
  229. /**
  230. * Allocate an AVHWDeviceContext for a given hardware type.
  231. *
  232. * @param type the type of the hardware device to allocate.
  233. * @return a reference to the newly created AVHWDeviceContext on success or NULL
  234. * on failure.
  235. */
  236. AVBufferRef *av_hwdevice_ctx_alloc(enum AVHWDeviceType type);
  237. /**
  238. * Finalize the device context before use. This function must be called after
  239. * the context is filled with all the required information and before it is
  240. * used in any way.
  241. *
  242. * @param ref a reference to the AVHWDeviceContext
  243. * @return 0 on success, a negative AVERROR code on failure
  244. */
  245. int av_hwdevice_ctx_init(AVBufferRef *ref);
  246. /**
  247. * 打开指定类型的设备,并为其创建AVHWDeviceContext。
  248. *
  249. * 这是一个方便的函数,旨在涵盖简单的情况。
  250. * 需要优化设备创建/管理的调用者应该手动打开设备,
  251. * 然后使用av_hwdevice_ctx_alloc()/av_hwdevice_ctx_init()将其包装在AVHWDeviceContext中。
  252. *
  253. * The returned context is already initialized and ready for use, the caller
  254. * should not call av_hwdevice_ctx_init() on it. The user_opaque/free fields of
  255. * the created AVHWDeviceContext are set by this function and should not be
  256. * touched by the caller.
  257. *
  258. * @param device_ctx 如果成功,将在这里写入对新创建的设备上下文的引用。
  259. * 引用由调用者拥有,当不再需要时,必须使用av_buffer_unref()释放它。
  260. * 如果失败,NULL将写入此指针。
  261. * @param type 要创建的设备的类型。
  262. * @param device 要创建的设备的类型。标识要打开的设备的类型特定字符串。
  263. * @param opts 打开设备时使用的附加(类型特定)选项的字典。词典仍归调用者所有。
  264. * @param flags 当前未使用
  265. *
  266. * @return 成功时为0,失败时为负AVERROR代码。
  267. */
  268. int av_hwdevice_ctx_create(AVBufferRef **device_ctx, enum AVHWDeviceType type,
  269. const char *device, AVDictionary *opts, int flags);
  270. /**
  271. * Create a new device of the specified type from an existing device.
  272. *
  273. * If the source device is a device of the target type or was originally
  274. * derived from such a device (possibly through one or more intermediate
  275. * devices of other types), then this will return a reference to the
  276. * existing device of the same type as is requested.
  277. *
  278. * Otherwise, it will attempt to derive a new device from the given source
  279. * device. If direct derivation to the new type is not implemented, it will
  280. * attempt the same derivation from each ancestor of the source device in
  281. * turn looking for an implemented derivation method.
  282. *
  283. * @param dst_ctx On success, a reference to the newly-created
  284. * AVHWDeviceContext.
  285. * @param type The type of the new device to create.
  286. * @param src_ctx A reference to an existing AVHWDeviceContext which will be
  287. * used to create the new device.
  288. * @param flags Currently unused; should be set to zero.
  289. * @return Zero on success, a negative AVERROR code on failure.
  290. */
  291. int av_hwdevice_ctx_create_derived(AVBufferRef **dst_ctx,
  292. enum AVHWDeviceType type,
  293. AVBufferRef *src_ctx, int flags);
  294. /**
  295. * Create a new device of the specified type from an existing device.
  296. *
  297. * This function performs the same action as av_hwdevice_ctx_create_derived,
  298. * however, it is able to set options for the new device to be derived.
  299. *
  300. * @param dst_ctx On success, a reference to the newly-created
  301. * AVHWDeviceContext.
  302. * @param type The type of the new device to create.
  303. * @param src_ctx A reference to an existing AVHWDeviceContext which will be
  304. * used to create the new device.
  305. * @param options Options for the new device to create, same format as in
  306. * av_hwdevice_ctx_create.
  307. * @param flags Currently unused; should be set to zero.
  308. * @return Zero on success, a negative AVERROR code on failure.
  309. */
  310. int av_hwdevice_ctx_create_derived_opts(AVBufferRef **dst_ctx,
  311. enum AVHWDeviceType type,
  312. AVBufferRef *src_ctx,
  313. AVDictionary *options, int flags);
  314. /**
  315. * Allocate an AVHWFramesContext tied to a given device context.
  316. *
  317. * @param device_ctx a reference to a AVHWDeviceContext. This function will make
  318. * a new reference for internal use, the one passed to the
  319. * function remains owned by the caller.
  320. * @return a reference to the newly created AVHWFramesContext on success or NULL
  321. * on failure.
  322. */
  323. AVBufferRef *av_hwframe_ctx_alloc(AVBufferRef *device_ctx);
  324. /**
  325. * Finalize the context before use. This function must be called after the
  326. * context is filled with all the required information and before it is attached
  327. * to any frames.
  328. *
  329. * @param ref a reference to the AVHWFramesContext
  330. * @return 0 on success, a negative AVERROR code on failure
  331. */
  332. int av_hwframe_ctx_init(AVBufferRef *ref);
  333. /**
  334. * Allocate a new frame attached to the given AVHWFramesContext.
  335. *
  336. * @param hwframe_ctx a reference to an AVHWFramesContext
  337. * @param frame an empty (freshly allocated or unreffed) frame to be filled with
  338. * newly allocated buffers.
  339. * @param flags currently unused, should be set to zero
  340. * @return 0 on success, a negative AVERROR code on failure
  341. */
  342. int av_hwframe_get_buffer(AVBufferRef *hwframe_ctx, AVFrame *frame, int flags);
  343. /**
  344. * 将数据复制到硬件表面或从硬件表面复制数据。dst/src中必须至少有一个附加了AVHWFramesContext。
  345. *
  346. * 如果src附加了AVHWFramesContext,那么dst的格式(如果设置了)必须使用av_hwframe_transfer_get_formats(src, AV_HWFRAME_TRANSFER_DIRECTION_FROM)返回的格式之一。
  347. * 如果dst附加了AVHWFramesContext,那么src的格式必须使用av_hwframe_transfer_get_formats(dst, AV_HWFRAME_TRANSFER_DIRECTION_TO)返回的格式之一。
  348. *
  349. * DST可能是“干净的”(即data/buf指针未设置),在这种情况下,数据缓冲区将由该函数使用av_frame_get_buffer()分配。
  350. * 如果dst->格式已设置,则将使用此格式,否则(当dst->格式为AV_PIX_FMT_NONE时)将选择第一个可接受的格式。
  351. *
  352. * 两个帧必须有匹配的分配尺寸(即等于AVHWFramesContext.width/height),因为不是所有的设备类型都支持传输整个表面的子矩形。
  353. * 显示尺寸(即AVFrame.width/height)可以小于分配的尺寸,但也必须为两个帧相等。
  354. * 当显示尺寸小于分配的尺寸时,将不指定目标帧中的填充内容
  355. *
  356. * @param dst the destination frame. dst is not touched on failure.
  357. * @param src the source frame.
  358. * @param flags 当前未使用,应设置为零
  359. * @return 0 on success, a negative AVERROR error code on failure.
  360. */
  361. int av_hwframe_transfer_data(AVFrame *dst, const AVFrame *src, int flags);
  362. enum AVHWFrameTransferDirection {
  363. /**
  364. * Transfer the data from the queried hw frame.
  365. */
  366. AV_HWFRAME_TRANSFER_DIRECTION_FROM,
  367. /**
  368. * Transfer the data to the queried hw frame.
  369. */
  370. AV_HWFRAME_TRANSFER_DIRECTION_TO,
  371. };
  372. /**
  373. * Get a list of possible source or target formats usable in
  374. * av_hwframe_transfer_data().
  375. *
  376. * @param hwframe_ctx the frame context to obtain the information for
  377. * @param dir the direction of the transfer
  378. * @param formats the pointer to the output format list will be written here.
  379. * The list is terminated with AV_PIX_FMT_NONE and must be freed
  380. * by the caller when no longer needed using av_free().
  381. * If this function returns successfully, the format list will
  382. * have at least one item (not counting the terminator).
  383. * On failure, the contents of this pointer are unspecified.
  384. * @param flags currently unused, should be set to zero
  385. * @return 0 on success, a negative AVERROR code on failure.
  386. */
  387. int av_hwframe_transfer_get_formats(AVBufferRef *hwframe_ctx,
  388. enum AVHWFrameTransferDirection dir,
  389. enum AVPixelFormat **formats, int flags);
  390. /**
  391. * This struct describes the constraints on hardware frames attached to
  392. * a given device with a hardware-specific configuration. This is returned
  393. * by av_hwdevice_get_hwframe_constraints() and must be freed by
  394. * av_hwframe_constraints_free() after use.
  395. */
  396. typedef struct AVHWFramesConstraints {
  397. /**
  398. * A list of possible values for format in the hw_frames_ctx,
  399. * terminated by AV_PIX_FMT_NONE. This member will always be filled.
  400. */
  401. enum AVPixelFormat *valid_hw_formats;
  402. /**
  403. * A list of possible values for sw_format in the hw_frames_ctx,
  404. * terminated by AV_PIX_FMT_NONE. Can be NULL if this information is
  405. * not known.
  406. */
  407. enum AVPixelFormat *valid_sw_formats;
  408. /**
  409. * The minimum size of frames in this hw_frames_ctx.
  410. * (Zero if not known.)
  411. */
  412. int min_width;
  413. int min_height;
  414. /**
  415. * The maximum size of frames in this hw_frames_ctx.
  416. * (INT_MAX if not known / no limit.)
  417. */
  418. int max_width;
  419. int max_height;
  420. } AVHWFramesConstraints;
  421. /**
  422. * Allocate a HW-specific configuration structure for a given HW device.
  423. * After use, the user must free all members as required by the specific
  424. * hardware structure being used, then free the structure itself with
  425. * av_free().
  426. *
  427. * @param device_ctx a reference to the associated AVHWDeviceContext.
  428. * @return The newly created HW-specific configuration structure on
  429. * success or NULL on failure.
  430. */
  431. void *av_hwdevice_hwconfig_alloc(AVBufferRef *device_ctx);
  432. /**
  433. * Get the constraints on HW frames given a device and the HW-specific
  434. * configuration to be used with that device. If no HW-specific
  435. * configuration is provided, returns the maximum possible capabilities
  436. * of the device.
  437. *
  438. * @param ref a reference to the associated AVHWDeviceContext.
  439. * @param hwconfig a filled HW-specific configuration structure, or NULL
  440. * to return the maximum possible capabilities of the device.
  441. * @return AVHWFramesConstraints structure describing the constraints
  442. * on the device, or NULL if not available.
  443. */
  444. AVHWFramesConstraints *av_hwdevice_get_hwframe_constraints(AVBufferRef *ref,
  445. const void *hwconfig);
  446. /**
  447. * Free an AVHWFrameConstraints structure.
  448. *
  449. * @param constraints The (filled or unfilled) AVHWFrameConstraints structure.
  450. */
  451. void av_hwframe_constraints_free(AVHWFramesConstraints **constraints);
  452. /**
  453. * Flags to apply to frame mappings.
  454. */
  455. enum {
  456. /**
  457. * The mapping must be readable.
  458. */
  459. AV_HWFRAME_MAP_READ = 1 << 0,
  460. /**
  461. * The mapping must be writeable.
  462. */
  463. AV_HWFRAME_MAP_WRITE = 1 << 1,
  464. /**
  465. * The mapped frame will be overwritten completely in subsequent
  466. * operations, so the current frame data need not be loaded. Any values
  467. * which are not overwritten are unspecified.
  468. */
  469. AV_HWFRAME_MAP_OVERWRITE = 1 << 2,
  470. /**
  471. * The mapping must be direct. That is, there must not be any copying in
  472. * the map or unmap steps. Note that performance of direct mappings may
  473. * be much lower than normal memory.
  474. */
  475. AV_HWFRAME_MAP_DIRECT = 1 << 3,
  476. };
  477. /**
  478. * Map a hardware frame.
  479. *
  480. * This has a number of different possible effects, depending on the format
  481. * and origin of the src and dst frames. On input, src should be a usable
  482. * frame with valid buffers and dst should be blank (typically as just created
  483. * by av_frame_alloc()). src should have an associated hwframe context, and
  484. * dst may optionally have a format and associated hwframe context.
  485. *
  486. * If src was created by mapping a frame from the hwframe context of dst,
  487. * then this function undoes the mapping - dst is replaced by a reference to
  488. * the frame that src was originally mapped from.
  489. *
  490. * If both src and dst have an associated hwframe context, then this function
  491. * attempts to map the src frame from its hardware context to that of dst and
  492. * then fill dst with appropriate data to be usable there. This will only be
  493. * possible if the hwframe contexts and associated devices are compatible -
  494. * given compatible devices, av_hwframe_ctx_create_derived() can be used to
  495. * create a hwframe context for dst in which mapping should be possible.
  496. *
  497. * If src has a hwframe context but dst does not, then the src frame is
  498. * mapped to normal memory and should thereafter be usable as a normal frame.
  499. * If the format is set on dst, then the mapping will attempt to create dst
  500. * with that format and fail if it is not possible. If format is unset (is
  501. * AV_PIX_FMT_NONE) then dst will be mapped with whatever the most appropriate
  502. * format to use is (probably the sw_format of the src hwframe context).
  503. *
  504. * A return value of AVERROR(ENOSYS) indicates that the mapping is not
  505. * possible with the given arguments and hwframe setup, while other return
  506. * values indicate that it failed somehow.
  507. *
  508. * On failure, the destination frame will be left blank, except for the
  509. * hw_frames_ctx/format fields thay may have been set by the caller - those will
  510. * be preserved as they were.
  511. *
  512. * @param dst Destination frame, to contain the mapping.
  513. * @param src Source frame, to be mapped.
  514. * @param flags Some combination of AV_HWFRAME_MAP_* flags.
  515. * @return Zero on success, negative AVERROR code on failure.
  516. */
  517. int av_hwframe_map(AVFrame *dst, const AVFrame *src, int flags);
  518. /**
  519. * Create and initialise an AVHWFramesContext as a mapping of another existing
  520. * AVHWFramesContext on a different device.
  521. *
  522. * av_hwframe_ctx_init() should not be called after this.
  523. *
  524. * @param derived_frame_ctx On success, a reference to the newly created
  525. * AVHWFramesContext.
  526. * @param derived_device_ctx A reference to the device to create the new
  527. * AVHWFramesContext on.
  528. * @param source_frame_ctx A reference to an existing AVHWFramesContext
  529. * which will be mapped to the derived context.
  530. * @param flags Some combination of AV_HWFRAME_MAP_* flags, defining the
  531. * mapping parameters to apply to frames which are allocated
  532. * in the derived device.
  533. * @return Zero on success, negative AVERROR code on failure.
  534. */
  535. int av_hwframe_ctx_create_derived(AVBufferRef **derived_frame_ctx,
  536. enum AVPixelFormat format,
  537. AVBufferRef *derived_device_ctx,
  538. AVBufferRef *source_frame_ctx,
  539. int flags);
  540. #endif /* AVUTIL_HWCONTEXT_H */