LibSourceyC++ 高性能网络开发库
LibSourcey 是跨平台 C++11 模块和类的集合,为开发人员提供了一个快速开发基于 p2p 和媒体流应用程序的高性能网络的库。可以把它看作 libuv 与 FFmpeg,OpenCV 和 WebRTC 特性的高度结合,所有这些都具有 stl(C++标准库)的易用性和可读性。
使用 LibSourcey 一个很好的出发点是 PacketStream,它可用来创建用于管道,处理并输出任意数据分组的动态委托链。分层分组处理器和动态功能的方法使得它能够快速且容易地开发出复杂的数据处理应用程序。
例如,下面的代码将介绍如何捕捉实时摄像头流,将其编码为 H.264,并通过互联网实时广播它:
// Create a PacketStream to pass packets from the
// input device captures => encoder => socket
PacketStream stream;
// Setup the encoder options
av::EncoderOptions options;
options.oformat = av::Format("MP4", "mp4",
av::VideoCodec("H.264", "libx264", 400, 300, 25, 48000, 128000, "yuv420p"),
av::AudioCodec("AAC", "libfdk_aac", 2, 44100, 64000, "s16"));
// Create a device manager instance to enumerate system devices
av::DeviceManager devman;
av::Device device;
// Create and attach the default video capture
av::VideoCapture::Ptr video;
if (devman.getDefaultCamera(device)) {
video.open(device.id, 640, 480, 30);
video.getEncoderFormat(options.iformat);
stream.attachSource(video, true);
}
// Create and attach the default audio capture
av::AudioCapture::Ptr audio;
if (devman.getDefaultMicrophone(device)) {
audio.open(device.id, 2, 44100);
audio.getEncoderFormat(options.iformat);
stream.attachSource(audio, true);
}
// Create and attach the multiplex encoder
av::MultiplexPacketEncoder::Ptr encoder(options);
stream.attach(encoder);
// Attach the output net::Socket instance (instantiated elsewhere)
// to broadcast encoded packets over the network
stream.attach(socket);
// Start the stream
// This method call will start the device captures and begin
// pumping encoded media into the output socket
stream.start();评论
