新增ps解析器c api (#4172)

This commit is contained in:
桑泽寰
2025-02-28 12:49:47 +08:00
committed by GitHub
parent c0a93f3c8f
commit e677e41502
2 changed files with 68 additions and 1 deletions

View File

@@ -11,6 +11,7 @@
#include "mk_frame.h"
#include "Record/MPEG.h"
#include "Extension/Factory.h"
#include "Rtp/PSDecoder.h"
using namespace mediakit;
@@ -223,4 +224,36 @@ API_EXPORT int API_CALL mk_mpeg_muxer_input_frame(mk_mpeg_muxer ctx, mk_frame fr
assert(ctx && frame);
auto ptr = reinterpret_cast<MpegMuxerForC *>(ctx);
return ptr->inputFrame(*((Frame::Ptr *) frame));
}
}
//////////////////////////////////////////////////////////////////////
#if defined(ENABLE_RTPPROXY)
API_EXPORT mk_ps_decoder API_CALL mk_ps_decoder_create(on_mk_ps_decoder_stream scb, on_mk_ps_decoder_frame dcb, void * user_data) {
assert(dcb);
auto ps_decoder = new PSDecoder();
std::shared_ptr<void> ptr(user_data, [](void *) {});
if (scb) {
ps_decoder->setOnStream([ptr,scb](int stream, int codecid, const void *extra, size_t bytes, int finish) {
scb(ptr.get(), stream, getCodecByMpegId(codecid), extra, bytes, finish);
});
}
ps_decoder->setOnDecode([ptr,dcb](int stream, int codecid, int flags, int64_t pts, int64_t dts, const void *data, size_t bytes) {
dcb(ptr.get(), stream,getCodecByMpegId(codecid),flags,pts,dts,data,bytes);
});
return reinterpret_cast<mk_ps_decoder>(ps_decoder);
}
API_EXPORT void API_CALL mk_ps_decoder_release(mk_ps_decoder ctx) {
assert(ctx);
auto ptr = reinterpret_cast<PSDecoder *>(ctx);
delete ptr;
}
API_EXPORT void API_CALL mk_ps_decoder_input(mk_ps_decoder ctx, const char * data, size_t bytes) {
assert(ctx && data);
auto ptr = reinterpret_cast<PSDecoder *>(ctx);
ptr->input(reinterpret_cast<const uint8_t *>(data), bytes);
}
#endif