Backed out changeset 30bfb150da06
[wine-gecko.git] / content / media / video / public / nsMediaDecoder.h
blob6d510eec5a04b1b30ec9303b4e9a5e732f145965
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(nsMediaDecoder_h_)
39 #define nsMediaDecoder_h_
41 #include "nsIObserver.h"
42 #include "nsIPrincipal.h"
43 #include "nsSize.h"
44 #include "prlog.h"
45 #include "gfxContext.h"
46 #include "gfxRect.h"
47 #include "nsITimer.h"
49 #ifdef PR_LOGGING
50 extern PRLogModuleInfo* gVideoDecoderLog;
51 #define LOG(type, msg) PR_LOG(gVideoDecoderLog, type, msg)
52 #else
53 #define LOG(type, msg)
54 #endif
56 class nsHTMLMediaElement;
58 // All methods of nsMediaDecoder must be called from the main thread only
59 // with the exception of SetRGBData. The latter can be called from any thread.
60 class nsMediaDecoder : public nsIObserver
62 public:
63 nsMediaDecoder();
64 virtual ~nsMediaDecoder();
66 // Initialize the logging object
67 static nsresult InitLogger();
69 // Perform any initialization required for the decoder.
70 // Return PR_TRUE on successful initialisation, PR_FALSE
71 // on failure.
72 virtual PRBool Init();
74 // Return the current URI being played or downloaded.
75 virtual void GetCurrentURI(nsIURI** aURI) = 0;
77 // Return the principal of the current URI being played or downloaded.
78 virtual nsIPrincipal* GetCurrentPrincipal() = 0;
80 // Return the time position in the video stream being
81 // played measured in seconds.
82 virtual float GetCurrentTime() = 0;
84 // Seek to the time position in (seconds) from the start of the video.
85 virtual nsresult Seek(float time) = 0;
87 // Called by the element when the playback rate has been changed.
88 // Adjust the speed of the playback, optionally with pitch correction,
89 // when this is called.
90 virtual nsresult PlaybackRateChanged() = 0;
92 // Return the duration of the video in seconds.
93 virtual float GetDuration() = 0;
95 // Pause video playback.
96 virtual void Pause() = 0;
98 // Return the current audio volume that the video plays at.
99 // This is a value form 0 through to 1.0.
100 virtual float GetVolume() = 0;
102 // Set the audio volume. It should be a value from 0 to 1.0.
103 virtual void SetVolume(float volume) = 0;
105 // Start playback of a video. 'Load' must have previously been
106 // called.
107 virtual nsresult Play() = 0;
109 // Stop playback of a video, and stop download of video stream.
110 virtual void Stop() = 0;
112 // Start downloading the video. Decode the downloaded data up to the
113 // point of the first frame of data.
114 // Exactly one of aURI and aChannel must be null. aListener must be
115 // null if and only if aChannel is.
116 virtual nsresult Load(nsIURI* aURI,
117 nsIChannel* aChannel,
118 nsIStreamListener **aListener) = 0;
120 // Draw the latest video data. This is done
121 // here instead of in nsVideoFrame so that the lock around the
122 // RGB buffer doesn't have to be exposed publically.
123 // The current video frame is drawn to fill aRect.
124 // Called in the main thread only.
125 virtual void Paint(gfxContext* aContext, const gfxRect& aRect);
127 // Called when the video file has completed downloading.
128 virtual void ResourceLoaded() = 0;
130 // Call from any thread safely. Return PR_TRUE if we are currently
131 // seeking in the media resource.
132 virtual PRBool IsSeeking() const = 0;
134 // Return the current number of bytes loaded from the video file.
135 // This is used for progress events.
136 virtual PRUint64 GetBytesLoaded() = 0;
138 // Return the size of the video file in bytes. Return 0 if the
139 // size is unknown or the stream is infinite.
140 virtual PRInt64 GetTotalBytes() = 0;
142 // Set the size of the video file in bytes.
143 virtual void SetTotalBytes(PRInt64 aBytes) = 0;
145 // Called when the HTML DOM element is bound.
146 virtual void ElementAvailable(nsHTMLMediaElement* anElement);
148 // Called when the HTML DOM element is unbound.
149 virtual void ElementUnavailable();
151 // Invalidate the frame.
152 virtual void Invalidate();
154 // Update progress information.
155 virtual void Progress();
157 // Keep track of the number of bytes downloaded
158 virtual void UpdateBytesDownloaded(PRUint64 aBytes) = 0;
160 // Cleanup internal data structures. Must be called on the main
161 // thread by the owning object before that object disposes of this object.
162 virtual void Shutdown();
164 protected:
166 // Start timer to update download progress information.
167 nsresult StartProgress();
169 // Stop progress information timer.
170 nsresult StopProgress();
172 // Set the RGB width, height and framerate. The passed RGB buffer is
173 // copied to the mRGB buffer. This also allocates the mRGB buffer if
174 // needed.
175 // This is the only nsMediaDecoder method that may be called
176 // from threads other than the main thread.
177 // It must be called with the mVideoUpdateLock held.
178 void SetRGBData(PRInt32 aWidth,
179 PRInt32 aHeight,
180 float aFramerate,
181 unsigned char* aRGBBuffer);
183 protected:
184 // Timer used for updating progress events
185 nsCOMPtr<nsITimer> mProgressTimer;
187 // The element is not reference counted. Instead the decoder is
188 // notified when it is able to be used. It should only ever be
189 // accessed from the main thread.
190 nsHTMLMediaElement* mElement;
192 // RGB data for last decoded frame of video data.
193 // The size of the buffer is mRGBWidth*mRGBHeight*4 bytes and
194 // contains bytes in RGBA format.
195 nsAutoArrayPtr<unsigned char> mRGB;
197 PRInt32 mRGBWidth;
198 PRInt32 mRGBHeight;
200 // Has our size changed since the last repaint?
201 PRPackedBool mSizeChanged;
203 // Lock around the video RGB, width and size data. This
204 // is used in the decoder backend threads and the main thread
205 // to ensure that repainting the video does not use these
206 // values while they are out of sync (width changed but
207 // not height yet, etc).
208 // Backends that are updating the height, width or writing
209 // to the RGB buffer must obtain this lock first to ensure that
210 // the video element does not use video data or sizes that are
211 // in the midst of being changed.
212 PRLock* mVideoUpdateLock;
214 // Framerate of video being displayed in the element
215 // expressed in numbers of frames per second.
216 float mFramerate;
219 #endif