]>
Commit | Line | Data |
---|---|---|
4d6306eb GL |
1 | //////////////////////////////////////////////////////////////////////////////// |
2 | // Name: mmfile.cpp | |
3 | // Purpose: wxMMedia | |
4 | // Author: Guilhem Lavaux | |
5 | // Created: 1997 | |
6 | // Updated: 1998 | |
7 | // Copyright: (C) 1997, 1998, Guilhem Lavaux | |
8 | // License: wxWindows license | |
9 | //////////////////////////////////////////////////////////////////////////////// | |
10 | #ifdef __GNUG__ | |
11 | #pragma implementation | |
12 | #endif | |
13 | #ifdef WX_PRECOMP | |
14 | #include "wx_prec.h" | |
15 | #else | |
16 | #include "wx/wx.h" | |
17 | #endif | |
18 | #include <wx/stream.h> | |
926c550d | 19 | #include <wx/wfstream.h> |
4d6306eb GL |
20 | #include <wx/mstream.h> |
21 | ||
22 | #include "mmfile.h" | |
23 | ||
24 | #ifdef __BORLANDC__ | |
25 | #pragma hdrstop | |
26 | #endif | |
27 | ||
28 | wxMMediaFile::wxMMediaFile() | |
29 | : m_istream(NULL), m_i_temp(NULL), m_ostream(NULL), m_o_temp(NULL), | |
30 | m_tmpfname((char *)NULL), m_mfname((char *)NULL), | |
31 | m_seekable(FALSE) | |
32 | { | |
33 | } | |
34 | ||
35 | wxMMediaFile::wxMMediaFile(wxOutputStream& os, bool seekable) | |
36 | : m_istream(NULL), m_i_temp(NULL), m_ostream(&os), m_o_temp(NULL), | |
37 | m_tmpfname((char *)NULL), m_mfname((char *)NULL), | |
38 | m_seekable(seekable) | |
39 | { | |
40 | } | |
41 | ||
42 | wxMMediaFile::wxMMediaFile(wxInputStream& is, bool preload, bool seekable) | |
43 | : m_istream(&is), m_i_temp(NULL), m_ostream(NULL), m_o_temp(NULL), | |
44 | m_tmpfname((char *)NULL), m_mfname((char *)NULL), | |
45 | m_seekable(seekable) | |
46 | { | |
47 | /* | |
48 | if (preload) { | |
49 | wxMemoryStream *tmpstream = new wxMemoryStream(); | |
50 | ||
51 | m_o_temp = tmpstream; | |
52 | m_i_temp = tmpstream; | |
53 | ||
54 | m_o_temp->Write(is); | |
55 | } | |
56 | */ | |
57 | } | |
58 | ||
59 | wxMMediaFile::wxMMediaFile(const wxString& fname) | |
60 | : m_istream(NULL), m_i_temp(NULL), m_ostream(NULL), m_o_temp(NULL), | |
61 | m_tmpfname((char *)NULL), m_mfname(fname), | |
62 | m_seekable(TRUE) | |
63 | { | |
64 | wxFileStream *s = new wxFileStream(fname); | |
65 | ||
66 | m_mfname = fname; | |
67 | m_istream = s; | |
68 | m_ostream = s; | |
69 | } | |
70 | ||
71 | void wxMMediaFile::SetFile(wxInputStream& str, bool preload, bool seekable) | |
72 | { | |
73 | CleanUpPrevious(); | |
74 | m_istream = &str; | |
75 | m_ostream = NULL; | |
76 | m_seekable = seekable; | |
77 | ||
78 | /* | |
79 | if (preload) { | |
80 | wxMemoryStream *tmpstream = new wxMemoryStream(); | |
81 | ||
82 | m_i_temp = tmpstream; | |
83 | m_o_temp = tmpstream; | |
84 | ||
85 | m_o_temp->Write(str); | |
86 | } | |
87 | */ | |
88 | } | |
89 | ||
90 | void wxMMediaFile::SetFile(wxOutputStream& str, bool seekable) | |
91 | { | |
92 | CleanUpPrevious(); | |
93 | m_ostream = &str; | |
94 | m_istream = NULL; | |
95 | m_seekable = seekable; | |
96 | } | |
97 | ||
98 | void wxMMediaFile::SetFile(const wxString& fname) | |
99 | { | |
100 | CleanUpPrevious(); | |
101 | ||
102 | m_mfname = fname; | |
103 | wxFileStream *f = new wxFileStream(fname); | |
104 | ||
105 | SetFile(*f, FALSE, TRUE); | |
106 | } | |
107 | ||
108 | void wxMMediaFile::CleanUpPrevious() | |
109 | { | |
110 | if (m_i_temp) { | |
111 | m_i_temp->SeekI(0); | |
112 | ||
113 | if (m_ostream) | |
114 | m_ostream->Write(*m_i_temp); | |
115 | ||
116 | delete m_i_temp; // Only one delete because m_tmpo* and m_tmpi* are linked | |
117 | ||
118 | if (m_tmpfname) | |
119 | wxRemoveFile(m_tmpfname); | |
120 | } | |
121 | ||
122 | if (!m_mfname.IsNull() && m_mfname != "") | |
123 | delete m_istream; | |
124 | ||
125 | m_i_temp = NULL; | |
126 | m_o_temp = NULL; | |
127 | m_istream = NULL; | |
128 | m_ostream = NULL; | |
129 | } | |
130 | ||
131 | wxMMediaFile::~wxMMediaFile() | |
132 | { | |
133 | CleanUpPrevious(); | |
134 | } | |
135 | ||
136 | wxMMtime wxMMediaFile::GetLength() | |
137 | { | |
138 | wxMMtime mm_time = {-1, 0, 0}; | |
139 | return mm_time; | |
140 | } | |
141 | ||
142 | wxMMtime wxMMediaFile::GetPosition() | |
143 | { | |
144 | wxMMtime mm_time = {0, 0, 0}; | |
145 | return mm_time; | |
146 | } | |
147 | ||
148 | wxInputStream *wxMMediaFile::GetIRawData() | |
149 | { | |
150 | if (!m_istream) | |
151 | return NULL; | |
152 | ||
153 | if (!m_seekable && !m_i_temp) | |
154 | CacheIO(); | |
155 | ||
156 | return (m_i_temp) ? m_i_temp : m_istream; | |
157 | } | |
158 | ||
159 | wxOutputStream *wxMMediaFile::GetORawData() | |
160 | { | |
161 | if (!m_ostream) | |
162 | return NULL; | |
163 | ||
164 | if (!m_seekable && !m_i_temp) | |
165 | CacheIO(); | |
166 | ||
167 | return (m_o_temp) ? m_o_temp : m_ostream; | |
168 | } | |
169 | ||
170 | wxString wxMMediaFile::GetCurrentFile() | |
171 | { | |
172 | if (!m_istream && !m_ostream) | |
173 | return wxString((char *)NULL); | |
174 | ||
175 | if (!m_mfname && !m_i_temp) | |
176 | CacheIO(); | |
177 | ||
178 | return (!m_tmpfname.IsEmpty()) ? m_tmpfname : m_mfname; | |
179 | } | |
180 | ||
181 | void wxMMediaFile::CacheIO() | |
182 | { | |
183 | if ((!m_istream && !m_ostream) || m_i_temp) | |
184 | return; | |
185 | ||
186 | m_tmpfname = wxGetTempFileName("mmd"); | |
187 | ||
188 | wxFileStream *tmpstream = new wxFileStream(m_tmpfname); | |
189 | m_i_temp = tmpstream; | |
190 | m_o_temp = tmpstream; | |
191 | ||
192 | if (m_istream) | |
193 | tmpstream->wxOutputStream::Write(*m_istream); | |
194 | } |