LibSourceyC++ 高性能網(wǎng)絡(luò)開發(fā)庫
LibSourcey 是跨平臺(tái) C++11 模塊和類的集合,為開發(fā)人員提供了一個(gè)快速開發(fā)基于 p2p 和媒體流應(yīng)用程序的高性能網(wǎng)絡(luò)的庫??梢园阉醋?libuv 與 FFmpeg,OpenCV 和 WebRTC 特性的高度結(jié)合,所有這些都具有 stl(C++標(biāo)準(zhǔn)庫)的易用性和可讀性。
使用 LibSourcey 一個(gè)很好的出發(fā)點(diǎn)是 PacketStream,它可用來創(chuàng)建用于管道,處理并輸出任意數(shù)據(jù)分組的動(dòng)態(tài)委托鏈。分層分組處理器和動(dòng)態(tài)功能的方法使得它能夠快速且容易地開發(fā)出復(fù)雜的數(shù)據(jù)處理應(yīng)用程序。
例如,下面的代碼將介紹如何捕捉實(shí)時(shí)攝像頭流,將其編碼為 H.264,并通過互聯(lián)網(wǎng)實(shí)時(shí)廣播它:
// 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();評(píng)論
圖片
表情
