{"id":13418183,"url":"https://github.com/sourcey/libsourcey","last_synced_at":"2025-04-08T08:12:36.759Z","repository":{"id":2546959,"uuid":"3524917","full_name":"sourcey/libsourcey","owner":"sourcey","description":"C++14 evented IO libraries for high performance networking and media based applications","archived":false,"fork":false,"pushed_at":"2023-01-11T22:14:49.000Z","size":36202,"stargazers_count":1295,"open_issues_count":70,"forks_count":344,"subscribers_count":131,"default_branch":"master","last_synced_at":"2024-07-31T22:41:46.417Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://sourcey.com/libsourcey","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-2.1","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sourcey.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-02-23T11:55:51.000Z","updated_at":"2024-07-29T10:19:49.000Z","dependencies_parsed_at":"2023-01-13T13:00:47.796Z","dependency_job_id":null,"html_url":"https://github.com/sourcey/libsourcey","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sourcey%2Flibsourcey","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sourcey%2Flibsourcey/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sourcey%2Flibsourcey/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sourcey%2Flibsourcey/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sourcey","download_url":"https://codeload.github.com/sourcey/libsourcey/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247801169,"owners_count":20998339,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T22:00:59.392Z","updated_at":"2025-04-08T08:12:36.731Z","avatar_url":"https://github.com/sourcey.png","language":"C++","readme":"# LibSourcey\n\n\u003e C++ Networking Evolved\n\n[![Circle CI](https://circleci.com/gh/sourcey/libsourcey.svg?style=shield\u0026circle-token=ab142562b19bb857de796d729aab28fa9df7682d)](https://circleci.com/gh/sourcey/libsourcey)\n[![Doxygen](https://sourcey.com/images/doxygen.svg)](https://sourcey.com/libsourcey)\n\n\u003c!-- \u003cimg style=\"float:left;width:70px;margin-right:15px;margin-bottom:10px\" src=\"https://sourcey.com/images/logos/libsourcey-80x80.png\"\u003e --\u003e\nLibSourcey is a collection of cross platform C++14 modules and classes that provide developers with an arsenal for rapidly developing high performance network based p2p and media streaming applications. Think of it as the power and performance of `libuv` combined with the features of `FFmpeg`, `OpenCV` and `WebRTC`, all integrated with the ease and readability of the `stl` (C++ Standard Library).\n\n* **Documentation**: [https://sourcey.com/libsourcey](https://sourcey.com/libsourcey)  \n* **Repository**: [https://github.com/sourcey/libsourcey](https://github.com/sourcey/libsourcey)  \n* **Licence**: [LGPL-2.1+](/LICENSE.md)\n\n## Basic features\n\n* **Event-based IO** — Core modules are built on top of `libuv` (the underlying C library that powers `nodejs`) and use event-based asynchronous IO throughout to maximize performance and minimize concurrency reliance for building mission critical native and server side apps.\n\n* **Cross platform** — The codebase is cross platform and should compile on any system with access to a modern C++14 compiler.\n\n* **Modular libraries** — Libraries are modular for easy integration into your existing projects, so you can just \"include what you need\" without incurring extra incumbent bloat.\n\n* **Well tested** — Core modules are well tested with unit tests and stress tested daily in production.\n\n* **Clean and readable code** — Modern C++ design principles have been adhered to throughout for clean and readable code.\n\n* **Easy packaging and installation** — LibSourcey can be compiled and installed on most platforms with `CMake`. For straight forward distribution and integration with existing projects the libraries be also packaged as a `deb`, `rpm`, `tar.gz`, `zip`, and more formats with a [single command](https://sourcey.com/libsourcey/installation#building-packages).\n\n* **Docker images** — Semantically versioned images are available on [Docker Hub](https://hub.docker.com/r/sourcey/libsourcey/). Just type `docker pull sourcey/libsourcey` to grab the latest.\n\n* **Solid networking layer** — At the core of LibSourcey is a solid and blazing fast networking layer build on `libuv` and `openssl` primitives, with TCP, SSL and UDP socket implementations.\n\n* **Web servers and clients** — A HTTP stack is provided that includes servers, clients, WebSockets, media streaming, file transfers, and authentication. The HTTP parser is based on the super-fast C code used by `nginx`.\n\n* **Media streaming and encoding** — The `av` library consists of thin wrappers around `FFmpeg` and `OpenCV` for media capture, encoding, recording, streaming, analysis and more.\n\n* **Realtime messaging** — LibSourcey aims to bridge the gap between desktop, mobile and web by providing performance oriented messaging solutions that work across all platforms.\n    * **Socket.IO** — Socket.IO C++ client that supports the latest protocol revision 4 (\u003e= 1.0). Read more about [Socket.IO](http://socket.io).\n    * **Symple** — Sourcey's home grown realtime messaging protocol that works over the top of Socket.IO to provide rostering, presence and many other features necessary for building online games and chat applications. [More about Symple](https://sourcey.com/symple).\n\n* **WebRTC support** — WebRTC native support allows you to build p2p desktop and server side applications that inherit LibSourcey's realtime messaging and media capabilities. Take a look at the [examples](https://sourcey.com/libsourcey/examples/) for how to stream live webcam and microphone streams to the browser, and also how to record live WebRTC streams on the server side.\n\n\u003c!--\n* **Full ICE stack** — The ICE module is a complete implementation of [RFC 5245 (Interactive Connectivity Establishment)](http://tools.ietf.org/html/rfc5245) based on LibSourcey architecture.\n    * **ICE** — [RFC 5245](http://tools.ietf.org/rfc/rfc5245) ICE agent implementation.\n    * **STUN** — [RFC 5389](http://tools.ietf.org/rfc/rfc5389) implementation that includes support for ICE and TURN and TURN TCP messages.\n    * **TURN** — Server and client stack that supports both [RFC 5766 (Traversal Using Relays around NAT)](http://tools.ietf.org/rfc/rfc5766) and [RFC 6062 (Traversal Using Relays around NAT Extensions for TCP Allocations)](http://tools.ietf.org/rfc/rfc6062) specifications.s\n    * **SDP** — [RFC 4566](http://tools.ietf.org/rfc/rfc4566) implementation that includes extra support for ICE headers.\n--\u003e\n\n## Getting started\n\nSee the [installation guides](https://sourcey.com/libsourcey/installation) in the docs to get started playing with LibSourcey.\n\n\n\u003c!--\nTODO: move to docs\n### Using Docker\n\nBuilding with Docker:\n\n```\nsudo docker build .\n```\n\nDocker images are available on Docker Hub: https://hub.docker.com/r/sourcey/libsourcey/\n\n```\nsudo docker pull sourcey/libsourcey\n```\n--\u003e\n\n## A few examples\n\nWhat better way to get acquainted with a new library then with some tasty code examples.\n\n#### HTTP echo server\n\nLets start with the classic HTTP echo server, which looks something like this:\n\n~~~cpp\nhttp::Server srv{ \"127.0.0.1\", 1337 };\nsrv.Connection += [](http::ServerConnection::Ptr conn) {\n    conn-\u003ePayload += [](http::ServerConnection\u0026 conn, const MutableBuffer\u0026 buffer) {\n        conn.send(bufferCast\u003cconst char*\u003e(buffer), buffer.size());\n        conn.close();\n    };\n};\nsrv.start();\n~~~\n\nPretty neat right? Its crazy fast too, especially on Linux kernel 3.9 or newer where its optimized to use of kernel level multicore socket load balancing. Don't take our word for it though, here are some benchmarks using `wrk`:\n\n**LibSourcey `httpechoserver`**\n\n~~~bash\n$ wrk -d10s --timeout 2s http://localhost:1337\nRunning 10s test @ http://localhost:1337\n  2 threads and 10 connections\n  Thread Stats   Avg      Stdev     Max   +/- Stdev\n    Latency   265.76us  472.62us  12.42ms   97.51%\n    Req/Sec    18.84k     1.26k   21.57k    74.50%\n  375060 requests in 10.01s, 20.39MB read\nRequests/sec:  37461.50\nTransfer/sec:      2.04MB\n~~~\n\n**Nodejs echo server**\n\n~~~bash\n$ wrk -d10s --timeout 2s http://localhost:1337\nRunning 10s test @ http://localhost:1337\n  2 threads and 10 connections\n  Thread Stats   Avg      Stdev     Max   +/- Stdev\n    Latency   502.70us  715.11us  14.83ms   97.90%\n    Req/Sec    11.69k     1.46k   14.52k    70.50%\n  232667 requests in 10.01s, 21.97MB read\nRequests/sec:  23236.33\nTransfer/sec:      2.19MB\n~~~\n\nAs you can see the `httpechoserver` is almost twice as fast as the dead simple `nodejs` echo server, which is not a bad performance gain over one of the web's leading technologies thats touted for it's performance. Check the `httpechoserver` sample for the full code, including the `nodejs` echo server we used for benchmarking.\n\n#### Processes\n\nInteracting with system processes and piping IO doesn't have to be painful.\nThe following code will run the `ping sourcey.com` and with `stdio` and exit callbacks:\n\n~~~cpp\nProcess proc{ \"ping\", \"sourcey.com\" };\nproc.onstdout = [](std::string line)\n{\n    // handle process output\n};\nproc.onexit = [](std::int64_t status)\n{\n    // handle process exit\n};\nproc.spawn();\n\n// write some random data to the stdin pipe\nproc.in() \u003c\u003c \"random data\"\n~~~\n\n#### Packet Stream\n\nA good starting point for learning LibSourcey is the `PacketStream`, which lets you create a dynamic delegate chain for piping, processing and outputting arbitrary data packets. This method of layering packet processors and makes it possible to develop complex data processing applications on the fly.\n\nFor example, the code below captures a live webcam stream, encodes it into H.264, and then finally broadcasts it in realtime over the internet:\n\n~~~cpp\n// Create a PacketStream to pass packets from the\n// input device captures -\u003e encoder -\u003e socket\nPacketStream stream;\n\n// Setup the encoder options\nav::EncoderOptions options;\noptions.oformat = av::Format{\"MP4\", \"mp4\",\n    { \"H.264\", \"libx264\", 640, 480, 25, 48000, 128000, \"yuv420p\" },\n    { \"AAC\", \"aac\", 2, 44100, 64000, \"fltp\" }};\n\n// Create a device manager instance to enumerate system devices\nav::DeviceManager devman;\nav::Device device;\n\n// Create and attach the default video capture\nav::VideoCapture::Ptr video;\nif (devman.getDefaultCamera(device)) {\n    video.open(device.id, 640, 480);\n    video.getEncoderFormat(options.iformat);\n    stream.attachSource(video, true);\n}\n\n// Create and attach the default audio capture\nav::AudioCapture::Ptr audio;\nif (devman.getDefaultMicrophone(device)) {\n    audio.open(device.id, 2, 44100);\n    audio.getEncoderFormat(options.iformat);\n    stream.attachSource(audio, true);\n}\n\n// Create and attach the multiplex encoder\nav::MultiplexPacketEncoder::Ptr encoder(options);\nstream.attach(encoder);\n\n// Attach the output net::Socket instance (instantiated elsewhere)\n// to broadcast encoded packets over the network\nstream.attach(socket);\n\n// Start the stream\n// This method call will start the device captures and begin\n// pumping encoded media into the output socket\nstream.start();\n~~~\n\nThere are plenty more demos and sample code to play with over on the [examples](https://sourcey.com/libsourcey/examples/) page.\n\n## Contributors\n\nA massive thanks to everyone who has contributed to making LibSourcey awesome:\n\n* Kam Low ([@auscaster](https://github.com/auscaster)) — Primary developer\n* Yury Shulbn ([@yuryshubin](https://github.com/yuryshubin)) — iOS build toolchain and platform fixes\n* Vinci Xu ([@VinciShark](https://github.com/VinciShark)) — Windows documentation, testing and updates\n* Michael Fig ([@michael-fig](https://github.com/michael-fig)) — Fixed compiler flags to build without FFmpeg\n* Hyunuk Kim ([@surinkim](https://github.com/surinkim)) — Fixed `std::codecvt` unicode character conversion on Windows\n* Damian Zelim ([@ZelimDamian](https://github.com/ZelimDamian)) — Fixed compiler flags for OS X build\n* Norm Ovenseri ([@normano](https://github.com/normano)) — Added verbose logging output to build system\n* Alexey ([@deilos](https://github.com/deilos)) — Fixed cross-platform FFmpeg build script\n* Kryton ([@Malesio](https://github.com/Malesio)) — Fixed segfaults in samples and tidied up Valgrind warnings\n\n\n## Contributing\n\nPull Requests are always welcome, so if you fix or make anything better then feel free to float a PR back upstream :)\n\n1. [Fork LibSourcey on Github](https://github.com/sourcey/libsourcey)\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n\n\u003c!--\n## Issues\n\nFor bugs and issues please use the [Github issue tracker](https://github.com/sourcey/libsourcey/issues).\n--\u003e\n","funding_links":[],"categories":["TODO scan for Android support in followings","Frameworks","C++","框架"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsourcey%2Flibsourcey","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsourcey%2Flibsourcey","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsourcey%2Flibsourcey/lists"}