@@ -26,18 +26,43 @@ using namespace firebolt::rialto;
2626uint32_t WaitForNeedDataRequest (int32_t sourceId, int timeoutMs = 5000 )
2727{
2828 std::unique_lock<std::mutex> lock (g_needDataMutex);
29- if (!g_needDataCv.wait_for (lock, std::chrono::milliseconds (timeoutMs), [sourceId]{
30- return !g_needDataQueue.empty () && g_needDataQueue.front ().sourceId == sourceId;
31- }))
29+
30+ // Wait until a matching event is in the queue
31+ bool ok = g_needDataCv.wait_for (lock, std::chrono::milliseconds (timeoutMs), [&]{
32+ std::queue<NeedDataRequestEvent> tmp = g_needDataQueue;
33+ while (!tmp.empty ()) {
34+ if (tmp.front ().sourceId == sourceId)
35+ return true ;
36+ tmp.pop ();
37+ }
38+ return false ;
39+ });
40+
41+ if (!ok)
3242 {
43+ fprintf (stderr, " ERROR: Timeout waiting for need-data for source %d\n " , sourceId);
3344 return UINT32_MAX;
3445 }
3546
36- uint32_t requestId = g_needDataQueue.front ().requestId ;
37- g_needDataQueue.pop ();
47+ uint32_t requestId = UINT32_MAX;
48+ size_t qSize = g_needDataQueue.size ();
49+ for (size_t i = 0 ; i < qSize; ++i) {
50+ NeedDataRequestEvent ev = g_needDataQueue.front ();
51+ g_needDataQueue.pop ();
52+
53+ if (ev.sourceId == sourceId && requestId == UINT32_MAX) {
54+ requestId = ev.requestId ;
55+
56+ } else {
57+ g_needDataQueue.push (ev);
58+ }
59+ }
60+
3861 return requestId;
3962}
4063
64+
65+
4166void LoadAndDemuxSegment (Mp4Demux &mp4Demux, const char *path)
4267{
4368 char fullpath[512 ];
@@ -142,7 +167,7 @@ void ConfigureVideo()
142167 }
143168 CodecData codecData;
144169 const char *codec_ptr = trackVideo.codec_data .c_str ();
145- codecData.data = std::vector<uint8_t >( codec_ptr, & codec_ptr[ trackVideo.codec_data .size ()] );
170+ codecData.data = std::vector<uint8_t >( codec_ptr, codec_ptr + trackVideo.codec_data .size () );
146171
147172 std::unique_ptr<IMediaPipeline::MediaSourceVideo> sourceVideo =
148173 std::make_unique<IMediaPipeline::MediaSourceVideo>(
@@ -240,13 +265,13 @@ int my_main(int argc, char **argv)
240265 return -1 ;
241266 }
242267
243- if (!gstMediaPipeline->setVideoWindow (0 , 0 , 1920 , 1080 ))
244- {
245- fprintf (stderr, " Warning: Failed to set video window. Video may not appear.\n " );
246- }
268+ // if (!gstMediaPipeline->setVideoWindow(0, 0, 1920, 1080))
269+ // {
270+ // fprintf(stderr, "Warning: Failed to set video window. Video may not appear.\n");
271+ // }
247272
248273 // MUST happen before any attachSource() to create a Rialto Gstreamer player
249- gstMediaPipeline->load (MediaType::MSE, " video/fmp4 " , " test://local" ); // Dummy values
274+ gstMediaPipeline->load (MediaType::MSE, " video/x-h265 " , " test://local" ); // Dummy values
250275
251276 ConfigureAudio ();
252277 ConfigureVideo ();
@@ -264,7 +289,7 @@ int my_main(int argc, char **argv)
264289 InjectVideo (videoReqId);
265290
266291
267- // std::this_thread::sleep_for(std::chrono::seconds(5 ));
292+ // std::this_thread::sleep_for(std::chrono::seconds(3 ));
268293
269294 // gstMediaPipeline->stop();
270295
0 commit comments