mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 19:00:01 +08:00
Player: 播放器改成同步解码
This commit is contained in:
parent
ded5d83e04
commit
34d833a1ed
@ -263,8 +263,8 @@ bool FFmpegDecoder::inputFrame_l(const Frame::Ptr &frame) {
|
|||||||
return decodeFrame(frame->data(), frame->size(), frame->dts(), frame->pts());
|
return decodeFrame(frame->data(), frame->size(), frame->dts(), frame->pts());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FFmpegDecoder::inputFrame(const Frame::Ptr &frame) {
|
bool FFmpegDecoder::inputFrame(const Frame::Ptr &frame, bool may_async) {
|
||||||
if (!TaskManager::isEnabled()) {
|
if (!may_async || !TaskManager::isEnabled()) {
|
||||||
return inputFrame_l(frame);
|
return inputFrame_l(frame);
|
||||||
}
|
}
|
||||||
auto frame_cache = Frame::getCacheAbleFrame(frame);
|
auto frame_cache = Frame::getCacheAbleFrame(frame);
|
||||||
|
@ -87,7 +87,7 @@ private:
|
|||||||
std::shared_ptr<thread> _thread;
|
std::shared_ptr<thread> _thread;
|
||||||
};
|
};
|
||||||
|
|
||||||
class FFmpegDecoder : public FrameWriterInterface, private TaskManager {
|
class FFmpegDecoder : private TaskManager {
|
||||||
public:
|
public:
|
||||||
using Ptr = std::shared_ptr<FFmpegDecoder>;
|
using Ptr = std::shared_ptr<FFmpegDecoder>;
|
||||||
using onDec = function<void(const FFmpegFrame::Ptr &)>;
|
using onDec = function<void(const FFmpegFrame::Ptr &)>;
|
||||||
@ -95,7 +95,7 @@ public:
|
|||||||
FFmpegDecoder(const Track::Ptr &track);
|
FFmpegDecoder(const Track::Ptr &track);
|
||||||
~FFmpegDecoder();
|
~FFmpegDecoder();
|
||||||
|
|
||||||
bool inputFrame(const Frame::Ptr &frame) override;
|
bool inputFrame(const Frame::Ptr &frame, bool may_async = true);
|
||||||
void setOnDecode(onDec cb);
|
void setOnDecode(onDec cb);
|
||||||
void flush();
|
void flush();
|
||||||
const AVCodecContext *getContext() const;
|
const AVCodecContext *getContext() const;
|
||||||
|
@ -84,7 +84,7 @@ int main(int argc, char *argv[]) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
auto delegate = std::make_shared<FrameWriterInterfaceHelper>([decoder](const Frame::Ptr &frame) {
|
auto delegate = std::make_shared<FrameWriterInterfaceHelper>([decoder](const Frame::Ptr &frame) {
|
||||||
return decoder->inputFrame(frame);
|
return decoder->inputFrame(frame, false);
|
||||||
});
|
});
|
||||||
videoTrack->addDelegate(delegate);
|
videoTrack->addDelegate(delegate);
|
||||||
}
|
}
|
||||||
@ -106,7 +106,7 @@ int main(int argc, char *argv[]) {
|
|||||||
audio_player->playPCM((const char *) (pcm->get()->data[0]), len);
|
audio_player->playPCM((const char *) (pcm->get()->data[0]), len);
|
||||||
});
|
});
|
||||||
auto audio_delegate = std::make_shared<FrameWriterInterfaceHelper>( [decoder](const Frame::Ptr &frame) {
|
auto audio_delegate = std::make_shared<FrameWriterInterfaceHelper>( [decoder](const Frame::Ptr &frame) {
|
||||||
return decoder->inputFrame(frame);
|
return decoder->inputFrame(frame, false);
|
||||||
});
|
});
|
||||||
audioTrack->addDelegate(audio_delegate);
|
audioTrack->addDelegate(audio_delegate);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user