{"id":1107,"date":"2023-11-15T23:08:17","date_gmt":"2023-11-15T15:08:17","guid":{"rendered":"https:\/\/www.fanyamin.com\/wordpress\/?p=1107"},"modified":"2023-11-16T08:53:32","modified_gmt":"2023-11-16T00:53:32","slug":"1107","status":"publish","type":"post","link":"https:\/\/www.fanyamin.com\/wordpress\/?p=1107","title":{"rendered":"Caps Negotiation"},"content":{"rendered":"<p>Caps Negotiatio## Caps Negotiation \u80fd\u529b\u534f\u5546\u6982\u8ff0<\/p>\n<p>Caps negotiation is the act of finding a media format (GstCaps) between elements that they can handle. This process in GStreamer can in most cases find an optimal solution for the complete pipeline. <\/p>\n<p>\u80fd\u529b\u534f\u5546\u662f\u6307\u5728\u4e24\u4e2a\u5143\u7d20\u4e4b\u95f4\u5bfb\u627e\u4e00\u4e2a\u5f7c\u6b64\u53ef\u4ee5\u5904\u7406\u7684\u5a92\u4f53\u683c\u5f0f\uff0c\u5728 GStreamer \u4e2d\u591a\u6570\u60c5\u51b5\u4e0b\u662f\u4e3a\u4e86\u6574\u4e2a\u7ba1\u9053\u5bfb\u627e\u4e00\u4e2a\u4f18\u5316\u7684\u65b9\u6848\u3002<\/p>\n<h2>Caps negotiation basics<\/h2>\n<p>In GStreamer, negotiation of the media format always follows the following simple rules:<\/p>\n<p>\u5728 GStreamer \u4e2d\uff0c \u5a92\u4f53\u683c\u5f0f\u534f\u5546\u603b\u662f\u9075\u5faa\u4e0b\u9762\u51e0\u6761\u7b80\u5355\u7684\u89c4\u5219\uff1a<\/p>\n<ol>\n<li>A downstream element suggest a format on its sinkpad and places the suggestion in the result of the CAPS query performed on the sinkpad. See also Implementing a CAPS query function.<\/li>\n<\/ol>\n<p>\u4e0b\u6e38\u7684\u5143\u7d20\u5728\u5b83\u7684 sinkpad \u4e0a\u5efa\u8bae\u4e00\u4e2a\u683c\u5f0f\uff0c\u5e76\u5728 sinkpad \u7684 CAPS query \u7684\u7ed3\u679c\u653e\u7f6e\u8fd9\u4e2a\u5efa\u8bae<\/p>\n<ol start=\"2\">\n<li>An upstream element decides on a format. It sends the selected media format downstream on its source pad with a CAPS event. Downstream elements reconfigure themselves to handle the media type in the CAPS event on the sinkpad.<\/li>\n<\/ol>\n<p>\u4e0a\u6e38\u7684\u5143\u7d20\u51b3\u5b9a\u7528\u54ea\u79cd\u683c\u5f0f\u3002\u5b83\u7531\u5176 source pad \u53d1\u9001\u6240\u9009\u62e9\u7684\u5a92\u4f53\u683c\u5f0f\u901a\u8fc7 CAPS event \u5230\u4e0b\u6e38<br \/>\n\u4e0b\u6e38\u7684\u5143\u7d20\u5728\u5176 sink pad \u4e0a\u91cd\u65b0\u914d\u7f6e\u4ee5\u5904\u7406 CAPS event \u4e2d\u6307\u5b9a\u7684\u5a92\u4f53\u7c7b\u578b<\/p>\n<ol start=\"3\">\n<li>A downstream element can inform upstream that it would like to suggest a new format by sending a RECONFIGURE event upstream. The RECONFIGURE event simply instructs an upstream element to restart the negotiation phase. Because the element that sent out the RECONFIGURE event is now suggesting another format, the format in the pipeline might change.<\/li>\n<\/ol>\n<p>\u4e0b\u6e38\u7684\u5143\u7d20\u53ef\u901a\u77e5\u4e0a\u6e38\uff0c\u5373\u901a\u8fc7\u53d1\u9001\u4e00\u4e2a RECONFIGURE event \u5230\u4e0a\u6e38\u5143\u7d20\u6765\u5efa\u8bae\u4e00\u4e2a\u65b0\u7684\u683c\u5f0f<br \/>\nRECONFIGURE event \u7b80\u5355\u5730\u6307\u793a\u4e0a\u6e38\u7684\u5143\u7d20\u91cd\u542f\u534f\u5546\u8fc7\u7a0b\uff0c\u56e0\u4e3a\u53d1\u9001 RECONFIGURE event \u7684\u5143\u7d20\u8981\u5efa\u8bae\u53e6\u5916\u7684\u683c\u5f0f\uff0c\u7ba1\u9053\u4e2d\u7684\u683c\u5f0f\u53ef\u80fd\u4f1a\u6539\u53d8\u3002<\/p>\n<p>In addition to the CAPS and RECONFIGURE event and the CAPS query, there is an ACCEPT_CAPS query to quickly check if a certain caps can be accepted by an element.<\/p>\n<p>\u9664\u4e86 CAPS \u548c RECONFIGURE event, \u8fd8\u6709 CAPS query, \u8fd8\u6709 ACCEPT_CAPS query \u6765\u5feb\u901f\u68c0\u67e5\u662f\u5426\u4e00\u4e2a\u7279\u5b9a\u7684 caps \u53ef\u4ee5\u88ab\u53e6\u5916\u4e00\u4e2a\u5143\u7d20\u63a5\u53d7.<\/p>\n<p>Capabilities negotiation is the process of deciding on an adequate format for dataflow within a GStreamer pipeline. Ideally, negotiation (also known as &quot;capsnego&quot;) transfers information from those parts of the pipeline that have information to those parts of the pipeline that are flexible, constrained by those parts of the pipeline that are not flexible.<\/p>\n<h2>Basic rules<\/h2>\n<p>These simple rules must be followed:<\/p>\n<ul>\n<li>downstream suggests formats<\/li>\n<li>upstream decides on format<\/li>\n<\/ul>\n<h2>There are 4 queries\/events used in caps negotiation:<\/h2>\n<ul>\n<li>GST_QUERY_CAPS: get possible formats<\/li>\n<li>GST_QUERY_ACCEPT_CAPS: check if format is possible<\/li>\n<li>GST_EVENT_CAPS: configure format (downstream)<\/li>\n<li>GST_EVENT_RECONFIGURE: inform upstream of possibly new caps<\/li>\n<\/ul>\n<p>an example flow:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.fanyamin.com\/wordpress\/wp-content\/uploads\/2023\/11\/image-1700063136972.png\" alt=\"file\" \/><\/p>\n<p>\u4f2a\u4ee3\u7801<\/p>\n<pre><code>\n[element wants to create a buffer]\nif not format\n  # see what we can do\n  ourcaps = gst_pad_query_caps (srcpad)\n  # see what the peer can do filtered against our caps\n  candidates = gst_pad_peer_query_caps (srcpad, ourcaps)\n\n  foreach candidate in candidates\n    # make sure the caps is fixed\n    fixedcaps = gst_pad_fixate_caps (srcpad, candidate)\n\n    # see if the peer accepts it\n    if gst_pad_peer_accept_caps (srcpad, fixedcaps)\n      # store the caps as the negotiated caps, this will\n      # call the setcaps function on the pad\n      gst_pad_push_event (srcpad, gst_event_new_caps (fixedcaps))\n      break\n    endif\n  done\nendif<\/code><\/pre>\n<h2>\u80fd\u529b\u534f\u5546\u7528\u4f8b<\/h2>\n<p>In what follows we will look at some use cases for push-mode scheduling. The pull-mode scheduling negotiation phase is discussed in Pull-mode Caps negotiation and is actually similar as we will see.<\/p>\n<p>\u6211\u4eec\u5148\u770b\u770b\u4e00\u4e9b push-mode \u4f1a\u5546\u7684\u4f8b\u5b50, pull-mode \u4f1a\u5546\u7684\u4f8b\u5b50\u540e\u9762\u518d\u8bf4\uff0c\u5176\u5b9e\u5b83\u4eec\u5f88\u7c7b\u4f3c\u3002<br \/>\nsink pads \u53ea\u5efa\u8bae\u683c\u5f0f, \u800c source pads \u9700\u8981\u505a\u51b3\u5b9a\uff0c\u6700\u590d\u6742\u7684\u5de5\u4f5c\u5728 source pads \u4e2d\u5b8c\u6210\u3002<br \/>\n\u6211\u4eec\u53ef\u4ee5\u8bc6\u522b source pads \u7684 3 \u4e2a\u80fd\u529b\u534f\u5546\u7684\u7528\u4f8b <\/p>\n<ol>\n<li>Fixed negotiation. An element can output one format only. See Fixed negotiation.<\/li>\n<\/ol>\n<p>\u56fa\u5b9a\u534f\u5546\uff1a\u4e00\u4e2a\u5143\u7d20\u53ea\u53ef\u4ee5\u8f93\u51fa\u4e00\u79cd\u683c\u5f0f<\/p>\n<ol start=\"2\">\n<li>Transform negotiation. There is a (fixed) transform between the input and output format of the element, usually based on some element property. The caps that the element will produce depend on the upstream caps and the caps that the element can accept depend on the downstream caps. See Transform negotiation.<\/li>\n<\/ol>\n<p>\u8f6c\u6362\u534f\u5546\uff1a\u5143\u7d20\u53ef\u4ee5\u6709\u4e00\u4e2a\u8f93\u5165\u4e0e\u8f93\u51fa\u683c\u5f0f\u7684\u56fa\u5b9a\u8f6c\u6362\uff0c\u901a\u5e38\u57fa\u4e8e\u4e00\u4e9b\u5143\u7d20\u5c5e\u6027\u3002\u5143\u7d20\u5c06\u4ea7\u751f\u7684\u80fd\u529b\u53d6\u51b3\u4e8e\u4e0a\u6e38\u7684\u80fd\u529b, \u800c\u5143\u7d20\u53ef\u63a5\u53d7\u7684\u80fd\u529b\u53d6\u51b3\u4e8e\u4e0b\u6e38\u7684\u80fd\u529b<\/p>\n<ol start=\"3\">\n<li>Dynamic negotiation. An element can output many formats. \u00df<\/li>\n<\/ol>\n<p>\u52a8\u6001\u534f\u5546\uff1a\u4e00\u4e2a\u5143\u7d20\u53ef\u4ee5\u8f93\u51fa\u8bb8\u591a\u683c\u5f0f<\/p>\n<h2>Reference<\/h2>\n<ul>\n<li><a href=\"https:\/\/gstreamer.freedesktop.org\/documentation\/plugin-development\/advanced\/negotiation.html?gi-language=c\">caps negotiation concepts<\/a><\/li>\n<li><a href=\"https:\/\/gstreamer.freedesktop.org\/documentation\/additional\/design\/negotiation.html?gi-language=c\">caps negotiation flow<\/a><\/li>\n<li><a href=\"https:\/\/gstreamer.freedesktop.org\/documentation\/gstreamer\/gstquery.html?gi-language=c#function-macros\">GstQuery<\/a><\/li>\n<li><a href=\"https:\/\/gstreamer.freedesktop.org\/documentation\/gstreamer\/gstpad.html?gi-language=c\">GstPad<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Caps Negotiatio## Caps Negotiation \u80fd\u529b\u534f\u5546\u6982\u8ff0 Caps negotiation is the act of finding a media format (GstCaps) between elements that they can handle. This process in GStreamer can in most cases find an optimal solution for the complete pipeline. \u80fd\u529b\u534f\u5546\u662f\u6307\u5728\u4e24\u4e2a\u5143\u7d20\u4e4b\u95f4\u5bfb\u627e\u4e00\u4e2a\u5f7c\u6b64\u53ef\u4ee5\u5904\u7406\u7684\u5a92\u4f53\u683c\u5f0f\uff0c\u5728 GStreamer \u4e2d\u591a\u6570\u60c5\u51b5\u4e0b\u662f\u4e3a\u4e86\u6574\u4e2a\u7ba1\u9053\u5bfb\u627e\u4e00\u4e2a\u4f18\u5316\u7684\u65b9\u6848\u3002 Caps negotiation basics In GStreamer, negotiation of the media format always follows the following [&hellip;] <a class=\"read-more\" href=\"https:\/\/www.fanyamin.com\/wordpress\/?p=1107\" title=\"Permanent Link to: Caps Negotiation\">&rarr;Read&nbsp;more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1107","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1107"}],"collection":[{"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1107"}],"version-history":[{"count":7,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1107\/revisions"}],"predecessor-version":[{"id":1116,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1107\/revisions\/1116"}],"wp:attachment":[{"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1107"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1107"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1107"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}