├── .gitignore ├── LICENSE ├── README.md ├── binding.cpp ├── binding.gyp ├── index.js ├── package.json ├── samples └── sample.js └── src ├── controller ├── controller.cpp └── controller.h ├── libavutil └── pixfmt.h └── queue ├── LICENSE ├── README ├── share_queue.h ├── share_queue_write.cpp ├── share_queue_write.h └── util.h /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | build 3 | *.log -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # node-virtualcam 2 | 3 | NOTE: This package is a work-in-progress. No support is provided, use at own risk. 4 | 5 | ## Installation 6 | 7 | This package is Windows-only for now. 8 | 9 | From admin command prompt: 10 | ```sh 11 | npm install --global --production windows-build-tools --vs2015 12 | ``` 13 | If this gets stuck, see https://github.com/felixrieseberg/windows-build-tools/issues/172#issuecomment-484091133. 14 | Also, see [StackOverflow](https://stackoverflow.com/questions/21658832/npm-install-error-msb3428-could-not-load-the-visual-c-component-vcbuild-ex#comment91997415_39235952) on why `--vs2015` is needed. 15 | 16 | Install/build package: 17 | ```sh 18 | npm install 19 | ``` 20 | 21 | Run sample: 22 | ```sh 23 | node samples\sample.js 24 | ``` 25 | 26 | The package uses [obs-virtual-cam](https://github.com/Fenrirthviti/obs-virtual-cam/releases) which has to be installed separately. Note that the obs-virtual-cam installer assumes an OBS Studio installation and will fail otherwise. You can also download and extract the obs-virtual-cam zip package directly without installing OBS Studio. After unzipping, simply run `regsvr32 /n /i:1 "obs-virtualcam\bin\32bit\obs-virtualsource.dll"` from an elevated command prompt to install the virtual camera device. Use `regsvr32 /u "obs-virtualcam\bin\32bit\obs-virtualsource.dll"` to uninstall it again. 27 | 28 | 29 | -------------------------------------------------------------------------------- /binding.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "controller/controller.h" 4 | 5 | NAN_METHOD(start) { 6 | int width = Nan::To(info[0]).FromJust(); 7 | int height = Nan::To(info[1]).FromJust(); 8 | double fps = Nan::To(info[2]).FromJust(); 9 | int delay = Nan::To(info[3]).FromJust(); 10 | if (!virtual_output_start(width, height, fps, delay)) 11 | throw std::runtime_error("error starting virtual camera output"); 12 | } 13 | 14 | NAN_METHOD(stop) { 15 | virtual_output_stop(); 16 | } 17 | 18 | NAN_METHOD(send) { 19 | if (!virtual_output_is_running()) 20 | return; 21 | int64_t timestamp = Nan::To(info[0]).FromJust(); 22 | v8::Local ta = info[1].As(); 23 | Nan::TypedArrayContents frame(ta); 24 | uint8_t* buf = *frame; 25 | if (buf == nullptr) 26 | throw std::runtime_error("invalid frame (not a uint8 typed array)"); 27 | int width, height; 28 | virtual_output_size(&width, &height); 29 | size_t n_lines = height; 30 | size_t line_size = width * 4; 31 | if (frame.length() != n_lines * line_size) 32 | throw std::runtime_error("frame has incorrect size, must be (h,w,c=4) in C memory layout"); 33 | uint8_t** data = (uint8_t**) malloc(sizeof(uint8_t*) * n_lines); 34 | for (size_t i=0; i < n_lines; i++) 35 | data[i] = buf + i*line_size; 36 | virtual_video(timestamp, data); 37 | free(data); 38 | } 39 | 40 | NAN_MODULE_INIT(InitAll) { 41 | Nan::Set(target, Nan::New("start").ToLocalChecked(), 42 | Nan::GetFunction(Nan::New(start)).ToLocalChecked()); 43 | 44 | Nan::Set(target, Nan::New("stop").ToLocalChecked(), 45 | Nan::GetFunction(Nan::New(stop)).ToLocalChecked()); 46 | 47 | Nan::Set(target, Nan::New("send").ToLocalChecked(), 48 | Nan::GetFunction(Nan::New(send)).ToLocalChecked()); 49 | } 50 | 51 | NODE_MODULE(binding, InitAll) 52 | -------------------------------------------------------------------------------- /binding.gyp: -------------------------------------------------------------------------------- 1 | { 2 | 'targets': [ 3 | { 4 | 'target_name': 'binding', 5 | 'sources': [ 'binding.cpp', 'src/controller/controller.cpp', 'src/queue/share_queue_write.cpp' ], 6 | 'include_dirs': [ 7 | 'src', 8 | " { 13 | clearInterval(timerId); 14 | virtualcam.stop(); 15 | console.log('virtual cam output stopped'); 16 | process.exit(1); 17 | }); 18 | 19 | virtualcam.start(width, height, fps, delay); 20 | console.log(`virtual cam output started (${width}x${height} @ ${fps}fps)`); 21 | 22 | let i = 0; 23 | timerId = setInterval(() => { 24 | const frame = new Uint8Array(height * width * 4); 25 | frame.fill(i % 255); 26 | virtualcam.send(i, frame); 27 | i += 1; 28 | }, frameMs); 29 | -------------------------------------------------------------------------------- /src/controller/controller.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "queue/share_queue.h" 3 | #include "queue/share_queue_write.h" 4 | #include "controller.h" 5 | 6 | struct virtual_out_data { 7 | share_queue video_queue; 8 | int width = 0; 9 | int height = 0; 10 | int delay = 0; 11 | int64_t last_video_ts = 0; 12 | }; 13 | 14 | struct virtual_out_data *virtual_out; 15 | bool output_running = false; 16 | 17 | bool virtual_output_start(int width, int height, double fps, int delay) 18 | { 19 | if (virtual_out) { 20 | fprintf(stderr, "virtual camera output already started\n"); 21 | return false; 22 | } 23 | virtual_out = (virtual_out_data*) malloc(sizeof(struct virtual_out_data)); 24 | 25 | bool start = false; 26 | virtual_out_data* out_data = (virtual_out_data*)virtual_out; 27 | out_data->delay = delay; 28 | out_data->width = width; 29 | out_data->height = height; 30 | uint64_t interval = static_cast(1000000000 / fps); 31 | 32 | start = shared_queue_create(&out_data->video_queue, 33 | ModeVideo, AV_PIX_FMT_RGBA, out_data->width, out_data->height, 34 | interval, out_data->delay + 10); 35 | 36 | if (start) { 37 | output_running = true; 38 | shared_queue_set_delay(&out_data->video_queue, out_data->delay); 39 | } else { 40 | output_running = false; 41 | shared_queue_write_close(&out_data->video_queue); 42 | 43 | fprintf(stderr, "shared_queue_create() failed\n"); 44 | } 45 | 46 | return start; 47 | } 48 | 49 | void virtual_output_size(int *width, int *height) 50 | { 51 | if (!virtual_out) { 52 | return; 53 | } 54 | *width = virtual_out->width; 55 | *height = virtual_out->height; 56 | } 57 | 58 | void virtual_output_stop() 59 | { 60 | if (!virtual_out) { 61 | return; 62 | } 63 | shared_queue_write_close(&virtual_out->video_queue); 64 | free(virtual_out); 65 | output_running = false; 66 | } 67 | 68 | // data is in RGBA format (packed RGBA 8:8:8:8, 32bpp, RGBARGBA...) 69 | // TODO RGB24 would be better but not supported in obs-virtual-cam 70 | void virtual_video(int64_t timestamp, uint8_t **data) 71 | { 72 | if (!output_running) 73 | return; 74 | 75 | uint32_t linesize[1] = {virtual_out->width * 4}; 76 | 77 | virtual_out_data *out_data = (virtual_out_data*)virtual_out; 78 | out_data->last_video_ts = timestamp; 79 | shared_queue_push_video(&out_data->video_queue, linesize, 80 | out_data->width, out_data->height, data, timestamp); 81 | } 82 | 83 | bool virtual_output_is_running() 84 | { 85 | return output_running; 86 | } 87 | -------------------------------------------------------------------------------- /src/controller/controller.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | bool virtual_output_start(int width, int height, double fps, int delay); 6 | void virtual_output_stop(); 7 | void virtual_output_size(int *width, int *height); 8 | void virtual_video(int64_t timestamp, uint8_t **data); 9 | bool virtual_output_is_running(); 10 | -------------------------------------------------------------------------------- /src/libavutil/pixfmt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) 2006 Michael Niedermayer 3 | * 4 | * This file is part of FFmpeg. 5 | * 6 | * FFmpeg is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * FFmpeg is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with FFmpeg; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef AVUTIL_PIXFMT_H 22 | #define AVUTIL_PIXFMT_H 23 | 24 | /** 25 | * @file 26 | * pixel format definitions 27 | */ 28 | 29 | #define AVPALETTE_SIZE 1024 30 | #define AVPALETTE_COUNT 256 31 | 32 | /** 33 | * Pixel format. 34 | * 35 | * @note 36 | * AV_PIX_FMT_RGB32 is handled in an endian-specific manner. An RGBA 37 | * color is put together as: 38 | * (A << 24) | (R << 16) | (G << 8) | B 39 | * This is stored as BGRA on little-endian CPU architectures and ARGB on 40 | * big-endian CPUs. 41 | * 42 | * @note 43 | * If the resolution is not a multiple of the chroma subsampling factor 44 | * then the chroma plane resolution must be rounded up. 45 | * 46 | * @par 47 | * When the pixel format is palettized RGB32 (AV_PIX_FMT_PAL8), the palettized 48 | * image data is stored in AVFrame.data[0]. The palette is transported in 49 | * AVFrame.data[1], is 1024 bytes long (256 4-byte entries) and is 50 | * formatted the same as in AV_PIX_FMT_RGB32 described above (i.e., it is 51 | * also endian-specific). Note also that the individual RGB32 palette 52 | * components stored in AVFrame.data[1] should be in the range 0..255. 53 | * This is important as many custom PAL8 video codecs that were designed 54 | * to run on the IBM VGA graphics adapter use 6-bit palette components. 55 | * 56 | * @par 57 | * For all the 8 bits per pixel formats, an RGB32 palette is in data[1] like 58 | * for pal8. This palette is filled in automatically by the function 59 | * allocating the picture. 60 | */ 61 | enum AVPixelFormat { 62 | AV_PIX_FMT_NONE = -1, 63 | AV_PIX_FMT_YUV420P, ///< planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples) 64 | AV_PIX_FMT_YUYV422, ///< packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr 65 | AV_PIX_FMT_RGB24, ///< packed RGB 8:8:8, 24bpp, RGBRGB... 66 | AV_PIX_FMT_BGR24, ///< packed RGB 8:8:8, 24bpp, BGRBGR... 67 | AV_PIX_FMT_YUV422P, ///< planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples) 68 | AV_PIX_FMT_YUV444P, ///< planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples) 69 | AV_PIX_FMT_YUV410P, ///< planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples) 70 | AV_PIX_FMT_YUV411P, ///< planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) 71 | AV_PIX_FMT_GRAY8, ///< Y , 8bpp 72 | AV_PIX_FMT_MONOWHITE, ///< Y , 1bpp, 0 is white, 1 is black, in each byte pixels are ordered from the msb to the lsb 73 | AV_PIX_FMT_MONOBLACK, ///< Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb 74 | AV_PIX_FMT_PAL8, ///< 8 bits with AV_PIX_FMT_RGB32 palette 75 | AV_PIX_FMT_YUVJ420P, ///< planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting color_range 76 | AV_PIX_FMT_YUVJ422P, ///< planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting color_range 77 | AV_PIX_FMT_YUVJ444P, ///< planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting color_range 78 | AV_PIX_FMT_UYVY422, ///< packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1 79 | AV_PIX_FMT_UYYVYY411, ///< packed YUV 4:1:1, 12bpp, Cb Y0 Y1 Cr Y2 Y3 80 | AV_PIX_FMT_BGR8, ///< packed RGB 3:3:2, 8bpp, (msb)2B 3G 3R(lsb) 81 | AV_PIX_FMT_BGR4, ///< packed RGB 1:2:1 bitstream, 4bpp, (msb)1B 2G 1R(lsb), a byte contains two pixels, the first pixel in the byte is the one composed by the 4 msb bits 82 | AV_PIX_FMT_BGR4_BYTE, ///< packed RGB 1:2:1, 8bpp, (msb)1B 2G 1R(lsb) 83 | AV_PIX_FMT_RGB8, ///< packed RGB 3:3:2, 8bpp, (msb)2R 3G 3B(lsb) 84 | AV_PIX_FMT_RGB4, ///< packed RGB 1:2:1 bitstream, 4bpp, (msb)1R 2G 1B(lsb), a byte contains two pixels, the first pixel in the byte is the one composed by the 4 msb bits 85 | AV_PIX_FMT_RGB4_BYTE, ///< packed RGB 1:2:1, 8bpp, (msb)1R 2G 1B(lsb) 86 | AV_PIX_FMT_NV12, ///< planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (first byte U and the following byte V) 87 | AV_PIX_FMT_NV21, ///< as above, but U and V bytes are swapped 88 | 89 | AV_PIX_FMT_ARGB, ///< packed ARGB 8:8:8:8, 32bpp, ARGBARGB... 90 | AV_PIX_FMT_RGBA, ///< packed RGBA 8:8:8:8, 32bpp, RGBARGBA... 91 | AV_PIX_FMT_ABGR, ///< packed ABGR 8:8:8:8, 32bpp, ABGRABGR... 92 | AV_PIX_FMT_BGRA, ///< packed BGRA 8:8:8:8, 32bpp, BGRABGRA... 93 | 94 | AV_PIX_FMT_GRAY16BE, ///< Y , 16bpp, big-endian 95 | AV_PIX_FMT_GRAY16LE, ///< Y , 16bpp, little-endian 96 | AV_PIX_FMT_YUV440P, ///< planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples) 97 | AV_PIX_FMT_YUVJ440P, ///< planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range 98 | AV_PIX_FMT_YUVA420P, ///< planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples) 99 | AV_PIX_FMT_RGB48BE, ///< packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as big-endian 100 | AV_PIX_FMT_RGB48LE, ///< packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as little-endian 101 | 102 | AV_PIX_FMT_RGB565BE, ///< packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), big-endian 103 | AV_PIX_FMT_RGB565LE, ///< packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), little-endian 104 | AV_PIX_FMT_RGB555BE, ///< packed RGB 5:5:5, 16bpp, (msb)1X 5R 5G 5B(lsb), big-endian , X=unused/undefined 105 | AV_PIX_FMT_RGB555LE, ///< packed RGB 5:5:5, 16bpp, (msb)1X 5R 5G 5B(lsb), little-endian, X=unused/undefined 106 | 107 | AV_PIX_FMT_BGR565BE, ///< packed BGR 5:6:5, 16bpp, (msb) 5B 6G 5R(lsb), big-endian 108 | AV_PIX_FMT_BGR565LE, ///< packed BGR 5:6:5, 16bpp, (msb) 5B 6G 5R(lsb), little-endian 109 | AV_PIX_FMT_BGR555BE, ///< packed BGR 5:5:5, 16bpp, (msb)1X 5B 5G 5R(lsb), big-endian , X=unused/undefined 110 | AV_PIX_FMT_BGR555LE, ///< packed BGR 5:5:5, 16bpp, (msb)1X 5B 5G 5R(lsb), little-endian, X=unused/undefined 111 | 112 | #if FF_API_VAAPI 113 | /** @name Deprecated pixel formats */ 114 | /**@{*/ 115 | AV_PIX_FMT_VAAPI_MOCO, ///< HW acceleration through VA API at motion compensation entry-point, Picture.data[3] contains a vaapi_render_state struct which contains macroblocks as well as various fields extracted from headers 116 | AV_PIX_FMT_VAAPI_IDCT, ///< HW acceleration through VA API at IDCT entry-point, Picture.data[3] contains a vaapi_render_state struct which contains fields extracted from headers 117 | AV_PIX_FMT_VAAPI_VLD, ///< HW decoding through VA API, Picture.data[3] contains a VASurfaceID 118 | /**@}*/ 119 | AV_PIX_FMT_VAAPI = AV_PIX_FMT_VAAPI_VLD, 120 | #else 121 | /** 122 | * Hardware acceleration through VA-API, data[3] contains a 123 | * VASurfaceID. 124 | */ 125 | AV_PIX_FMT_VAAPI, 126 | #endif 127 | 128 | AV_PIX_FMT_YUV420P16LE, ///< planar YUV 4:2:0, 24bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian 129 | AV_PIX_FMT_YUV420P16BE, ///< planar YUV 4:2:0, 24bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian 130 | AV_PIX_FMT_YUV422P16LE, ///< planar YUV 4:2:2, 32bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian 131 | AV_PIX_FMT_YUV422P16BE, ///< planar YUV 4:2:2, 32bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian 132 | AV_PIX_FMT_YUV444P16LE, ///< planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian 133 | AV_PIX_FMT_YUV444P16BE, ///< planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian 134 | AV_PIX_FMT_DXVA2_VLD, ///< HW decoding through DXVA2, Picture.data[3] contains a LPDIRECT3DSURFACE9 pointer 135 | 136 | AV_PIX_FMT_RGB444LE, ///< packed RGB 4:4:4, 16bpp, (msb)4X 4R 4G 4B(lsb), little-endian, X=unused/undefined 137 | AV_PIX_FMT_RGB444BE, ///< packed RGB 4:4:4, 16bpp, (msb)4X 4R 4G 4B(lsb), big-endian, X=unused/undefined 138 | AV_PIX_FMT_BGR444LE, ///< packed BGR 4:4:4, 16bpp, (msb)4X 4B 4G 4R(lsb), little-endian, X=unused/undefined 139 | AV_PIX_FMT_BGR444BE, ///< packed BGR 4:4:4, 16bpp, (msb)4X 4B 4G 4R(lsb), big-endian, X=unused/undefined 140 | AV_PIX_FMT_YA8, ///< 8 bits gray, 8 bits alpha 141 | 142 | AV_PIX_FMT_Y400A = AV_PIX_FMT_YA8, ///< alias for AV_PIX_FMT_YA8 143 | AV_PIX_FMT_GRAY8A= AV_PIX_FMT_YA8, ///< alias for AV_PIX_FMT_YA8 144 | 145 | AV_PIX_FMT_BGR48BE, ///< packed RGB 16:16:16, 48bpp, 16B, 16G, 16R, the 2-byte value for each R/G/B component is stored as big-endian 146 | AV_PIX_FMT_BGR48LE, ///< packed RGB 16:16:16, 48bpp, 16B, 16G, 16R, the 2-byte value for each R/G/B component is stored as little-endian 147 | 148 | /** 149 | * The following 12 formats have the disadvantage of needing 1 format for each bit depth. 150 | * Notice that each 9/10 bits sample is stored in 16 bits with extra padding. 151 | * If you want to support multiple bit depths, then using AV_PIX_FMT_YUV420P16* with the bpp stored separately is better. 152 | */ 153 | AV_PIX_FMT_YUV420P9BE, ///< planar YUV 4:2:0, 13.5bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian 154 | AV_PIX_FMT_YUV420P9LE, ///< planar YUV 4:2:0, 13.5bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian 155 | AV_PIX_FMT_YUV420P10BE,///< planar YUV 4:2:0, 15bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian 156 | AV_PIX_FMT_YUV420P10LE,///< planar YUV 4:2:0, 15bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian 157 | AV_PIX_FMT_YUV422P10BE,///< planar YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian 158 | AV_PIX_FMT_YUV422P10LE,///< planar YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian 159 | AV_PIX_FMT_YUV444P9BE, ///< planar YUV 4:4:4, 27bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian 160 | AV_PIX_FMT_YUV444P9LE, ///< planar YUV 4:4:4, 27bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian 161 | AV_PIX_FMT_YUV444P10BE,///< planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian 162 | AV_PIX_FMT_YUV444P10LE,///< planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian 163 | AV_PIX_FMT_YUV422P9BE, ///< planar YUV 4:2:2, 18bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian 164 | AV_PIX_FMT_YUV422P9LE, ///< planar YUV 4:2:2, 18bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian 165 | AV_PIX_FMT_GBRP, ///< planar GBR 4:4:4 24bpp 166 | AV_PIX_FMT_GBR24P = AV_PIX_FMT_GBRP, // alias for #AV_PIX_FMT_GBRP 167 | AV_PIX_FMT_GBRP9BE, ///< planar GBR 4:4:4 27bpp, big-endian 168 | AV_PIX_FMT_GBRP9LE, ///< planar GBR 4:4:4 27bpp, little-endian 169 | AV_PIX_FMT_GBRP10BE, ///< planar GBR 4:4:4 30bpp, big-endian 170 | AV_PIX_FMT_GBRP10LE, ///< planar GBR 4:4:4 30bpp, little-endian 171 | AV_PIX_FMT_GBRP16BE, ///< planar GBR 4:4:4 48bpp, big-endian 172 | AV_PIX_FMT_GBRP16LE, ///< planar GBR 4:4:4 48bpp, little-endian 173 | AV_PIX_FMT_YUVA422P, ///< planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples) 174 | AV_PIX_FMT_YUVA444P, ///< planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples) 175 | AV_PIX_FMT_YUVA420P9BE, ///< planar YUV 4:2:0 22.5bpp, (1 Cr & Cb sample per 2x2 Y & A samples), big-endian 176 | AV_PIX_FMT_YUVA420P9LE, ///< planar YUV 4:2:0 22.5bpp, (1 Cr & Cb sample per 2x2 Y & A samples), little-endian 177 | AV_PIX_FMT_YUVA422P9BE, ///< planar YUV 4:2:2 27bpp, (1 Cr & Cb sample per 2x1 Y & A samples), big-endian 178 | AV_PIX_FMT_YUVA422P9LE, ///< planar YUV 4:2:2 27bpp, (1 Cr & Cb sample per 2x1 Y & A samples), little-endian 179 | AV_PIX_FMT_YUVA444P9BE, ///< planar YUV 4:4:4 36bpp, (1 Cr & Cb sample per 1x1 Y & A samples), big-endian 180 | AV_PIX_FMT_YUVA444P9LE, ///< planar YUV 4:4:4 36bpp, (1 Cr & Cb sample per 1x1 Y & A samples), little-endian 181 | AV_PIX_FMT_YUVA420P10BE, ///< planar YUV 4:2:0 25bpp, (1 Cr & Cb sample per 2x2 Y & A samples, big-endian) 182 | AV_PIX_FMT_YUVA420P10LE, ///< planar YUV 4:2:0 25bpp, (1 Cr & Cb sample per 2x2 Y & A samples, little-endian) 183 | AV_PIX_FMT_YUVA422P10BE, ///< planar YUV 4:2:2 30bpp, (1 Cr & Cb sample per 2x1 Y & A samples, big-endian) 184 | AV_PIX_FMT_YUVA422P10LE, ///< planar YUV 4:2:2 30bpp, (1 Cr & Cb sample per 2x1 Y & A samples, little-endian) 185 | AV_PIX_FMT_YUVA444P10BE, ///< planar YUV 4:4:4 40bpp, (1 Cr & Cb sample per 1x1 Y & A samples, big-endian) 186 | AV_PIX_FMT_YUVA444P10LE, ///< planar YUV 4:4:4 40bpp, (1 Cr & Cb sample per 1x1 Y & A samples, little-endian) 187 | AV_PIX_FMT_YUVA420P16BE, ///< planar YUV 4:2:0 40bpp, (1 Cr & Cb sample per 2x2 Y & A samples, big-endian) 188 | AV_PIX_FMT_YUVA420P16LE, ///< planar YUV 4:2:0 40bpp, (1 Cr & Cb sample per 2x2 Y & A samples, little-endian) 189 | AV_PIX_FMT_YUVA422P16BE, ///< planar YUV 4:2:2 48bpp, (1 Cr & Cb sample per 2x1 Y & A samples, big-endian) 190 | AV_PIX_FMT_YUVA422P16LE, ///< planar YUV 4:2:2 48bpp, (1 Cr & Cb sample per 2x1 Y & A samples, little-endian) 191 | AV_PIX_FMT_YUVA444P16BE, ///< planar YUV 4:4:4 64bpp, (1 Cr & Cb sample per 1x1 Y & A samples, big-endian) 192 | AV_PIX_FMT_YUVA444P16LE, ///< planar YUV 4:4:4 64bpp, (1 Cr & Cb sample per 1x1 Y & A samples, little-endian) 193 | 194 | AV_PIX_FMT_VDPAU, ///< HW acceleration through VDPAU, Picture.data[3] contains a VdpVideoSurface 195 | 196 | AV_PIX_FMT_XYZ12LE, ///< packed XYZ 4:4:4, 36 bpp, (msb) 12X, 12Y, 12Z (lsb), the 2-byte value for each X/Y/Z is stored as little-endian, the 4 lower bits are set to 0 197 | AV_PIX_FMT_XYZ12BE, ///< packed XYZ 4:4:4, 36 bpp, (msb) 12X, 12Y, 12Z (lsb), the 2-byte value for each X/Y/Z is stored as big-endian, the 4 lower bits are set to 0 198 | AV_PIX_FMT_NV16, ///< interleaved chroma YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples) 199 | AV_PIX_FMT_NV20LE, ///< interleaved chroma YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian 200 | AV_PIX_FMT_NV20BE, ///< interleaved chroma YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian 201 | 202 | AV_PIX_FMT_RGBA64BE, ///< packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is stored as big-endian 203 | AV_PIX_FMT_RGBA64LE, ///< packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is stored as little-endian 204 | AV_PIX_FMT_BGRA64BE, ///< packed RGBA 16:16:16:16, 64bpp, 16B, 16G, 16R, 16A, the 2-byte value for each R/G/B/A component is stored as big-endian 205 | AV_PIX_FMT_BGRA64LE, ///< packed RGBA 16:16:16:16, 64bpp, 16B, 16G, 16R, 16A, the 2-byte value for each R/G/B/A component is stored as little-endian 206 | 207 | AV_PIX_FMT_YVYU422, ///< packed YUV 4:2:2, 16bpp, Y0 Cr Y1 Cb 208 | 209 | AV_PIX_FMT_YA16BE, ///< 16 bits gray, 16 bits alpha (big-endian) 210 | AV_PIX_FMT_YA16LE, ///< 16 bits gray, 16 bits alpha (little-endian) 211 | 212 | AV_PIX_FMT_GBRAP, ///< planar GBRA 4:4:4:4 32bpp 213 | AV_PIX_FMT_GBRAP16BE, ///< planar GBRA 4:4:4:4 64bpp, big-endian 214 | AV_PIX_FMT_GBRAP16LE, ///< planar GBRA 4:4:4:4 64bpp, little-endian 215 | /** 216 | * HW acceleration through QSV, data[3] contains a pointer to the 217 | * mfxFrameSurface1 structure. 218 | */ 219 | AV_PIX_FMT_QSV, 220 | /** 221 | * HW acceleration though MMAL, data[3] contains a pointer to the 222 | * MMAL_BUFFER_HEADER_T structure. 223 | */ 224 | AV_PIX_FMT_MMAL, 225 | 226 | AV_PIX_FMT_D3D11VA_VLD, ///< HW decoding through Direct3D11 via old API, Picture.data[3] contains a ID3D11VideoDecoderOutputView pointer 227 | 228 | /** 229 | * HW acceleration through CUDA. data[i] contain CUdeviceptr pointers 230 | * exactly as for system memory frames. 231 | */ 232 | AV_PIX_FMT_CUDA, 233 | 234 | AV_PIX_FMT_0RGB, ///< packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined 235 | AV_PIX_FMT_RGB0, ///< packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined 236 | AV_PIX_FMT_0BGR, ///< packed BGR 8:8:8, 32bpp, XBGRXBGR... X=unused/undefined 237 | AV_PIX_FMT_BGR0, ///< packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined 238 | 239 | AV_PIX_FMT_YUV420P12BE, ///< planar YUV 4:2:0,18bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian 240 | AV_PIX_FMT_YUV420P12LE, ///< planar YUV 4:2:0,18bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian 241 | AV_PIX_FMT_YUV420P14BE, ///< planar YUV 4:2:0,21bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian 242 | AV_PIX_FMT_YUV420P14LE, ///< planar YUV 4:2:0,21bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian 243 | AV_PIX_FMT_YUV422P12BE, ///< planar YUV 4:2:2,24bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian 244 | AV_PIX_FMT_YUV422P12LE, ///< planar YUV 4:2:2,24bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian 245 | AV_PIX_FMT_YUV422P14BE, ///< planar YUV 4:2:2,28bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian 246 | AV_PIX_FMT_YUV422P14LE, ///< planar YUV 4:2:2,28bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian 247 | AV_PIX_FMT_YUV444P12BE, ///< planar YUV 4:4:4,36bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian 248 | AV_PIX_FMT_YUV444P12LE, ///< planar YUV 4:4:4,36bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian 249 | AV_PIX_FMT_YUV444P14BE, ///< planar YUV 4:4:4,42bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian 250 | AV_PIX_FMT_YUV444P14LE, ///< planar YUV 4:4:4,42bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian 251 | AV_PIX_FMT_GBRP12BE, ///< planar GBR 4:4:4 36bpp, big-endian 252 | AV_PIX_FMT_GBRP12LE, ///< planar GBR 4:4:4 36bpp, little-endian 253 | AV_PIX_FMT_GBRP14BE, ///< planar GBR 4:4:4 42bpp, big-endian 254 | AV_PIX_FMT_GBRP14LE, ///< planar GBR 4:4:4 42bpp, little-endian 255 | AV_PIX_FMT_YUVJ411P, ///< planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV411P and setting color_range 256 | 257 | AV_PIX_FMT_BAYER_BGGR8, ///< bayer, BGBG..(odd line), GRGR..(even line), 8-bit samples 258 | AV_PIX_FMT_BAYER_RGGB8, ///< bayer, RGRG..(odd line), GBGB..(even line), 8-bit samples 259 | AV_PIX_FMT_BAYER_GBRG8, ///< bayer, GBGB..(odd line), RGRG..(even line), 8-bit samples 260 | AV_PIX_FMT_BAYER_GRBG8, ///< bayer, GRGR..(odd line), BGBG..(even line), 8-bit samples 261 | AV_PIX_FMT_BAYER_BGGR16LE, ///< bayer, BGBG..(odd line), GRGR..(even line), 16-bit samples, little-endian 262 | AV_PIX_FMT_BAYER_BGGR16BE, ///< bayer, BGBG..(odd line), GRGR..(even line), 16-bit samples, big-endian 263 | AV_PIX_FMT_BAYER_RGGB16LE, ///< bayer, RGRG..(odd line), GBGB..(even line), 16-bit samples, little-endian 264 | AV_PIX_FMT_BAYER_RGGB16BE, ///< bayer, RGRG..(odd line), GBGB..(even line), 16-bit samples, big-endian 265 | AV_PIX_FMT_BAYER_GBRG16LE, ///< bayer, GBGB..(odd line), RGRG..(even line), 16-bit samples, little-endian 266 | AV_PIX_FMT_BAYER_GBRG16BE, ///< bayer, GBGB..(odd line), RGRG..(even line), 16-bit samples, big-endian 267 | AV_PIX_FMT_BAYER_GRBG16LE, ///< bayer, GRGR..(odd line), BGBG..(even line), 16-bit samples, little-endian 268 | AV_PIX_FMT_BAYER_GRBG16BE, ///< bayer, GRGR..(odd line), BGBG..(even line), 16-bit samples, big-endian 269 | 270 | AV_PIX_FMT_XVMC,///< XVideo Motion Acceleration via common packet passing 271 | 272 | AV_PIX_FMT_YUV440P10LE, ///< planar YUV 4:4:0,20bpp, (1 Cr & Cb sample per 1x2 Y samples), little-endian 273 | AV_PIX_FMT_YUV440P10BE, ///< planar YUV 4:4:0,20bpp, (1 Cr & Cb sample per 1x2 Y samples), big-endian 274 | AV_PIX_FMT_YUV440P12LE, ///< planar YUV 4:4:0,24bpp, (1 Cr & Cb sample per 1x2 Y samples), little-endian 275 | AV_PIX_FMT_YUV440P12BE, ///< planar YUV 4:4:0,24bpp, (1 Cr & Cb sample per 1x2 Y samples), big-endian 276 | AV_PIX_FMT_AYUV64LE, ///< packed AYUV 4:4:4,64bpp (1 Cr & Cb sample per 1x1 Y & A samples), little-endian 277 | AV_PIX_FMT_AYUV64BE, ///< packed AYUV 4:4:4,64bpp (1 Cr & Cb sample per 1x1 Y & A samples), big-endian 278 | 279 | AV_PIX_FMT_VIDEOTOOLBOX, ///< hardware decoding through Videotoolbox 280 | 281 | AV_PIX_FMT_P010LE, ///< like NV12, with 10bpp per component, data in the high bits, zeros in the low bits, little-endian 282 | AV_PIX_FMT_P010BE, ///< like NV12, with 10bpp per component, data in the high bits, zeros in the low bits, big-endian 283 | 284 | AV_PIX_FMT_GBRAP12BE, ///< planar GBR 4:4:4:4 48bpp, big-endian 285 | AV_PIX_FMT_GBRAP12LE, ///< planar GBR 4:4:4:4 48bpp, little-endian 286 | 287 | AV_PIX_FMT_GBRAP10BE, ///< planar GBR 4:4:4:4 40bpp, big-endian 288 | AV_PIX_FMT_GBRAP10LE, ///< planar GBR 4:4:4:4 40bpp, little-endian 289 | 290 | AV_PIX_FMT_MEDIACODEC, ///< hardware decoding through MediaCodec 291 | 292 | AV_PIX_FMT_GRAY12BE, ///< Y , 12bpp, big-endian 293 | AV_PIX_FMT_GRAY12LE, ///< Y , 12bpp, little-endian 294 | AV_PIX_FMT_GRAY10BE, ///< Y , 10bpp, big-endian 295 | AV_PIX_FMT_GRAY10LE, ///< Y , 10bpp, little-endian 296 | 297 | AV_PIX_FMT_P016LE, ///< like NV12, with 16bpp per component, little-endian 298 | AV_PIX_FMT_P016BE, ///< like NV12, with 16bpp per component, big-endian 299 | 300 | /** 301 | * Hardware surfaces for Direct3D11. 302 | * 303 | * This is preferred over the legacy AV_PIX_FMT_D3D11VA_VLD. The new D3D11 304 | * hwaccel API and filtering support AV_PIX_FMT_D3D11 only. 305 | * 306 | * data[0] contains a ID3D11Texture2D pointer, and data[1] contains the 307 | * texture array index of the frame as intptr_t if the ID3D11Texture2D is 308 | * an array texture (or always 0 if it's a normal texture). 309 | */ 310 | AV_PIX_FMT_D3D11, 311 | 312 | AV_PIX_FMT_GRAY9BE, ///< Y , 9bpp, big-endian 313 | AV_PIX_FMT_GRAY9LE, ///< Y , 9bpp, little-endian 314 | 315 | AV_PIX_FMT_GBRPF32BE, ///< IEEE-754 single precision planar GBR 4:4:4, 96bpp, big-endian 316 | AV_PIX_FMT_GBRPF32LE, ///< IEEE-754 single precision planar GBR 4:4:4, 96bpp, little-endian 317 | AV_PIX_FMT_GBRAPF32BE, ///< IEEE-754 single precision planar GBRA 4:4:4:4, 128bpp, big-endian 318 | AV_PIX_FMT_GBRAPF32LE, ///< IEEE-754 single precision planar GBRA 4:4:4:4, 128bpp, little-endian 319 | 320 | /** 321 | * DRM-managed buffers exposed through PRIME buffer sharing. 322 | * 323 | * data[0] points to an AVDRMFrameDescriptor. 324 | */ 325 | AV_PIX_FMT_DRM_PRIME, 326 | /** 327 | * Hardware surfaces for OpenCL. 328 | * 329 | * data[i] contain 2D image objects (typed in C as cl_mem, used 330 | * in OpenCL as image2d_t) for each plane of the surface. 331 | */ 332 | AV_PIX_FMT_OPENCL, 333 | 334 | AV_PIX_FMT_GRAY14BE, ///< Y , 14bpp, big-endian 335 | AV_PIX_FMT_GRAY14LE, ///< Y , 14bpp, little-endian 336 | 337 | AV_PIX_FMT_GRAYF32BE, ///< IEEE-754 single precision Y, 32bpp, big-endian 338 | AV_PIX_FMT_GRAYF32LE, ///< IEEE-754 single precision Y, 32bpp, little-endian 339 | 340 | AV_PIX_FMT_YUVA422P12BE, ///< planar YUV 4:2:2,24bpp, (1 Cr & Cb sample per 2x1 Y samples), 12b alpha, big-endian 341 | AV_PIX_FMT_YUVA422P12LE, ///< planar YUV 4:2:2,24bpp, (1 Cr & Cb sample per 2x1 Y samples), 12b alpha, little-endian 342 | AV_PIX_FMT_YUVA444P12BE, ///< planar YUV 4:4:4,36bpp, (1 Cr & Cb sample per 1x1 Y samples), 12b alpha, big-endian 343 | AV_PIX_FMT_YUVA444P12LE, ///< planar YUV 4:4:4,36bpp, (1 Cr & Cb sample per 1x1 Y samples), 12b alpha, little-endian 344 | 345 | AV_PIX_FMT_NV24, ///< planar YUV 4:4:4, 24bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (first byte U and the following byte V) 346 | AV_PIX_FMT_NV42, ///< as above, but U and V bytes are swapped 347 | 348 | /** 349 | * Vulkan hardware images. 350 | * 351 | * data[0] points to an AVVkFrame 352 | */ 353 | AV_PIX_FMT_VULKAN, 354 | 355 | AV_PIX_FMT_Y210BE, ///< packed YUV 4:2:2 like YUYV422, 20bpp, data in the high bits, big-endian 356 | AV_PIX_FMT_Y210LE, ///< packed YUV 4:2:2 like YUYV422, 20bpp, data in the high bits, little-endian 357 | 358 | AV_PIX_FMT_NB ///< number of pixel formats, DO NOT USE THIS if you want to link with shared libav* because the number of formats might differ between versions 359 | }; 360 | 361 | #if AV_HAVE_BIGENDIAN 362 | # define AV_PIX_FMT_NE(be, le) AV_PIX_FMT_##be 363 | #else 364 | # define AV_PIX_FMT_NE(be, le) AV_PIX_FMT_##le 365 | #endif 366 | 367 | #define AV_PIX_FMT_RGB32 AV_PIX_FMT_NE(ARGB, BGRA) 368 | #define AV_PIX_FMT_RGB32_1 AV_PIX_FMT_NE(RGBA, ABGR) 369 | #define AV_PIX_FMT_BGR32 AV_PIX_FMT_NE(ABGR, RGBA) 370 | #define AV_PIX_FMT_BGR32_1 AV_PIX_FMT_NE(BGRA, ARGB) 371 | #define AV_PIX_FMT_0RGB32 AV_PIX_FMT_NE(0RGB, BGR0) 372 | #define AV_PIX_FMT_0BGR32 AV_PIX_FMT_NE(0BGR, RGB0) 373 | 374 | #define AV_PIX_FMT_GRAY9 AV_PIX_FMT_NE(GRAY9BE, GRAY9LE) 375 | #define AV_PIX_FMT_GRAY10 AV_PIX_FMT_NE(GRAY10BE, GRAY10LE) 376 | #define AV_PIX_FMT_GRAY12 AV_PIX_FMT_NE(GRAY12BE, GRAY12LE) 377 | #define AV_PIX_FMT_GRAY14 AV_PIX_FMT_NE(GRAY14BE, GRAY14LE) 378 | #define AV_PIX_FMT_GRAY16 AV_PIX_FMT_NE(GRAY16BE, GRAY16LE) 379 | #define AV_PIX_FMT_YA16 AV_PIX_FMT_NE(YA16BE, YA16LE) 380 | #define AV_PIX_FMT_RGB48 AV_PIX_FMT_NE(RGB48BE, RGB48LE) 381 | #define AV_PIX_FMT_RGB565 AV_PIX_FMT_NE(RGB565BE, RGB565LE) 382 | #define AV_PIX_FMT_RGB555 AV_PIX_FMT_NE(RGB555BE, RGB555LE) 383 | #define AV_PIX_FMT_RGB444 AV_PIX_FMT_NE(RGB444BE, RGB444LE) 384 | #define AV_PIX_FMT_RGBA64 AV_PIX_FMT_NE(RGBA64BE, RGBA64LE) 385 | #define AV_PIX_FMT_BGR48 AV_PIX_FMT_NE(BGR48BE, BGR48LE) 386 | #define AV_PIX_FMT_BGR565 AV_PIX_FMT_NE(BGR565BE, BGR565LE) 387 | #define AV_PIX_FMT_BGR555 AV_PIX_FMT_NE(BGR555BE, BGR555LE) 388 | #define AV_PIX_FMT_BGR444 AV_PIX_FMT_NE(BGR444BE, BGR444LE) 389 | #define AV_PIX_FMT_BGRA64 AV_PIX_FMT_NE(BGRA64BE, BGRA64LE) 390 | 391 | #define AV_PIX_FMT_YUV420P9 AV_PIX_FMT_NE(YUV420P9BE , YUV420P9LE) 392 | #define AV_PIX_FMT_YUV422P9 AV_PIX_FMT_NE(YUV422P9BE , YUV422P9LE) 393 | #define AV_PIX_FMT_YUV444P9 AV_PIX_FMT_NE(YUV444P9BE , YUV444P9LE) 394 | #define AV_PIX_FMT_YUV420P10 AV_PIX_FMT_NE(YUV420P10BE, YUV420P10LE) 395 | #define AV_PIX_FMT_YUV422P10 AV_PIX_FMT_NE(YUV422P10BE, YUV422P10LE) 396 | #define AV_PIX_FMT_YUV440P10 AV_PIX_FMT_NE(YUV440P10BE, YUV440P10LE) 397 | #define AV_PIX_FMT_YUV444P10 AV_PIX_FMT_NE(YUV444P10BE, YUV444P10LE) 398 | #define AV_PIX_FMT_YUV420P12 AV_PIX_FMT_NE(YUV420P12BE, YUV420P12LE) 399 | #define AV_PIX_FMT_YUV422P12 AV_PIX_FMT_NE(YUV422P12BE, YUV422P12LE) 400 | #define AV_PIX_FMT_YUV440P12 AV_PIX_FMT_NE(YUV440P12BE, YUV440P12LE) 401 | #define AV_PIX_FMT_YUV444P12 AV_PIX_FMT_NE(YUV444P12BE, YUV444P12LE) 402 | #define AV_PIX_FMT_YUV420P14 AV_PIX_FMT_NE(YUV420P14BE, YUV420P14LE) 403 | #define AV_PIX_FMT_YUV422P14 AV_PIX_FMT_NE(YUV422P14BE, YUV422P14LE) 404 | #define AV_PIX_FMT_YUV444P14 AV_PIX_FMT_NE(YUV444P14BE, YUV444P14LE) 405 | #define AV_PIX_FMT_YUV420P16 AV_PIX_FMT_NE(YUV420P16BE, YUV420P16LE) 406 | #define AV_PIX_FMT_YUV422P16 AV_PIX_FMT_NE(YUV422P16BE, YUV422P16LE) 407 | #define AV_PIX_FMT_YUV444P16 AV_PIX_FMT_NE(YUV444P16BE, YUV444P16LE) 408 | 409 | #define AV_PIX_FMT_GBRP9 AV_PIX_FMT_NE(GBRP9BE , GBRP9LE) 410 | #define AV_PIX_FMT_GBRP10 AV_PIX_FMT_NE(GBRP10BE, GBRP10LE) 411 | #define AV_PIX_FMT_GBRP12 AV_PIX_FMT_NE(GBRP12BE, GBRP12LE) 412 | #define AV_PIX_FMT_GBRP14 AV_PIX_FMT_NE(GBRP14BE, GBRP14LE) 413 | #define AV_PIX_FMT_GBRP16 AV_PIX_FMT_NE(GBRP16BE, GBRP16LE) 414 | #define AV_PIX_FMT_GBRAP10 AV_PIX_FMT_NE(GBRAP10BE, GBRAP10LE) 415 | #define AV_PIX_FMT_GBRAP12 AV_PIX_FMT_NE(GBRAP12BE, GBRAP12LE) 416 | #define AV_PIX_FMT_GBRAP16 AV_PIX_FMT_NE(GBRAP16BE, GBRAP16LE) 417 | 418 | #define AV_PIX_FMT_BAYER_BGGR16 AV_PIX_FMT_NE(BAYER_BGGR16BE, BAYER_BGGR16LE) 419 | #define AV_PIX_FMT_BAYER_RGGB16 AV_PIX_FMT_NE(BAYER_RGGB16BE, BAYER_RGGB16LE) 420 | #define AV_PIX_FMT_BAYER_GBRG16 AV_PIX_FMT_NE(BAYER_GBRG16BE, BAYER_GBRG16LE) 421 | #define AV_PIX_FMT_BAYER_GRBG16 AV_PIX_FMT_NE(BAYER_GRBG16BE, BAYER_GRBG16LE) 422 | 423 | #define AV_PIX_FMT_GBRPF32 AV_PIX_FMT_NE(GBRPF32BE, GBRPF32LE) 424 | #define AV_PIX_FMT_GBRAPF32 AV_PIX_FMT_NE(GBRAPF32BE, GBRAPF32LE) 425 | 426 | #define AV_PIX_FMT_GRAYF32 AV_PIX_FMT_NE(GRAYF32BE, GRAYF32LE) 427 | 428 | #define AV_PIX_FMT_YUVA420P9 AV_PIX_FMT_NE(YUVA420P9BE , YUVA420P9LE) 429 | #define AV_PIX_FMT_YUVA422P9 AV_PIX_FMT_NE(YUVA422P9BE , YUVA422P9LE) 430 | #define AV_PIX_FMT_YUVA444P9 AV_PIX_FMT_NE(YUVA444P9BE , YUVA444P9LE) 431 | #define AV_PIX_FMT_YUVA420P10 AV_PIX_FMT_NE(YUVA420P10BE, YUVA420P10LE) 432 | #define AV_PIX_FMT_YUVA422P10 AV_PIX_FMT_NE(YUVA422P10BE, YUVA422P10LE) 433 | #define AV_PIX_FMT_YUVA444P10 AV_PIX_FMT_NE(YUVA444P10BE, YUVA444P10LE) 434 | #define AV_PIX_FMT_YUVA422P12 AV_PIX_FMT_NE(YUVA422P12BE, YUVA422P12LE) 435 | #define AV_PIX_FMT_YUVA444P12 AV_PIX_FMT_NE(YUVA444P12BE, YUVA444P12LE) 436 | #define AV_PIX_FMT_YUVA420P16 AV_PIX_FMT_NE(YUVA420P16BE, YUVA420P16LE) 437 | #define AV_PIX_FMT_YUVA422P16 AV_PIX_FMT_NE(YUVA422P16BE, YUVA422P16LE) 438 | #define AV_PIX_FMT_YUVA444P16 AV_PIX_FMT_NE(YUVA444P16BE, YUVA444P16LE) 439 | 440 | #define AV_PIX_FMT_XYZ12 AV_PIX_FMT_NE(XYZ12BE, XYZ12LE) 441 | #define AV_PIX_FMT_NV20 AV_PIX_FMT_NE(NV20BE, NV20LE) 442 | #define AV_PIX_FMT_AYUV64 AV_PIX_FMT_NE(AYUV64BE, AYUV64LE) 443 | #define AV_PIX_FMT_P010 AV_PIX_FMT_NE(P010BE, P010LE) 444 | #define AV_PIX_FMT_P016 AV_PIX_FMT_NE(P016BE, P016LE) 445 | 446 | #define AV_PIX_FMT_Y210 AV_PIX_FMT_NE(Y210BE, Y210LE) 447 | 448 | /** 449 | * Chromaticity coordinates of the source primaries. 450 | * These values match the ones defined by ISO/IEC 23001-8_2013 § 7.1. 451 | */ 452 | enum AVColorPrimaries { 453 | AVCOL_PRI_RESERVED0 = 0, 454 | AVCOL_PRI_BT709 = 1, ///< also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP177 Annex B 455 | AVCOL_PRI_UNSPECIFIED = 2, 456 | AVCOL_PRI_RESERVED = 3, 457 | AVCOL_PRI_BT470M = 4, ///< also FCC Title 47 Code of Federal Regulations 73.682 (a)(20) 458 | 459 | AVCOL_PRI_BT470BG = 5, ///< also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM 460 | AVCOL_PRI_SMPTE170M = 6, ///< also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC 461 | AVCOL_PRI_SMPTE240M = 7, ///< functionally identical to above 462 | AVCOL_PRI_FILM = 8, ///< colour filters using Illuminant C 463 | AVCOL_PRI_BT2020 = 9, ///< ITU-R BT2020 464 | AVCOL_PRI_SMPTE428 = 10, ///< SMPTE ST 428-1 (CIE 1931 XYZ) 465 | AVCOL_PRI_SMPTEST428_1 = AVCOL_PRI_SMPTE428, 466 | AVCOL_PRI_SMPTE431 = 11, ///< SMPTE ST 431-2 (2011) / DCI P3 467 | AVCOL_PRI_SMPTE432 = 12, ///< SMPTE ST 432-1 (2010) / P3 D65 / Display P3 468 | AVCOL_PRI_EBU3213 = 22, ///< EBU Tech. 3213-E / JEDEC P22 phosphors 469 | AVCOL_PRI_JEDEC_P22 = AVCOL_PRI_EBU3213, 470 | AVCOL_PRI_NB ///< Not part of ABI 471 | }; 472 | 473 | /** 474 | * Color Transfer Characteristic. 475 | * These values match the ones defined by ISO/IEC 23001-8_2013 § 7.2. 476 | */ 477 | enum AVColorTransferCharacteristic { 478 | AVCOL_TRC_RESERVED0 = 0, 479 | AVCOL_TRC_BT709 = 1, ///< also ITU-R BT1361 480 | AVCOL_TRC_UNSPECIFIED = 2, 481 | AVCOL_TRC_RESERVED = 3, 482 | AVCOL_TRC_GAMMA22 = 4, ///< also ITU-R BT470M / ITU-R BT1700 625 PAL & SECAM 483 | AVCOL_TRC_GAMMA28 = 5, ///< also ITU-R BT470BG 484 | AVCOL_TRC_SMPTE170M = 6, ///< also ITU-R BT601-6 525 or 625 / ITU-R BT1358 525 or 625 / ITU-R BT1700 NTSC 485 | AVCOL_TRC_SMPTE240M = 7, 486 | AVCOL_TRC_LINEAR = 8, ///< "Linear transfer characteristics" 487 | AVCOL_TRC_LOG = 9, ///< "Logarithmic transfer characteristic (100:1 range)" 488 | AVCOL_TRC_LOG_SQRT = 10, ///< "Logarithmic transfer characteristic (100 * Sqrt(10) : 1 range)" 489 | AVCOL_TRC_IEC61966_2_4 = 11, ///< IEC 61966-2-4 490 | AVCOL_TRC_BT1361_ECG = 12, ///< ITU-R BT1361 Extended Colour Gamut 491 | AVCOL_TRC_IEC61966_2_1 = 13, ///< IEC 61966-2-1 (sRGB or sYCC) 492 | AVCOL_TRC_BT2020_10 = 14, ///< ITU-R BT2020 for 10-bit system 493 | AVCOL_TRC_BT2020_12 = 15, ///< ITU-R BT2020 for 12-bit system 494 | AVCOL_TRC_SMPTE2084 = 16, ///< SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems 495 | AVCOL_TRC_SMPTEST2084 = AVCOL_TRC_SMPTE2084, 496 | AVCOL_TRC_SMPTE428 = 17, ///< SMPTE ST 428-1 497 | AVCOL_TRC_SMPTEST428_1 = AVCOL_TRC_SMPTE428, 498 | AVCOL_TRC_ARIB_STD_B67 = 18, ///< ARIB STD-B67, known as "Hybrid log-gamma" 499 | AVCOL_TRC_NB ///< Not part of ABI 500 | }; 501 | 502 | /** 503 | * YUV colorspace type. 504 | * These values match the ones defined by ISO/IEC 23001-8_2013 § 7.3. 505 | */ 506 | enum AVColorSpace { 507 | AVCOL_SPC_RGB = 0, ///< order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB) 508 | AVCOL_SPC_BT709 = 1, ///< also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / SMPTE RP177 Annex B 509 | AVCOL_SPC_UNSPECIFIED = 2, 510 | AVCOL_SPC_RESERVED = 3, 511 | AVCOL_SPC_FCC = 4, ///< FCC Title 47 Code of Federal Regulations 73.682 (a)(20) 512 | AVCOL_SPC_BT470BG = 5, ///< also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601 513 | AVCOL_SPC_SMPTE170M = 6, ///< also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC 514 | AVCOL_SPC_SMPTE240M = 7, ///< functionally identical to above 515 | AVCOL_SPC_YCGCO = 8, ///< Used by Dirac / VC-2 and H.264 FRext, see ITU-T SG16 516 | AVCOL_SPC_YCOCG = AVCOL_SPC_YCGCO, 517 | AVCOL_SPC_BT2020_NCL = 9, ///< ITU-R BT2020 non-constant luminance system 518 | AVCOL_SPC_BT2020_CL = 10, ///< ITU-R BT2020 constant luminance system 519 | AVCOL_SPC_SMPTE2085 = 11, ///< SMPTE 2085, Y'D'zD'x 520 | AVCOL_SPC_CHROMA_DERIVED_NCL = 12, ///< Chromaticity-derived non-constant luminance system 521 | AVCOL_SPC_CHROMA_DERIVED_CL = 13, ///< Chromaticity-derived constant luminance system 522 | AVCOL_SPC_ICTCP = 14, ///< ITU-R BT.2100-0, ICtCp 523 | AVCOL_SPC_NB ///< Not part of ABI 524 | }; 525 | 526 | /** 527 | * MPEG vs JPEG YUV range. 528 | */ 529 | enum AVColorRange { 530 | AVCOL_RANGE_UNSPECIFIED = 0, 531 | AVCOL_RANGE_MPEG = 1, ///< the normal 219*2^(n-8) "MPEG" YUV ranges 532 | AVCOL_RANGE_JPEG = 2, ///< the normal 2^n-1 "JPEG" YUV ranges 533 | AVCOL_RANGE_NB ///< Not part of ABI 534 | }; 535 | 536 | /** 537 | * Location of chroma samples. 538 | * 539 | * Illustration showing the location of the first (top left) chroma sample of the 540 | * image, the left shows only luma, the right 541 | * shows the location of the chroma sample, the 2 could be imagined to overlay 542 | * each other but are drawn separately due to limitations of ASCII 543 | * 544 | * 1st 2nd 1st 2nd horizontal luma sample positions 545 | * v v v v 546 | * ______ ______ 547 | *1st luma line > |X X ... |3 4 X ... X are luma samples, 548 | * | |1 2 1-6 are possible chroma positions 549 | *2nd luma line > |X X ... |5 6 X ... 0 is undefined/unknown position 550 | */ 551 | enum AVChromaLocation { 552 | AVCHROMA_LOC_UNSPECIFIED = 0, 553 | AVCHROMA_LOC_LEFT = 1, ///< MPEG-2/4 4:2:0, H.264 default for 4:2:0 554 | AVCHROMA_LOC_CENTER = 2, ///< MPEG-1 4:2:0, JPEG 4:2:0, H.263 4:2:0 555 | AVCHROMA_LOC_TOPLEFT = 3, ///< ITU-R 601, SMPTE 274M 296M S314M(DV 4:1:1), mpeg2 4:2:2 556 | AVCHROMA_LOC_TOP = 4, 557 | AVCHROMA_LOC_BOTTOMLEFT = 5, 558 | AVCHROMA_LOC_BOTTOM = 6, 559 | AVCHROMA_LOC_NB ///< Not part of ABI 560 | }; 561 | 562 | #endif /* AVUTIL_PIXFMT_H */ 563 | -------------------------------------------------------------------------------- /src/queue/LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /src/queue/README: -------------------------------------------------------------------------------- 1 | Copied from https://github.com/Fenrirthviti/obs-virtual-cam/tree/master/src/queue. 2 | 3 | -------------------------------------------------------------------------------- /src/queue/share_queue.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "libavutil/pixfmt.h" 5 | 6 | #define AUDIO_SIZE 4096 7 | #define MAPPING_NAMEV "OBSVirtualVideo" 8 | #define MAPPING_NAMEV2 "OBSVirtualVideo2" 9 | #define MAPPING_NAMEV3 "OBSVirtualVideo3" 10 | #define MAPPING_NAMEV4 "OBSVirtualVideo4" 11 | #define MAPPING_NAMEA "OBSVirtualAudio" 12 | 13 | typedef signed char int8_t; 14 | typedef short int16_t; 15 | typedef int int32_t; 16 | typedef long long int64_t; 17 | typedef unsigned char uint8_t; 18 | typedef unsigned short uint16_t; 19 | typedef unsigned int uint32_t; 20 | typedef unsigned long long uint64_t; 21 | 22 | enum { 23 | ModeVideo = 0, 24 | ModeVideo2 = 1, 25 | ModeVideo3 = 2, 26 | ModeVideo4 = 3, 27 | ModeAudio = 5, 28 | }; 29 | 30 | enum { 31 | OutputStop = 0, 32 | OutputStart = 1, 33 | OutputReady = 2, 34 | }; 35 | 36 | struct frame_header { 37 | uint64_t timestamp; 38 | uint32_t linesize[4]; 39 | int frame_width; 40 | int frame_height; 41 | }; 42 | 43 | struct queue_header { 44 | int state; 45 | int format; 46 | int queue_length; 47 | int write_index; 48 | int header_size; 49 | int element_size; 50 | int element_header_size; 51 | int delay_frame; 52 | int recommended_width; 53 | int recommended_height; 54 | int aspect_ratio_type; 55 | uint64_t last_ts; 56 | uint64_t frame_time; 57 | }; 58 | 59 | struct share_queue { 60 | int mode =0 ; 61 | int index = -1; 62 | int operating_width; 63 | int operating_height; 64 | HANDLE hwnd =NULL; 65 | queue_header* header = nullptr; 66 | }; 67 | 68 | inline char* get_mapping_name(int mode) 69 | { 70 | switch (mode){ 71 | case ModeVideo: return MAPPING_NAMEV; 72 | case ModeVideo2: return MAPPING_NAMEV2; 73 | case ModeVideo3: return MAPPING_NAMEV3; 74 | case ModeVideo4: return MAPPING_NAMEV4; 75 | case ModeAudio: return MAPPING_NAMEA; 76 | default: return NULL; 77 | } 78 | } 79 | 80 | inline frame_header* get_frame_header(queue_header* qhead, int index) 81 | { 82 | int offset = qhead->header_size + (qhead->element_size) * index; 83 | uint8_t* buff = (uint8_t*)qhead + offset; 84 | return (frame_header*)buff; 85 | } 86 | 87 | inline int cal_video_buffer_size(int format, int width, int height) 88 | { 89 | int frame_size = 0; 90 | switch (format) { 91 | case AV_PIX_FMT_YUV420P: 92 | case AV_PIX_FMT_NV12: 93 | frame_size = width * height * 3 / 2; 94 | break; 95 | 96 | case AV_PIX_FMT_GRAY8: 97 | frame_size = width * height; 98 | break; 99 | 100 | case AV_PIX_FMT_YUYV422: 101 | case AV_PIX_FMT_UYVY422: 102 | frame_size = width * height *2; 103 | break; 104 | 105 | case AV_PIX_FMT_RGBA: 106 | case AV_PIX_FMT_BGRA: 107 | frame_size = width * height * 4; 108 | break; 109 | 110 | case AV_PIX_FMT_YUV444P: 111 | frame_size = width * height * 3; 112 | break; 113 | } 114 | 115 | return frame_size; 116 | } -------------------------------------------------------------------------------- /src/queue/share_queue_write.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "share_queue_write.h" 3 | #include "util.h" 4 | 5 | bool shared_queue_create(share_queue* q, int mode, int format, 6 | int width, int height, uint64_t frame_time, int qlength) 7 | { 8 | if (!q) { 9 | fprintf(stderr, "q argument NULL\n"); 10 | return false; 11 | } 12 | 13 | if (!shared_queue_check(mode)) { 14 | fprintf(stderr, "shared_queue_check() failed\n"); 15 | return false; 16 | } 17 | 18 | int frame_size = 0; 19 | const char* name = get_mapping_name(mode); 20 | 21 | if (mode < ModeAudio) { 22 | frame_size = cal_video_buffer_size(format, width, height); 23 | } else { 24 | frame_size = AUDIO_SIZE; 25 | } 26 | int buffer_size = sizeof(queue_header) + (sizeof(frame_header) + 27 | frame_size) * qlength; 28 | q->hwnd = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, 29 | PAGE_READWRITE, 0, buffer_size, name); 30 | 31 | if (!q->hwnd) { 32 | PrintLastError(); 33 | fprintf(stderr, "CreateFileMappingA() failed\n"); 34 | return false; 35 | } 36 | 37 | q->header = (queue_header*)MapViewOfFile(q->hwnd, FILE_MAP_ALL_ACCESS, 38 | 0, 0, buffer_size); 39 | 40 | if (!q->header) { 41 | PrintLastError(); 42 | fprintf(stderr, "MapViewOfFile() failed\n"); 43 | return false; 44 | } 45 | 46 | queue_header* q_head = q->header; 47 | 48 | q_head->header_size = sizeof(queue_header); 49 | q_head->element_header_size = sizeof(frame_header); 50 | q_head->element_size = sizeof(frame_header) + frame_size; 51 | q_head->format = format; 52 | q_head->queue_length = qlength; 53 | q_head->write_index = 0; 54 | q_head->state = OutputStart; 55 | q_head->frame_time = frame_time; 56 | q_head->delay_frame = 5; 57 | q_head->recommended_width = width; 58 | q_head->recommended_height = height; 59 | q->mode = mode; 60 | q->index = 0; 61 | 62 | return true; 63 | } 64 | 65 | void shared_queue_write_close(share_queue* q) 66 | { 67 | if (q && q->header) { 68 | q->header->state = OutputStop; 69 | UnmapViewOfFile(q->header); 70 | CloseHandle(q->hwnd); 71 | q->header = nullptr; 72 | q->hwnd = NULL; 73 | q->index = -1; 74 | } 75 | } 76 | 77 | bool shared_queue_push_video(share_queue* q, uint32_t* linesize, 78 | uint32_t width, uint32_t height, uint8_t** data, uint64_t timestamp) 79 | { 80 | if (!q || !q->header) 81 | return false; 82 | 83 | frame_header* frame = get_frame_header(q->header, q->index); 84 | uint8_t* dst = (uint8_t*)frame + q->header->element_header_size; 85 | int planes = 0; 86 | 87 | switch (q->header->format) { 88 | case AV_PIX_FMT_NONE: 89 | return false; 90 | 91 | case AV_PIX_FMT_YUV420P: 92 | planes = 3; 93 | memcpy(dst, data[0], linesize[0] * height); 94 | dst += linesize[0] * height; 95 | memcpy(dst, data[1], linesize[1] * height / 2); 96 | dst += linesize[1] * height / 2; 97 | memcpy(dst, data[2], linesize[2] * height / 2); 98 | break; 99 | 100 | case AV_PIX_FMT_NV12: 101 | planes = 2; 102 | memcpy(dst, data[0], linesize[0] * height); 103 | dst += linesize[0] * height; 104 | memcpy(dst, data[1], linesize[1] * height / 2); 105 | break; 106 | 107 | case AV_PIX_FMT_GRAY8: 108 | case AV_PIX_FMT_YUYV422: 109 | case AV_PIX_FMT_UYVY422: 110 | case AV_PIX_FMT_RGBA: 111 | case AV_PIX_FMT_BGRA: 112 | planes = 1; 113 | memcpy(dst, data[0], linesize[0] * height); 114 | break; 115 | 116 | case AV_PIX_FMT_YUV444P: 117 | planes = 3; 118 | memcpy(dst, data[0], linesize[0] * height); 119 | dst += linesize[0] * height; 120 | memcpy(dst, data[1], linesize[1] * height); 121 | dst += linesize[1] * height; 122 | memcpy(dst, data[2], linesize[2] * height); 123 | break; 124 | } 125 | 126 | for (int i = 0; i < planes; i++) 127 | frame->linesize[i] = linesize[i]; 128 | 129 | frame->timestamp = timestamp; 130 | frame->frame_width = width; 131 | frame->frame_height = height; 132 | q->header->write_index = q->index; 133 | 134 | q->index++; 135 | 136 | if (q->index >= q->header->queue_length) { 137 | q->header->state = OutputReady; 138 | q->index = 0; 139 | } 140 | 141 | return true; 142 | } 143 | 144 | bool shared_queue_push_audio(share_queue* q, uint32_t size, 145 | uint8_t* src, uint64_t timestamp, uint64_t video_ts) 146 | { 147 | if (!q || !q->header) 148 | return false; 149 | 150 | int offset = q->header->header_size + 151 | (q->header->element_size) * q->index; 152 | 153 | q->header->write_index = q->index; 154 | q->header->last_ts = video_ts; 155 | 156 | uint8_t* buff = (uint8_t*)q->header + offset; 157 | frame_header* head = (frame_header*)buff; 158 | uint8_t* data = (uint8_t*)buff + q->header->element_header_size; 159 | memcpy(data, src, size); 160 | head->linesize[0] = size; 161 | head->timestamp = timestamp; 162 | 163 | q->index++; 164 | 165 | if (q->index >= q->header->queue_length) { 166 | q->index = 0; 167 | q->header->state = OutputReady; 168 | } 169 | 170 | return true; 171 | } 172 | 173 | bool shared_queue_check(int mode) 174 | { 175 | HANDLE hwnd = NULL; 176 | const char *name = get_mapping_name(mode); 177 | 178 | hwnd = OpenFileMappingA(FILE_MAP_ALL_ACCESS, FALSE, name); 179 | 180 | if (hwnd) { 181 | fprintf(stderr, "%s handle exists already\n", name); 182 | CloseHandle(hwnd); 183 | return false; 184 | } else 185 | return true; 186 | } 187 | 188 | bool shared_queue_set_delay(share_queue* q, int delay_video_frame) 189 | { 190 | if (!q || !q->header) 191 | return false; 192 | 193 | q->header->delay_frame = delay_video_frame; 194 | return true; 195 | } 196 | 197 | bool shared_queue_set_keep_ratio(share_queue* q, bool keep_ratio) 198 | { 199 | if (!q || !q->header) 200 | return false; 201 | 202 | if (keep_ratio) 203 | q->header->aspect_ratio_type = 1; 204 | else 205 | q->header->aspect_ratio_type = 0; 206 | return true; 207 | } 208 | 209 | bool shared_queue_set_recommended_format(share_queue* q, int width, int height) 210 | { 211 | if (!q || !q->header) 212 | return false; 213 | 214 | q->header->recommended_width = width; 215 | q->header->recommended_height = height; 216 | 217 | return true; 218 | } 219 | -------------------------------------------------------------------------------- /src/queue/share_queue_write.h: -------------------------------------------------------------------------------- 1 | #include "share_queue.h" 2 | bool shared_queue_create(share_queue* q, int mode, int format, 3 | int frame_width, int frame_height, uint64_t frame_time, int qlength); 4 | void shared_queue_write_close(share_queue* q); 5 | bool shared_queue_push_video(share_queue* q, uint32_t* linesize, 6 | uint32_t width, uint32_t height, uint8_t** data, uint64_t timestamp); 7 | bool shared_queue_push_audio(share_queue* q, uint32_t size, 8 | uint8_t* src, uint64_t timestamp, uint64_t video_ts); 9 | bool shared_queue_check(int mode); 10 | bool shared_queue_set_delay(share_queue* q, int delay_video_frame); 11 | bool shared_queue_set_keep_ratio(share_queue* q, bool keep_ratio); 12 | bool shared_queue_set_recommended_format(share_queue* q, int width, 13 | int height); -------------------------------------------------------------------------------- /src/queue/util.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | inline void PrintLastError() 7 | { 8 | DWORD errorMessageID = GetLastError(); 9 | if (errorMessageID == 0) 10 | return; 11 | 12 | LPSTR messageBuffer = nullptr; 13 | size_t size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 14 | NULL, errorMessageID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&messageBuffer, 0, NULL); 15 | 16 | fprintf(stderr, messageBuffer); 17 | LocalFree(messageBuffer); 18 | } 19 | --------------------------------------------------------------------------------