GUI Forms Video Streams

I am creating a custom video player in C # form. Currently, the player has initialization and shutdown procedures, and the stream works in the background, viewing video frames and displaying them. I'm new to C #, so I'm trying to establish how best to send start \ stop \ pause commands from a GUI stream to a video stream. Should I just use the lock protected state variable and poll it around my video stream every time. are there any other recommendations here?

Thanks.

+4
source share
3 answers

The voice state variable will seem to be the simplest solution, providing a sufficient number of video stream cycles.

You might not even need a lock, so C # should be enough for a volatile state variable if only one thread updates it. ( volatile in C # has slightly different semantics than C, and should ensure that another thread gets a new value)

+1
source

Several ways are possible. Since you're new to C # and probably closely related to the user interface, I suggest you use the BackgroundWorker class.

http://msdn.microsoft.com/en-us/library/cc221403 (v = vs .95) .aspx

You can pass your arguments using the DoWorkEventArgs from the DoWork event. Also with this approach and without shared objects (via streams) you can avoid using blocking or synchronization

I think this may be the best solution for you, but there are alternatives. You can use an asynchronous programming model (APM) or even Thread / ThreadPool or a parallel task library.

Should I just use a lock protected state variable and poll it around my video stream each time; are there any other recommendations?

If you have a general condition, such as a video stream, you should use stream synchronization. So the answer is yes, you should use some protected variable, you can avoid blocking with just volatile, but consider using other synchronization primitives. Since using volatile just ensures that you read / write the most actual value, but that does not interfere with reading / writing other threads.

Some links to choose whether to use a lock (other primitives) or just unstable:

Do I need to block or mark as volatile when accessing a simple boolean flag in C #?

Volatile against blocking against blocking

0
source

You can be able to start / stop / pause the DirectShow filter graph without restrictions. This will call the appropriate methods in the source filter (for more information, see Filter Status section). The source filter should notify the background thread of a state change if it has not already been done.

Synchronization can be implemented in the same way as in the DirectShow classes, where two AutoResetEvent filters are used in the filter, one to notify the background thread of a new request and notify the calling thread of the completion of the request.

0
source

Source: https://habr.com/ru/post/1392447/


All Articles