void FramedSource::stopGettingFrames() {
  fIsCurrentlyAwaitingData = False; // indicates that we can be read again
  fAfterGettingFunc = NULL;
  fOnCloseFunc = NULL;

  // Perform any specialized action now:
  doStopGettingFrames();
}
void EasyCameraSource::stopGettingFrames() 
{
	OSMutexLocker locker(this->GetMutex());
	fOnCloseFunc = NULL;
	doStopGettingFrames();
}
void LiveVideoStreamSource::deliverFrame() {
    // This function is called when new frame data is available from the device.
    // We deliver this data by copying it to the 'downstream' object, using the following parameters (class members):
    // 'in' parameters (these should *not* be modified by this function):
    //     fTo: The frame data is copied to this address.
    //         (Note that the variable "fTo" is *not* modified.  Instead,
    //          the frame data is copied to the address pointed to by "fTo".)
    //     fMaxSize: This is the maximum number of bytes that can be copied
    //         (If the actual frame is larger than this, then it should
    //          be truncated, and "fNumTruncatedBytes" set accordingly.)
    // 'out' parameters (these are modified by this function):
    //     fFrameSize: Should be set to the delivered frame size (<= fMaxSize).
    //     fNumTruncatedBytes: Should be set iff the delivered frame would have been
    //         bigger than "fMaxSize", in which case it's set to the number of bytes
    //         that have been omitted.
    //     fPresentationTime: Should be set to the frame's presentation time
    //         (seconds, microseconds).  This time must be aligned with 'wall-clock time' - i.e., the time that you would get
    //         by calling "gettimeofday()".
    //     fDurationInMicroseconds: Should be set to the frame's duration, if known.
    //         If, however, the device is a 'live source' (e.g., encoded from a camera or microphone), then we probably don't need
    //         to set this variable, because - in this case - data will never arrive 'early'.
    // Note the code below.

    // we're not ready for the data yet
    if (!isCurrentlyAwaitingData()) {
		printf("Frame LOSS!!!!!!!!\n");
        return;
	}

    VENC_CHN_STAT_S stStat;
    VENC_STREAM_S stStream;
    HI_S32 s32Ret;

    s32Ret = HI_MPI_VENC_Query(fChannelNo, &stStat);
    if (HI_SUCCESS != s32Ret)
    {
        return;
    }

    if (stStat.u32CurPacks <= 0) {
        return;
    }

    stStream.pstPack = (VENC_PACK_S *)alloca(sizeof(VENC_PACK_S) * stStat.u32CurPacks);
    stStream.u32PackCount = stStat.u32CurPacks;
    stStream.u32Seq = 0;
    memset(&stStream.stH264Info, 0, sizeof(VENC_STREAM_INFO_H264_S));
    s32Ret = HI_MPI_VENC_GetStream(fChannelNo, &stStream, HI_FALSE);
    if (HI_SUCCESS != s32Ret)
    {
        g_critical("HI_MPI_VENC_GetStream failed with %#x!\n", s32Ret);
        return;
    }

    fPresentationTime.tv_sec = stStream.pstPack[0].u64PTS / 1000000UL;
    fPresentationTime.tv_usec = stStream.pstPack[0].u64PTS % 1000000UL;

    fFrameSize = 0;
    for (int i = 0; i < stStream.u32PackCount; i++) {
        for (int j = 0; j < ARRAY_SIZE(stStream.pstPack[i].pu8Addr); j++) {
            HI_U8 *p = stStream.pstPack[i].pu8Addr[j];
            HI_U32 len = stStream.pstPack[i].u32Len[j];

            if (len == 0)
                continue;

            if (len >= 3 && p[0] == 0x00 && p[1] == 0x00 && p[2] == 0x01) {
                p += 3;
                len -= 3;
            }
            if (len >= 4 && p[0] == 0x00 && p[1] == 0x00 && p[2] == 0x00 && p[3] == 0x01) {
                p += 4;
                len -= 4;
            }

            if (fFrameSize + len > fMaxSize) {
                g_critical("Package Length execute the fMaxSize\n");
                break;
            }

            memmove(&fTo[fFrameSize], p, len);
            fFrameSize += len;
        }
    }

    s32Ret = HI_MPI_VENC_ReleaseStream(fChannelNo, &stStream);
    if (HI_SUCCESS != s32Ret)
    {
        g_critical("HI_MPI_VENC_ReleaseStream failed with %#x!\n", s32Ret);
    }

	doStopGettingFrames();

    // After delivering the data, inform the reader that it is now available:
    FramedSource::afterGetting(this);
}