Video recording using media session causes latency in streaming

I am developing a desktop application to record video and stream from a USB camera using MediaSession . I have implemented video and audio capture. Also, my application has a Play / Pause / Stop state implemented , but I ran into an issue after resuming a video from a pause state.

Using the IMFMediaSession :: Start method , I resumed capturing the video from paused state. There is too much lag in the preview after calling this method. When video recording is resumed, media samples are queued.

I have created an asynchronous recording session ... Please find the following piece of code,

HRESULT SetTopologyFunc()
{
    hr = MFCreateMediaSession(NULL, &m_pMediaSession);  if(FAILED(hr))  {   return hr;  }

    if(m_pMediaSession != NULL)
    {
        hr = m_pMediaSession->BeginGetEvent((IMFAsyncCallback*)this, NULL); if(FAILED(hr))  {   return hr;  }
    }

    // Create a blank topology
    hr = MFCreateTopology(&pTopology);  if(FAILED(hr))  {   return hr;  }

    // Set the topology on the media session.       
    hr = m_pMediaSession->SetTopology(MFSESSION_SETTOPOLOGY_IMMEDIATE, pTopology);  if(FAILED(hr))  {   return hr;  }
}

HRESULT StartPlayback()
{
    HRESULT hr = S_OK;
    PROPVARIANT varStart;
    PropVariantInit(&varStart);
    varStart.vt = VT_EMPTY;     

    hr = m_pMediaSession->Start(&GUID_NULL, &varStart);     if (SUCCEEDED(hr))  {    m_state = Started; }

    PropVariantClear(&varStart);

    return hr;
}

HRESULT  CResumeVideoCapture()
{
    HRESULT hr = S_OK;

    if (m_state != Paused && m_state != Stopped)        {   return MF_E_INVALIDREQUEST; }
    if (m_pMediaSession == NULL || m_pMediaSource == NULL)  {   return E_UNEXPECTED;    }

    hr = StartPlayback();

    return hr;
}

HRESULT CStopVideoCapture()
{
    if (m_state != Started && m_state != Paused)        {   return MF_E_INVALIDREQUEST; }
    if (m_pMediaSession == NULL || m_pMediaSource == NULL)  {   return E_UNEXPECTED;    }

    HRESULT hr = m_pMediaSession->Stop();   if (SUCCEEDED(hr))  {    m_state = Stopped; }

    return hr;
}

HRESULT CPauseVideoCapture()
{
    if (m_state != Started) {   return MF_E_INVALIDREQUEST; }
    if (m_pMediaSession == NULL || m_pMediaSource == NULL)  {   return E_UNEXPECTED;    }

    HRESULT hr = m_pMediaSession->Pause();  if (SUCCEEDED(hr))  {    m_state = Paused;  }

    return hr;
}

      

I already tried the IMFSourceReader method to capture video and audio together, but I could not combine both. For this reason, I switched to the multimedia session technique. Everything is working fine, but I have no control over the state of the presentation.

To clear the sample queues in the topig, I tried IMFMediaSession :: ClearTopologies and IMFMediaSession :: SetTopology using the MFSESSION_SETTOPOLOGY_CLEAR_CURRENT methods before resuming recording.

Can you guide me to control the state of the presentation while recording video in a media session?

+3


source to share





All Articles