gpt4 book ai didi

facebook - 如何使用 Proxygen 和 Folly 发送 HTTP 分块响应来模拟视频流?

转载 作者:可可西里 更新时间:2023-11-01 16:37:24 26 4
gpt4 key购买 nike

我正在编写一个基于 Facebook 的 Proxygen 的 HTTP 视频流服务器。没有寻求计划。使用 proxygen::ResponseBuilder 我能够发送 webm 编码视频 block 作为 HTTP 响应,即分块传输编码正在工作。我的问题是,Proxygen 在发送响应 header 之前等待 proxygen::ResponseBuilder::sendWithEOM()。我希望它在每次调用 proxygen::ResponseBuilder::send() 后尽快发送数据。

我尝试使用 evb->runInLoop()evb->runInEventBaseThread() 从 EventBaseThread 执行的 lambda 运行 ResponseBuilder 调用

using namespace folly;
using namespace proxygen;

std::thread t([&](){
EventBase* evb = EventBaseManager::get()->getExistingEventBase();
// send headers ...
while ( chunks avail. ) {
//...
evb->runInLoop([&](){
ResponseBuilder(downstream_)
.body(std::move(chunk))
.send();
});
//...
}
// sendWithEOM ...
});
t.detach();

此代码是从我的 RequestHandleronRequest() 方法调用的。我尝试调用 ResponseBuilder::send() 而不将其包装到 evb->runInLoop() 中,但是 Proxygen v0.25.0 和 Folly v0.42.0 禁止调用 ResponseBuilder::send() 来自另一个使用断言的线程。我从这里删除了这个断言:https://github.com/facebook/folly/blob/v0.42.0/folly/io/async/EventBase.cpp#L491 .

现在模拟流可以正常工作,但如果有并行请求,它就会崩溃。我想它不应该像这样使用,这就是断言的目的。但也许有人知道如何为我的用例正确使用 Proxygen 基础设施?

最佳答案

同样的问题。我用这样的东西让它工作。

folly::EventBase* eventBase = folly::EventBaseManager::get()->getExistingEventBase();
thread t([&, eventBase]() {
while( chunks exist ) {
auto chunk = getChunk();
eventBase->runInEventBaseThread([&, chunk=chunk]() mutable {
ResponseBuilder(downstream_).body(move(chunk)).send();
});
}
});
// sendWithEOM ...
t.detach();

关于facebook - 如何使用 Proxygen 和 Folly 发送 HTTP 分块响应来模拟视频流?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30847200/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com