mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 10:40:05 +08:00
修复异步addDelegate导致丢帧的问题
This commit is contained in:
parent
8092cb446e
commit
1df3859c98
@ -1 +1 @@
|
||||
Subproject commit ec50224e4094b91be10a40ba221793706676b2b9
|
||||
Subproject commit 03d0953f91e0a75fa8e95fce032ff9d3bef04789
|
@ -25,6 +25,7 @@
|
||||
*/
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#include "Util/util.h"
|
||||
#include "Util/logger.h"
|
||||
#include <iostream>
|
||||
#include "Poller/EventPoller.h"
|
||||
@ -68,22 +69,27 @@ int main(int argc, char *argv[]) {
|
||||
WarnL << "没有视频或者视频不是264编码!";
|
||||
return;
|
||||
}
|
||||
SDLDisplayerHelper::Instance().doTask([viedoTrack]() {
|
||||
std::shared_ptr<H264Decoder> decoder(new H264Decoder);
|
||||
std::shared_ptr<YuvDisplayer> displayer(new YuvDisplayer);
|
||||
viedoTrack->addDelegate(std::make_shared<FrameWriterInterfaceHelper>([decoder, displayer](const Frame::Ptr &frame) {
|
||||
SDLDisplayerHelper::Instance().doTask([decoder, displayer, frame]() {
|
||||
AVFrame *pFrame = nullptr;
|
||||
bool flag = decoder->inputVideo((unsigned char *) frame->data(), frame->size(),
|
||||
frame->stamp(), &pFrame);
|
||||
if (flag) {
|
||||
displayer->displayYUV(pFrame);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}));
|
||||
return true;
|
||||
});
|
||||
|
||||
AnyStorage::Ptr storage(new AnyStorage);
|
||||
viedoTrack->addDelegate(std::make_shared<FrameWriterInterfaceHelper>([storage](const Frame::Ptr &frame) {
|
||||
SDLDisplayerHelper::Instance().doTask([frame,storage]() {
|
||||
auto &decoder = (*storage)["decoder"];
|
||||
auto &displayer = (*storage)["displayer"];
|
||||
if(!decoder){
|
||||
decoder.set<H264Decoder>();
|
||||
}
|
||||
if(!displayer){
|
||||
displayer.set<YuvDisplayer>();
|
||||
}
|
||||
|
||||
AVFrame *pFrame = nullptr;
|
||||
bool flag = decoder.get<H264Decoder>().inputVideo((unsigned char *) frame->data(), frame->size(), frame->stamp(), &pFrame);
|
||||
if (flag) {
|
||||
displayer.get<YuvDisplayer>().displayYUV(pFrame);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user