IMFByteStream become unusable after the IMFMediaSource is shutdown. Playing mp3 playlist using Microsoft Media Foundation

Widyo Wicaksono 1 Reputation point
2021-08-13T07:07:19.923+00:00

Hello,
This is my first question here. I apologize in advance if I make some mistakes.

I'm writing a software that call a customer number (audio/voiced) when a button is pressed with as little delay as possible. It's for Windows 10, using C++ on MS Visual Studio 2017. The requirement are as follows:

  1. Load all the mp3 files onto memory
  2. Whenever signal is received/button is pressed, construct a playlist containing only relevant mp3 files to the customer number being called
  3. Play the playlist on certain designated audio output device (there are multiple soundcards installed)
  4. Destroy the playlist after the session ended

I have tried the Playlist sample from Microsoft Media Foundation sample and it worked. Unfortunately the sample does not preload all mp3 files onto the memory so there are couple hundred ms delay each time the playlist is played.

I also have tried using bytestream (IMFByteStream). I load all the mp3 files onto vector of IMFByteStream pointers, then everytime signal received/button pressed, I construct the media source (IMFMediaSource). Unfortunately it only ran once. After the media source is shutdown after the session ended, the bytestream became unusable (error "the provided bytestream expected to be seekable" when trying to create media source using CreateObjectFromByteStream).

hr = pSourceResolver->CreateObjectFromByteStream(m_pMediaStreams[media_source_index].pStream, NULL, MF_RESOLUTION_MEDIASOURCE, NULL, &ObjectType, &pSource);

Clearly I did something wrong. Any hints and pointers are greatly appreciated. If some portions of the code are needed then I will post it here. The code is big and I don't know which parts are relevant.

Many thanks.

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,426 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,537 questions
{count} votes