mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-25 07:34:03 -06:00
ENH: refine the timestamp when using P1P
the timestamp of mjpeg is not accurate we simulate one Change-Id: I9198f1ba930994cc4f86e8d3a3c778539d04ccb3
This commit is contained in:
parent
3d378563b5
commit
6b15afc7b6
4 changed files with 81 additions and 53 deletions
|
@ -23,11 +23,6 @@ extern "C" {
|
||||||
|
|
||||||
#ifndef __cplusplus
|
#ifndef __cplusplus
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
/* We need these workarounds since we're compiling C source, not C++. */
|
|
||||||
typedef enum Bambu_StreamType Bambu_StreamType;
|
|
||||||
typedef struct Bambu_StreamInfo Bambu_StreamInfo;
|
|
||||||
typedef struct Bambu_Sample Bambu_Sample;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
@ -40,31 +35,33 @@ typedef void* Bambu_Tunnel;
|
||||||
|
|
||||||
typedef void (*Logger)(void * context, int level, tchar const* msg);
|
typedef void (*Logger)(void * context, int level, tchar const* msg);
|
||||||
|
|
||||||
enum Bambu_StreamType
|
typedef enum __Bambu_StreamType
|
||||||
{
|
{
|
||||||
VIDE,
|
VIDE,
|
||||||
AUDI
|
AUDI
|
||||||
};
|
} Bambu_StreamType;
|
||||||
|
|
||||||
enum Bambu_VideoSubType
|
typedef enum __Bambu_VideoSubType
|
||||||
{
|
{
|
||||||
AVC1,
|
AVC1,
|
||||||
};
|
MJPG,
|
||||||
|
} Bambu_VideoSubType;
|
||||||
|
|
||||||
enum Bambu_AudioSubType
|
typedef enum __Bambu_AudioSubType
|
||||||
{
|
{
|
||||||
MP4A
|
MP4A
|
||||||
};
|
} Bambu_AudioSubType;
|
||||||
|
|
||||||
enum Bambu_FormatType
|
typedef enum __Bambu_FormatType
|
||||||
{
|
{
|
||||||
video_avc_packet,
|
video_avc_packet,
|
||||||
video_avc_byte_stream,
|
video_avc_byte_stream,
|
||||||
|
video_jpeg,
|
||||||
audio_raw,
|
audio_raw,
|
||||||
audio_adts
|
audio_adts
|
||||||
};
|
} Bambu_FormatType;
|
||||||
|
|
||||||
struct Bambu_StreamInfo
|
typedef struct __Bambu_StreamInfo
|
||||||
{
|
{
|
||||||
Bambu_StreamType type;
|
Bambu_StreamType type;
|
||||||
int sub_type;
|
int sub_type;
|
||||||
|
@ -84,33 +81,34 @@ struct Bambu_StreamInfo
|
||||||
} format;
|
} format;
|
||||||
int format_type;
|
int format_type;
|
||||||
int format_size;
|
int format_size;
|
||||||
|
int max_frame_size;
|
||||||
unsigned char const * format_buffer;
|
unsigned char const * format_buffer;
|
||||||
};
|
} Bambu_StreamInfo;
|
||||||
|
|
||||||
enum Bambu_SampleFlag
|
typedef enum __Bambu_SampleFlag
|
||||||
{
|
{
|
||||||
f_sync = 1
|
f_sync = 1
|
||||||
};
|
} Bambu_SampleFlag;
|
||||||
|
|
||||||
struct Bambu_Sample
|
typedef struct __Bambu_Sample
|
||||||
{
|
{
|
||||||
int itrack;
|
int itrack;
|
||||||
int size;
|
int size;
|
||||||
int flags;
|
int flags;
|
||||||
unsigned char const * buffer;
|
unsigned char const * buffer;
|
||||||
unsigned long long decode_time;
|
unsigned long long decode_time;
|
||||||
};
|
} Bambu_Sample;
|
||||||
|
|
||||||
enum Bambu_Error
|
typedef enum __Bambu_Error
|
||||||
{
|
{
|
||||||
Bambu_success,
|
Bambu_success,
|
||||||
Bambu_stream_end,
|
Bambu_stream_end,
|
||||||
Bambu_would_block,
|
Bambu_would_block,
|
||||||
Bambu_buffer_limit
|
Bambu_buffer_limit
|
||||||
};
|
} Bambu_Error;
|
||||||
|
|
||||||
#ifdef BAMBU_DYNAMIC
|
#ifdef BAMBU_DYNAMIC
|
||||||
struct BambuLib {
|
typedef struct __BambuLib {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
BAMBU_EXPORT int BAMBU_FUNC(Bambu_Create)(Bambu_Tunnel* tunnel, char const* path);
|
BAMBU_EXPORT int BAMBU_FUNC(Bambu_Create)(Bambu_Tunnel* tunnel, char const* path);
|
||||||
|
@ -148,7 +146,7 @@ BAMBU_EXPORT char const* BAMBU_FUNC(Bambu_GetLastErrorMsg)();
|
||||||
BAMBU_EXPORT void BAMBU_FUNC(Bambu_FreeLogMsg)(tchar const* msg);
|
BAMBU_EXPORT void BAMBU_FUNC(Bambu_FreeLogMsg)(tchar const* msg);
|
||||||
|
|
||||||
#ifdef BAMBU_DYNAMIC
|
#ifdef BAMBU_DYNAMIC
|
||||||
};
|
} BambuLib;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -910,6 +910,8 @@ StaticBambuLib &StaticBambuLib::get()
|
||||||
GET_FUNC(Bambu_Create);
|
GET_FUNC(Bambu_Create);
|
||||||
GET_FUNC(Bambu_Open);
|
GET_FUNC(Bambu_Open);
|
||||||
GET_FUNC(Bambu_StartStream);
|
GET_FUNC(Bambu_StartStream);
|
||||||
|
GET_FUNC(Bambu_GetStreamCount);
|
||||||
|
GET_FUNC(Bambu_GetStreamInfo);
|
||||||
GET_FUNC(Bambu_SendMessage);
|
GET_FUNC(Bambu_SendMessage);
|
||||||
GET_FUNC(Bambu_ReadSample);
|
GET_FUNC(Bambu_ReadSample);
|
||||||
GET_FUNC(Bambu_Close);
|
GET_FUNC(Bambu_Close);
|
||||||
|
@ -922,6 +924,6 @@ StaticBambuLib &StaticBambuLib::get()
|
||||||
return lib;
|
return lib;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" struct BambuLib *bambulib_get() {
|
extern "C" BambuLib *bambulib_get() {
|
||||||
return &StaticBambuLib::get();
|
return &StaticBambuLib::get();
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,8 +64,8 @@ extern "C"
|
||||||
#else
|
#else
|
||||||
extern
|
extern
|
||||||
#endif
|
#endif
|
||||||
struct BambuLib *bambulib_get();
|
BambuLib *bambulib_get();
|
||||||
static struct BambuLib *_lib = NULL;
|
BambuLib *_lib = NULL;
|
||||||
#define BAMBULIB(x) (_lib->x)
|
#define BAMBULIB(x) (_lib->x)
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
@ -270,7 +270,7 @@ gst_bambusrc_create (GstPushSrc * psrc, GstBuffer ** outbuf)
|
||||||
GST_DEBUG_OBJECT (src, "create()");
|
GST_DEBUG_OBJECT (src, "create()");
|
||||||
|
|
||||||
int rv;
|
int rv;
|
||||||
struct Bambu_Sample sample;
|
Bambu_Sample sample;
|
||||||
|
|
||||||
if (!src->tnl) {
|
if (!src->tnl) {
|
||||||
return GST_FLOW_ERROR;
|
return GST_FLOW_ERROR;
|
||||||
|
@ -300,12 +300,24 @@ gst_bambusrc_create (GstPushSrc * psrc, GstBuffer ** outbuf)
|
||||||
* need to feed this in too -- otherwise the GStreamer pipeline gets upset
|
* need to feed this in too -- otherwise the GStreamer pipeline gets upset
|
||||||
* and starts triggering QoS events.
|
* and starts triggering QoS events.
|
||||||
*/
|
*/
|
||||||
if (!src->sttime) {
|
if (src->video_type == AVC1) {
|
||||||
src->sttime = sample.decode_time * 100ULL;
|
if (!src->sttime) {
|
||||||
|
src->sttime = sample.decode_time * 100ULL;
|
||||||
|
}
|
||||||
|
GST_BUFFER_DTS(*outbuf) = sample.decode_time * 100ULL - src->sttime;
|
||||||
|
GST_BUFFER_PTS(*outbuf) = GST_CLOCK_TIME_NONE;
|
||||||
|
GST_BUFFER_DURATION(*outbuf) = GST_CLOCK_TIME_NONE;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (!src->sttime) {
|
||||||
|
src->sttime = gst_element_get_current_clock_time((GstElement *)psrc);
|
||||||
|
//if (GST_CLOCK_TIME_NONE == src->sttime)
|
||||||
|
// src->sttime
|
||||||
|
}
|
||||||
|
GST_BUFFER_DTS(*outbuf) = gst_element_get_current_clock_time((GstElement *)psrc) - src->sttime;
|
||||||
|
GST_BUFFER_PTS(*outbuf) = GST_CLOCK_TIME_NONE;
|
||||||
|
GST_BUFFER_DURATION(*outbuf) = GST_CLOCK_TIME_NONE;
|
||||||
}
|
}
|
||||||
GST_BUFFER_DTS(*outbuf) = sample.decode_time * 100ULL - src->sttime;
|
|
||||||
GST_BUFFER_PTS(*outbuf) = GST_CLOCK_TIME_NONE;
|
|
||||||
GST_BUFFER_DURATION(*outbuf) = GST_CLOCK_TIME_NONE;
|
|
||||||
|
|
||||||
return GST_FLOW_OK;
|
return GST_FLOW_OK;
|
||||||
}
|
}
|
||||||
|
@ -348,7 +360,7 @@ gst_bambusrc_start (GstBaseSrc * bsrc)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rv;
|
int rv, n = 0;
|
||||||
while ((rv = BAMBULIB(Bambu_StartStream)(src->tnl, 1 /* video */)) == Bambu_would_block) {
|
while ((rv = BAMBULIB(Bambu_StartStream)(src->tnl, 1 /* video */)) == Bambu_would_block) {
|
||||||
usleep(100000);
|
usleep(100000);
|
||||||
}
|
}
|
||||||
|
@ -359,6 +371,21 @@ gst_bambusrc_start (GstBaseSrc * bsrc)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
src->video_type = AVC1;
|
||||||
|
n = BAMBULIB(Bambu_GetStreamCount)(src->tnl);
|
||||||
|
GST_INFO_OBJECT (src, "Bambu_GetStreamCount returned stream count=%d",n);
|
||||||
|
for (int i = 0; i < n; ++i) {
|
||||||
|
Bambu_StreamInfo info;
|
||||||
|
BAMBULIB(Bambu_GetStreamInfo)(src->tnl, i, &info);
|
||||||
|
|
||||||
|
GST_INFO_OBJECT (src, "stream %d type=%d, sub_type=%d", i, info.type, info.sub_type);
|
||||||
|
if (info.type == VIDE) {
|
||||||
|
src->video_type = info.sub_type;
|
||||||
|
GST_INFO_OBJECT (src, " width %d height=%d, frame_rate=%d",
|
||||||
|
info.format.video.width, info.format.video.height, info.format.video.frame_rate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
src->sttime = 0;
|
src->sttime = 0;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,6 +64,7 @@ struct _GstBambuSrc
|
||||||
gchar *location;
|
gchar *location;
|
||||||
Bambu_Tunnel tnl;
|
Bambu_Tunnel tnl;
|
||||||
GstClockTime sttime;
|
GstClockTime sttime;
|
||||||
|
int video_type;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern void gstbambusrc_register();
|
extern void gstbambusrc_register();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue