mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 10:40:05 +08:00
Fix crash issue when exit test_player
This commit is contained in:
parent
4d28b99780
commit
306a32131c
@ -10,6 +10,7 @@
|
||||
|
||||
#include <signal.h>
|
||||
#include "Util/logger.h"
|
||||
#include "Util/util.h"
|
||||
#include <iostream>
|
||||
#include "Common/config.h"
|
||||
#include "Rtsp/UDPServer.h"
|
||||
@ -48,6 +49,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstanc, LPSTR lpCmdLine,
|
||||
int main(int argc, char *argv[]) {
|
||||
#endif
|
||||
static char *url = argv[1];
|
||||
{
|
||||
// 设置退出信号处理函数
|
||||
signal(SIGINT, [](int) { SDLDisplayerHelper::Instance().shutdown(); });
|
||||
// 设置日志
|
||||
@ -83,9 +85,7 @@ int main(int argc, char *argv[]) {
|
||||
return true;
|
||||
});
|
||||
});
|
||||
videoTrack->addDelegate([decoder](const Frame::Ptr &frame) {
|
||||
return decoder->inputFrame(frame, false, true);
|
||||
});
|
||||
videoTrack->addDelegate([decoder](const Frame::Ptr &frame) { return decoder->inputFrame(frame, false, true); });
|
||||
}
|
||||
|
||||
if (audioTrack) {
|
||||
@ -97,22 +97,17 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
decoder->setOnDecode([audio_player, swr](const FFmpegFrame::Ptr &frame) mutable {
|
||||
if (!swr) {
|
||||
swr = std::make_shared<FFmpegSwr>(AV_SAMPLE_FMT_S16, frame->get()->channels,
|
||||
frame->get()->channel_layout, frame->get()->sample_rate);
|
||||
swr = std::make_shared<FFmpegSwr>(AV_SAMPLE_FMT_S16, frame->get()->channels, frame->get()->channel_layout, frame->get()->sample_rate);
|
||||
}
|
||||
auto pcm = swr->inputFrame(frame);
|
||||
auto len = pcm->get()->nb_samples * pcm->get()->channels * av_get_bytes_per_sample((enum AVSampleFormat)pcm->get()->format);
|
||||
audio_player->playPCM((const char *)(pcm->get()->data[0]), MIN(len, frame->get()->linesize[0]));
|
||||
});
|
||||
audioTrack->addDelegate([decoder](const Frame::Ptr &frame) {
|
||||
return decoder->inputFrame(frame, false, true);
|
||||
});
|
||||
audioTrack->addDelegate([decoder](const Frame::Ptr &frame) { return decoder->inputFrame(frame, false, true); });
|
||||
}
|
||||
});
|
||||
|
||||
player->setOnShutdown([](const SockException &ex){
|
||||
WarnL << "play shutdown: " << ex.what();
|
||||
});
|
||||
player->setOnShutdown([](const SockException &ex) { WarnL << "play shutdown: " << ex.what(); });
|
||||
|
||||
(*player)[Client::kRtpType] = atoi(argv[2]);
|
||||
// 不等待track ready再回调播放成功事件,这样可以加快秒开速度
|
||||
@ -122,6 +117,8 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
player->play(argv[1]);
|
||||
SDLDisplayerHelper::Instance().runLoop();
|
||||
}
|
||||
sleep(1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user