CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    Nov 2013
    Posts
    4

    Video player in visual C++

    I have a code which is a set of rgb frames to be displayed at 25 fps to make it look like a video. While I createWindow invalidate and update it based on a timer, the video plays fine, but the buttons of Play, Pause etc hangs during the time video is playing.? any idea how to go around this problem?

  2. #2
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Video player in visual C++

    The idea is to never block GUI thread.
    Best regards,
    Igor

  3. #3
    Join Date
    Nov 2013
    Posts
    4

    Re: Video player in visual C++

    So this means the invalidate and updateWindow commands shoud be executed in a separate thread?

  4. #4
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Video player in visual C++

    This means that the timer thing must be done in a separate thread. Besides, it would be good to prepare bitmaps in separate thread as well.
    Last edited by Igor Vartanov; November 20th, 2013 at 08:32 AM.
    Best regards,
    Igor

  5. #5
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: Video player in visual C++

    Quote Originally Posted by sidaeron View Post
    So this means the invalidate and updateWindow commands shoud be executed in a separate thread?
    you should only interact with a window on the same thread that created the window (your GUI thread). This is clearly documented in the Windows API's.

    you can have more than 1 interactive/GUI thread, but it's rare to do so, and it's a whole can of worms.

    You also need to keep your GUI thread responsive (i.e. it needs to continue to handle messages). if you just have a long loop to display the video without ever returning to the messageloop, you're effectively blocking the app from receiving further messages.

    You probably either want a WM_TIMER based updating system or a system where a worker thread notifies you of stuff to be displayed. There are other (though more complex) scenario's that have their benefits as well.

  6. #6
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: Video player in visual C++

    Quote Originally Posted by sidaeron View Post
    ... invalidate and update it based on a timer...
    What timer exactly?
    How do you use it?
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  7. #7
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Video player in visual C++

    Quote Originally Posted by OReubens View Post
    you should only interact with a window on the same thread that created the window (your GUI thread). This is clearly documented in the Windows API's.
    Well, this is not true. Win32 API is completely thread safe, and issues may appear only with third party wrappers/frameworks/libraries or applications themselves.
    Best regards,
    Igor

  8. #8
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: Video player in visual C++

    Quote Originally Posted by Igor Vartanov View Post
    Well, this is not true. Win32 API is completely thread safe, and issues may appear only with third party wrappers/frameworks/libraries or applications themselves.
    The Win32 is "largely" thread safe, some parts of it definately aren't. The exceptions tend to be documented.

    It's also the thread that created a window that will need to service the messages for that window. Creating a window in a worker thread, expecting the GUI thread to receive the messages is not going to work.
    Note that I said "should", you definately can send messages to a window from a worker thread, but this may end up giving you a deadlock or another subtle error. The sad part about the MSDN documentation is that while a lot of API functions end up using SendMessage() (like Get/SetWindowText()), but this isn't mentioned, so by extention all those functions are potential hazards too.

    Just because you CAN do something in windows, doesn't mean it's smart or always safe to do so. It's a good practice to avoid directly interacting with the UI from a worker thread and merely posting to the GUI thread that something in the UI needs to be changed...

  9. #9
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Video player in visual C++

    A good practice is to avoid using API function without reading technical documentation on it. Another good practice is understanding limits beyond which you enter unsafe grounds. A good practice is to understand the nature of the limits and conditions and consequences of crossing those.

    But following "commonly known good practices" religiously is not a good practice at all. It's just a practice, one of possible ones.

    Just knowing that something in Windows MAY be unsafe never stops me from using that thing proper way and under proper circumstances. Know what you do, and do what you know.
    Last edited by Igor Vartanov; November 22nd, 2013 at 02:13 AM.
    Best regards,
    Igor

  10. #10
    Join Date
    Nov 2013
    Posts
    4

    Re: Video player in visual C++

    Hey I used WM_Timer as suggested...but for playing frame at 25 fps, if i give a timer for 40 ms, it doesnt play at 40 but a bit more...when I give it 32ms as timer, it plays good for about 5-6 sec and then it slows down and behaves unexpectedly..I assume WM is not accurate...Any other timer that is more accurate than WM?

  11. #11
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Video player in visual C++

    Best regards,
    Igor

  12. #12
    Join Date
    Nov 2013
    Posts
    4

    Re: Video player in visual C++

    Oh I used CreateTimerQueueTimer, they worked fine. Thanks for the help!!!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured