On x86 compilers without fastcall, simulate it when invoking traces and un-simulate...
[wine-gecko.git] / content / media / video / public / nsVideoDecoder.h
blob6989a4d4a478a9883f4cd136bae67d649f3298c0
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
3 /* ***** BEGIN LICENSE BLOCK *****
4 * Version: ML 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
16 * The Original Code is Mozilla code.
18 * The Initial Developer of the Original Code is the Mozilla Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 2007
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Chris Double <chris.double@double.co.nz>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
38 #if !defined(nsVideoDecoder_h___)
39 #define nsVideoDecoder_h___
41 #include "nsIObserver.h"
42 #include "nsSize.h"
43 #include "prlog.h"
44 #include "gfxContext.h"
45 #include "gfxRect.h"
46 #include "nsITimer.h"
48 #ifdef PR_LOGGING
49 extern PRLogModuleInfo* gVideoDecoderLog;
50 #define LOG(type, msg) PR_LOG(gVideoDecoderLog, type, msg)
51 #else
52 #define LOG(type, msg)
53 #endif
55 class nsHTMLMediaElement;
57 // All methods of nsVideoDecoder must be called from the main thread only
58 // with the exception of SetRGBData. The latter can be called from any thread.
59 class nsVideoDecoder : public nsIObserver
61 public:
62 nsVideoDecoder();
63 virtual ~nsVideoDecoder() { }
65 // Initialize the logging object
66 static nsresult InitLogger();
68 // Perform any initialization required for the decoder.
69 // Return PR_TRUE on successful initialisation, PR_FALSE
70 // on failure.
71 virtual PRBool Init();
74 // Return the current URI being played or downloaded.
75 virtual void GetCurrentURI(nsIURI** aURI) = 0;
77 // Return the time position in the video stream being
78 // played measured in seconds.
79 virtual float GetCurrentTime() = 0;
81 // Seek to the time position in (seconds) from the start of the video.
82 virtual nsresult Seek(float time) = 0;
84 // Called by the element when the playback rate has been changed.
85 // Adjust the speed of the playback, optionally with pitch correction,
86 // when this is called.
87 virtual nsresult PlaybackRateChanged() = 0;
89 // Return the duration of the video in seconds.
90 virtual float GetDuration() = 0;
92 // Pause video playback.
93 virtual void Pause() = 0;
95 // Return the current audio volume that the video plays at.
96 // This is a value form 0 through to 1.0.
97 virtual float GetVolume() = 0;
99 // Set the audio volume. It should be a value from 0 to 1.0.
100 virtual void SetVolume(float volume) = 0;
102 // Returns the current video frame width and height.
103 // If there is no video frame, returns the given default size.
104 virtual nsIntSize GetVideoSize(nsIntSize defaultSize) = 0;
106 // Return the current framerate of the video, in frames per second.
107 virtual double GetVideoFramerate() = 0;
109 // Start playback of a video. 'Load' must have previously been
110 // called.
111 virtual nsresult Play() = 0;
113 // Stop playback of a video, and stop download of video stream.
114 virtual void Stop() = 0;
116 // Start downloading the video at the given URI. Decode
117 // the downloaded data up to the point of the first frame
118 // of data.
119 virtual nsresult Load(nsIURI* aURI) = 0;
121 // Draw the latest video data. This is done
122 // here instead of in nsVideoFrame so that the lock around the
123 // RGB buffer doesn't have to be exposed publically.
124 // The current video frame is drawn to fill aRect.
125 // Called in the main thread only.
126 virtual void Paint(gfxContext* aContext, const gfxRect& aRect);
128 // Called when the video file has completed downloading.
129 virtual void ResourceLoaded() = 0;
131 // Return the current number of bytes loaded from the video file.
132 // This is used for progress events.
133 virtual PRUint32 GetBytesLoaded() = 0;
135 // Return the size of the video file in bytes.
136 // This is used for progress events.
137 virtual PRUint32 GetTotalBytes() = 0;
139 // Called when the HTML DOM element is bound.
140 virtual void ElementAvailable(nsHTMLMediaElement* anElement);
142 // Called when the HTML DOM element is unbound.
143 virtual void ElementUnavailable();
145 // Invalidate the frame.
146 virtual void Invalidate();
148 // Update progress information.
149 virtual void Progress();
151 protected:
152 // Cleanup internal data structures
153 virtual void Shutdown();
155 // Start invalidating the video frame at the interval required
156 // by the specificed framerate (in frames per second).
157 nsresult StartInvalidating(double aFramerate);
159 // Stop invalidating the video frame
160 void StopInvalidating();
162 // Start timer to update download progress information.
163 nsresult StartProgress();
165 // Stop progress information timer.
166 nsresult StopProgress();
168 // Set the RGB width, height and framerate. The passed RGB buffer is
169 // copied to the mRGB buffer. This also allocates the mRGB buffer if
170 // needed.
171 // This is the only nsVideoDecoder method that may be called
172 // from threads other than the main thread.
173 void SetRGBData(PRInt32 aWidth,
174 PRInt32 aHeight,
175 double aFramerate,
176 unsigned char* aRGBBuffer);
178 protected:
179 // Timer used for invalidating the video
180 nsCOMPtr<nsITimer> mInvalidateTimer;
182 // Timer used for updating progress events
183 nsCOMPtr<nsITimer> mProgressTimer;
185 // The element is not reference counted. Instead the decoder is
186 // notified when it is able to be used. It should only ever be
187 // accessed from the main thread.
188 nsHTMLMediaElement* mElement;
190 // RGB data for last decoded frame of video data.
191 // The size of the buffer is mRGBWidth*mRGBHeight*4 bytes and
192 // contains bytes in RGBA format.
193 nsAutoArrayPtr<unsigned char> mRGB;
195 PRInt32 mRGBWidth;
196 PRInt32 mRGBHeight;
198 // Has our size changed since the last repaint?
199 PRPackedBool mSizeChanged;
201 // Lock around the video RGB, width and size data. This
202 // is used in the decoder backend threads and the main thread
203 // to ensure that repainting the video does not use these
204 // values while they are out of sync (width changed but
205 // not height yet, etc).
206 // Backends that are updating the height, width or writing
207 // to the RGB buffer must obtain this lock first to ensure that
208 // the video element does not use video data or sizes that are
209 // in the midst of being changed.
210 PRLock* mVideoUpdateLock;
212 // Framerate of video being displayed in the element
213 // expressed in numbers of frames per second.
214 double mFramerate;
217 #endif