]> git.saurik.com Git - wxWidgets.git/blobdiff - utils/wxMMedia2/lib/vidwin.cpp
Inserted "stdio catch" in wxExecute. The activation is controlled by wxProcess.
[wxWidgets.git] / utils / wxMMedia2 / lib / vidwin.cpp
index a8e83b2decb41ed08c26b7d58d58975252c55a4f..131b12503cee754d79df65c672bbe42dd0138dd8 100644 (file)
-////////////////////////////////////////////////////////////////////////////////
+// -----------------------------------------------------------------------------
 // Name:       vidwin.h
 // Purpose:    wxMMedia
 // Author:     Guilhem Lavaux
 // Created:    February 1998
 // Updated:
-// Copyright:  (C) 1998, Guilhem Lavaux
+// Copyright:  (C) 1998, 1999, 2000 Guilhem Lavaux
 // License:    wxWindows license
-////////////////////////////////////////////////////////////////////////////////
+// -----------------------------------------------------------------------------
 
 #ifdef __GNUG__
 #pragma implementation "vidwin.h"
 #endif
 
-#if 0
 #include "wx/wxprec.h"
-#else
+
+#ifndef WX_PRECOMP
 #include "wx/wx.h"
 #endif
 
+#include "wx/stream.h"
+#include "wx/wfstream.h"
+
 #define WXMMEDIA_INTERNAL
 #include <windows.h>
 #include <mmsystem.h>
 #include <digitalv.h>
-#include "mmtype.h"
-#include "mmfile.h"
 #include "vidwin.h"
 
 #ifdef __BORLANDC__
 #pragma hdrstop
 #endif
 
-wxVideoWindows::wxVideoWindows(void)
+IMPLEMENT_DYNAMIC_CLASS(wxVideoWindows, wxVideoBaseDriver)
+
+wxVideoWindows::wxVideoWindows()
 {
 }
 
-wxVideoWindows::wxVideoWindows(wxInputStream& str, bool seekable)
-  : wxVideoBaseDriver(str, seekable)
+wxVideoWindows::wxVideoWindows(wxInputStream& str)
+  : wxVideoBaseDriver(str)
 {
-  OpenFile(GetCurrentFile());
+    m_internal    = new wxVIDWinternal;
+    m_remove_file = TRUE;
+    m_filename    = wxGetTempFileName("wxvid");
+    m_paused      = FALSE;
+    m_stopped     = TRUE;
+    m_frameRate   = 1.0;
+    
+    wxFileOutputStream temp_file(m_filename);
+    temp_file << str;
+
+    OpenFile();
 }
 
-wxVideoWindows::wxVideoWindows(const char *fname)
-  : wxVideoBaseDriver(fname)
+wxVideoWindows::wxVideoWindows(const wxString& filename)
+  : wxVideoBaseDriver(filename)
 {
-  OpenFile(fname);
+    m_internal    = new wxVIDWinternal;
+    m_remove_file = FALSE;
+    m_filename    = filename;
+    m_paused      = FALSE;
+    m_stopped     = TRUE;
+    m_frameRate   = 1.0;
+    OpenFile();
 }
 
 wxVideoWindows::~wxVideoWindows(void)
 {
-  mciSendCommand(internal->dev_id, MCI_CLOSE, 0, 0);
+    mciSendCommand(m_internal->m_dev_id, MCI_CLOSE, 0, 0);
 
-  if (internal)
-    delete internal;
+    if (m_internal)
+        delete m_internal;
 }
 
-void wxVideoWindows::OpenFile(const char *fname)
+void wxVideoWindows::OpenFile()
 {
-  MCI_DGV_OPEN_PARMS open_struct;
-  DWORD ret;
+    MCI_DGV_OPEN_PARMS openStruct;
+    MCI_DGV_SET_PARMS setStruct;
+    MCI_STATUS_PARMS statusStruct;
+    DWORD ret;
+
+    openStruct.lpstrDeviceType = "avivideo";
+    openStruct.lpstrElementName = (LPSTR)(m_filename.mb_str());
+    openStruct.hWndParent = 0;
+    
+    ret = mciSendCommand(0, MCI_OPEN,
+                        MCI_OPEN_ELEMENT|MCI_DGV_OPEN_PARENT|MCI_OPEN_TYPE|MCI_DGV_OPEN_32BIT,
+                         (DWORD)(LPVOID)&openStruct);
+    m_internal->m_dev_id = openStruct.wDeviceID;
+
+
+    setStruct.dwCallback = 0;
+    setStruct.dwTimeFormat = MCI_FORMAT_FRAMES;
+
+    ret = mciSendCommand(m_internal->m_dev_id, MCI_SET, MCI_SET_TIME_FORMAT,
+                         (DWORD)(LPVOID)&setStruct);
+
+
+    statusStruct.dwCallback = 0;
+    statusStruct.dwItem = MCI_DGV_STATUS_FRAME_RATE;
+    ret = mciSendCommand(m_internal->m_dev_id, MCI_STATUS,
+                         MCI_STATUS_ITEM,
+                         (DWORD)(LPVOID)&statusStruct);
 
-  internal = new VIDW_Internal;
+    m_frameRate = ((double)statusStruct.dwReturn) / 1000;
 
-  open_struct.lpstrDeviceType = "avivideo";
-  open_struct.lpstrElementName = (LPSTR)fname;
-  open_struct.hWndParent = 0;
+    statusStruct.dwItem = MCI_DGV_STATUS_BITSPERSAMPLE;
+    ret = mciSendCommand(m_internal->m_dev_id, MCI_STATUS, MCI_STATUS_ITEM,
+                         (DWORD)(LPVOID)&statusStruct);
+    m_bps = statusStruct.dwReturn;
 
-  ret = mciSendCommand(0, MCI_OPEN,
-        MCI_OPEN_ELEMENT|MCI_DGV_OPEN_PARENT|MCI_OPEN_TYPE|MCI_DGV_OPEN_32BIT,
-                       (DWORD)(LPVOID)&open_struct);
-  internal->dev_id = open_struct.wDeviceID;
 }
 
-bool wxVideoWindows::Pause(void)
+bool wxVideoWindows::Pause()
 {
-  return (mciSendCommand(internal->dev_id, MCI_PAUSE, 0, 0) == 0);
+    if (m_paused || m_stopped)
+        return TRUE;
+    m_paused = TRUE;
+    return (mciSendCommand(m_internal->m_dev_id, MCI_PAUSE, MCI_WAIT, 0) == 0);
 }
 
-bool wxVideoWindows::Resume(void)
+bool wxVideoWindows::Resume()
 {
-  return (mciSendCommand(internal->dev_id, MCI_PAUSE, 0, 0) == 0);
+    if (!m_paused || m_stopped)
+        return TRUE;
+    m_paused = FALSE;
+    return (mciSendCommand(m_internal->m_dev_id, MCI_RESUME, 0, 0) == 0);
 }
 
-bool wxVideoWindows::SetVolume(wxUint8 vol)
+bool wxVideoWindows::IsPaused() const
 {
-  return TRUE;
+    return m_paused;
 }
 
-bool wxVideoWindows::Resize(wxUint16 w, wxUint16 h)
+bool wxVideoWindows::IsStopped() const
 {
-  return TRUE;
+    return m_stopped;
+}
+
+bool wxVideoWindows::GetSize(wxSize& size) const
+{
+    size.SetWidth(200);
+    size.SetHeight(200);
+    return TRUE;
+}
+
+bool wxVideoWindows::SetSize(wxSize size)
+{
+    return TRUE;
 }
 
 bool wxVideoWindows::IsCapable(wxVideoType v_type)
 {
-  return (v_type == wxVIDEO_MSAVI);
+    return (v_type == wxVIDEO_MSAVI);
+}
+
+bool wxVideoWindows::AttachOutput(wxWindow& output)
+{
+    MCI_DGV_WINDOW_PARMS win_struct;
+    
+    if (!wxVideoBaseDriver::AttachOutput(output))
+        return FALSE;
+    
+    win_struct.hWnd = (HWND)output.GetHWND();
+    mciSendCommand(m_internal->m_dev_id, MCI_WINDOW,
+                  MCI_DGV_WINDOW_HWND, (DWORD)(LPVOID)&win_struct);
+    return TRUE;
 }
 
-bool wxVideoWindows::AttachOutput(wxVideoOutput& output)
+void wxVideoWindows::DetachOutput()
 {
-  MCI_DGV_WINDOW_PARMS win_struct;
+    MCI_DGV_WINDOW_PARMS win_struct;
 
-  if (!wxVideoBaseDriver::AttachOutput(output))
-    return FALSE;
+    wxVideoBaseDriver::DetachOutput();
+    
+    win_struct.hWnd = 0;
+    mciSendCommand(m_internal->m_dev_id, MCI_WINDOW,
+                  MCI_DGV_WINDOW_HWND, (DWORD)(LPVOID)&win_struct);
+}
+
+bool wxVideoWindows::Play()
+{
+    if (!m_stopped)
+        return FALSE;
+    m_stopped = FALSE;
+    return (mciSendCommand(m_internal->m_dev_id, MCI_PLAY, 0, NULL) == 0);
+}
+
+bool wxVideoWindows::Stop()
+{
+    MCI_SEEK_PARMS seekStruct;
+
+    if (m_stopped)
+        return FALSE;
+    m_stopped = TRUE;
+    if (::mciSendCommand(m_internal->m_dev_id, MCI_STOP, MCI_WAIT, NULL) != 0)
+      return FALSE;
+
+    seekStruct.dwCallback = 0;
+    seekStruct.dwTo = 0;
+    return (::mciSendCommand(m_internal->m_dev_id, MCI_SEEK, MCI_SEEK_TO_START|MCI_WAIT, (DWORD)(LPVOID)&seekStruct) == 0);
+}
 
-  win_struct.hWnd = (HWND)output.GetHWND();
-  mciSendCommand(internal->dev_id, MCI_WINDOW,
-                 MCI_DGV_WINDOW_HWND, (DWORD)(LPVOID)&win_struct);
-  return TRUE;
+// TODO TODO
+// I hate windows :-(. The doc says MCI_STATUS should return all info I want but when I call it
+// it returns to me with an UNSUPPORTED_FUNCTION error. I will have to do all by myself. Grrrr !
+
+wxString wxVideoWindows::GetMovieCodec() const
+{
+    return wxT("No info");
 }
 
-void wxVideoWindows::DetachOutput(void)
+wxString wxVideoWindows::GetAudioCodec() const
 {
-  MCI_DGV_WINDOW_PARMS win_struct;
+    return wxT("No info");
+}
 
-  wxVideoBaseDriver::DetachOutput();
+wxUint32 wxVideoWindows::GetSampleRate() const
+{
+    return 22500;
+}
 
-  win_struct.hWnd = 0;
-  mciSendCommand(internal->dev_id, MCI_WINDOW,
-                 MCI_DGV_WINDOW_HWND, (DWORD)(LPVOID)&win_struct);
+wxUint8 wxVideoWindows::GetChannels() const
+{
+    return 1;
+}
+
+wxUint8 wxVideoWindows::GetBPS() const
+{
+    return m_bps;
 }
 
-bool wxVideoWindows::StartPlay(void)
+double wxVideoWindows::GetFrameRate() const
 {
-  return (mciSendCommand(internal->dev_id, MCI_PLAY, 0, NULL) == 0);
+    return m_frameRate;
 }
 
-void wxVideoWindows::StopPlay(void)
+wxUint32 wxVideoWindows::GetNbFrames() const
 {
-  mciSendCommand(internal->dev_id, MCI_STOP, 0, NULL);
+    return 0;
 }