static GstFlowReturn onNewSampleFromAppSink()

in source/src/AppRtspSrc.c [197:263]


static GstFlowReturn onNewSampleFromAppSink(GstElement* sink, gpointer udata, UINT64 trackid)
{
    STATUS retStatus = STATUS_SUCCESS;
    PRtspSrcContext pRtspSrcContext = (PRtspSrcContext) udata;
    Frame frame;
    BOOL isDroppable, delta;
    GstFlowReturn gstFlowReturn = GST_FLOW_OK;
    GstSample* sample = NULL;
    GstBuffer* buffer;
    GstMapInfo info;
    GstSegment* segment;
    GstClockTime buf_pts;

    info.data = NULL;
    CHK((sink != NULL) && (pRtspSrcContext != NULL), STATUS_MEDIA_NULL_ARG);

    sample = app_gst_app_sink_pull_sample(APP_GST_APP_SINK(sink));
    buffer = app_gst_sample_get_buffer(sample);

    isDroppable = GST_BUFFER_FLAG_IS_SET(buffer, GST_BUFFER_FLAG_CORRUPTED) || //!< the buffer data is corrupted.
        GST_BUFFER_FLAG_IS_SET(buffer, GST_BUFFER_FLAG_DECODE_ONLY) || (GST_BUFFER_FLAGS(buffer) == GST_BUFFER_FLAG_DISCONT) ||
        (GST_BUFFER_FLAG_IS_SET(buffer, GST_BUFFER_FLAG_DISCONT) && GST_BUFFER_FLAG_IS_SET(buffer, GST_BUFFER_FLAG_DELTA_UNIT)) ||
        // drop if buffer contains header only and has invalid timestamp
        !GST_BUFFER_PTS_IS_VALID(buffer);

    if (!isDroppable) {
        delta = GST_BUFFER_FLAG_IS_SET(buffer, GST_BUFFER_FLAG_DELTA_UNIT);

        frame.flags = delta ? FRAME_FLAG_NONE : FRAME_FLAG_KEY_FRAME;
        segment = app_gst_sample_get_segment(sample);
        buf_pts = app_gst_segment_to_running_time(segment, GST_FORMAT_TIME, buffer->pts);
        if (!GST_CLOCK_TIME_IS_VALID(buf_pts)) {
            DLOGI("frame contains invalid PTS, dropping the frame.");
            goto CleanUp;
        }
        if (!(app_gst_buffer_map(buffer, &info, GST_MAP_READ))) {
            DLOGI("media buffer mapping failed");
            goto CleanUp;
        }
        frame.trackId = trackid;
        frame.duration = 0;
        frame.version = FRAME_CURRENT_VERSION;
        frame.size = (UINT32) info.size;
        frame.frameData = (PBYTE) info.data;
        frame.presentationTs = buf_pts * DEFAULT_TIME_UNIT_IN_NANOS;
        frame.decodingTs = frame.presentationTs;
        if (pRtspSrcContext->mediaSinkHook != NULL) {
            retStatus = pRtspSrcContext->mediaSinkHook(pRtspSrcContext->mediaSinkHookUserdata, &frame);
        }
    }

CleanUp:

    if (info.data != NULL) {
        app_gst_buffer_unmap(buffer, &info);
    }
    if (sample != NULL) {
        app_gst_sample_unref(sample);
    }
    if (STATUS_FAILED(retStatus)) {
        gstFlowReturn = GST_FLOW_EOS;
    }
    if (pRtspSrcContext != NULL && (gstFlowReturn == GST_FLOW_EOS || ATOMIC_LOAD_BOOL(&pRtspSrcContext->shutdownRtspSrc))) {
        closeGstRtspSrc(pRtspSrcContext);
    }
    return gstFlowReturn;
}