]>
git.saurik.com Git - wxWidgets.git/blob - utils/wxMMedia/mmfile.cpp
1 ////////////////////////////////////////////////////////////////////////////////
4 // Author: Guilhem Lavaux
7 // Copyright: (C) 1997, 1998, Guilhem Lavaux
8 // License: wxWindows license
9 ////////////////////////////////////////////////////////////////////////////////
11 #pragma implementation
18 #include <wx/stream.h>
19 #include <wx/wfstream.h>
27 wxMMediaFile::wxMMediaFile()
28 : m_istream(NULL
), m_i_temp(NULL
), m_ostream(NULL
), m_o_temp(NULL
),
29 m_tmpfname((char *)NULL
), m_mfname((char *)NULL
),
34 wxMMediaFile::wxMMediaFile(wxOutputStream
& os
, bool seekable
)
35 : m_istream(NULL
), m_i_temp(NULL
), m_ostream(&os
), m_o_temp(NULL
),
36 m_tmpfname((char *)NULL
), m_mfname((char *)NULL
),
41 wxMMediaFile::wxMMediaFile(wxInputStream
& is
, bool preload
, bool seekable
)
42 : m_istream(&is
), m_i_temp(NULL
), m_ostream(NULL
), m_o_temp(NULL
),
43 m_tmpfname((char *)NULL
), m_mfname((char *)NULL
),
47 wxStreamBuffer
*streamb
= new wxStreamBuffer(wxStreamBuffer::read_write
);
49 streamb
->Fixed(FALSE
);
50 streamb
->Flushable(FALSE
);
52 m_o_temp
= new wxOutputStream(streamb
);
53 m_i_temp
= new wxInputStream(streamb
);
56 streamb
->ResetBuffer();
60 wxMMediaFile::wxMMediaFile(const wxString
& fname
)
61 : m_istream(NULL
), m_i_temp(NULL
), m_ostream(NULL
), m_o_temp(NULL
),
62 m_tmpfname((char *)NULL
), m_mfname(fname
),
65 wxFileStream
*s
= new wxFileStream(fname
);
72 void wxMMediaFile::SetFile(wxInputStream
& str
, bool preload
, bool seekable
)
77 m_seekable
= seekable
;
80 wxStreamBuffer
*streamb
= new wxStreamBuffer(wxStreamBuffer::read_write
);
82 streamb
->Fixed(FALSE
);
83 streamb
->Flushable(FALSE
);
85 m_o_temp
= new wxOutputStream(streamb
);
86 m_i_temp
= new wxInputStream(streamb
);
89 streamb
->ResetBuffer();
93 void wxMMediaFile::SetFile(wxOutputStream
& str
, bool seekable
)
98 m_seekable
= seekable
;
101 void wxMMediaFile::SetFile(const wxString
& fname
)
106 wxFileStream
*f
= new wxFileStream(fname
);
108 SetFile(*f
, FALSE
, TRUE
);
111 void wxMMediaFile::CleanUpPrevious()
117 m_ostream
->Write(*m_i_temp
);
119 delete (m_i_temp
->InputStreamBuffer());
124 wxRemoveFile(m_tmpfname
);
127 if (!m_mfname
.IsNull() && m_mfname
!= "")
136 wxMMediaFile::~wxMMediaFile()
141 wxMMtime
wxMMediaFile::GetLength()
143 wxMMtime mm_time
= {-1, 0, 0};
147 wxMMtime
wxMMediaFile::GetPosition()
149 wxMMtime mm_time
= {0, 0, 0};
153 wxInputStream
*wxMMediaFile::GetIRawData()
158 if (!m_seekable
&& !m_i_temp
)
161 return (m_i_temp
) ? m_i_temp
: m_istream
;
164 wxOutputStream
*wxMMediaFile::GetORawData()
169 if (!m_seekable
&& !m_i_temp
)
172 return (m_o_temp
) ? m_o_temp
: m_ostream
;
175 wxString
wxMMediaFile::GetCurrentFile()
177 if (!m_istream
&& !m_ostream
)
178 return wxString((char *)NULL
);
180 if (!m_mfname
&& !m_i_temp
)
183 return (!m_tmpfname
.IsEmpty()) ? m_tmpfname
: m_mfname
;
186 void wxMMediaFile::CacheIO()
188 if ((!m_istream
&& !m_ostream
) || m_i_temp
)
191 m_tmpfname
= wxGetTempFileName("mmd");
193 wxFileStream
*tmpstream
= new wxFileStream(m_tmpfname
);
194 m_i_temp
= tmpstream
;
195 m_o_temp
= tmpstream
;
198 tmpstream
->wxOutputStream::Write(*m_istream
);