sbGStreamerPlatformBase.cpp
Go to the documentation of this file.
1 /*
2 //
3 // BEGIN SONGBIRD GPL
4 //
5 // This file is part of the Songbird web player.
6 //
7 // Copyright(c) 2005-2008 POTI, Inc.
8 // http://songbirdnest.com
9 //
10 // This file may be licensed under the terms of of the
11 // GNU General Public License Version 2 (the "GPL").
12 //
13 // Software distributed under the License is distributed
14 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
15 // express or implied. See the GPL for the specific language
16 // governing rights and limitations.
17 //
18 // You should have received a copy of the GPL along with this
19 // program. If not, go to http://www.gnu.org/licenses/gpl.html
20 // or write to the Free Software Foundation, Inc.,
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 //
23 // END SONGBIRD GPL
24 //
25 */
26 
28 
29 #include <prlog.h>
30 #include <nsDebug.h>
31 #include <nsStringGlue.h>
32 
33 #include <nsIDOMDocumentEvent.h>
34 #include <nsIDOMEventTarget.h>
35 
42 #ifdef PR_LOGGING
43 
44 static PRLogModuleInfo* gGStreamerPlatformBase =
45  PR_NewLogModule("sbGStreamerPlatformBase");
46 
47 #define LOG(args) \
48  if (gGStreamerPlatformBase) \
49  PR_LOG(gGStreamerPlatformBase, PR_LOG_WARNING, args)
50 
51 #define TRACE(args) \
52  if (gGStreamerPlatformBase) \
53  PR_LOG(gGStreamerPlatformBase, PR_LOG_DEBUG, args)
54 
55 #else /* PR_LOGGING */
56 
57 #define LOG(args) /* nothing */
58 #define TRACE(args) /* nothing */
59 
60 #endif /* PR_LOGGING */
61 
64 , mDisplayWidth(0)
65 , mDisplayHeight(0)
66 , mDisplayX(0)
67 , mDisplayY(0)
68 , mDARNum(1)
69 , mDARDenom(1)
70 , mFullscreen(false)
71 , mVideoBox(NULL)
72 , mVideoSink(NULL)
73 , mAudioSink(NULL)
74 , mCore(aCore)
75 {
76 }
77 
79 {
80  if (mVideoSink)
81  gst_object_unref(mVideoSink);
82  if (mAudioSink)
83  gst_object_unref(mAudioSink);
84 }
85 
86 bool
88 {
89  return mFullscreen;
90 }
91 
92 void
94 {
95  if (aFullscreen && !mFullscreen) {
96  mFullscreen = true;
97  FullScreen();
98  }
99  else if (!aFullscreen && mFullscreen) {
100  mFullscreen = false;
101  UnFullScreen();
102 
103  // Make sure we're in the right place and the right size
104  ResizeToWindow();
105  ResizeVideo();
106  }
107  // Otherwise, we're already in the right mode, so don't do anything.
108 }
109 
110 void
112 {
113  // Only resize based on our XUL element if we're not in fullscreen mode.
114  if (!mFullscreen) {
115  LOG(("Resizing video to fit window in non-fullscreen mode"));
116  PRInt32 x, y, width, height;
117 
118  if (mVideoBox) {
119  mVideoBox->GetX(&x);
120  mVideoBox->GetY(&y);
121  mVideoBox->GetWidth(&width);
122  mVideoBox->GetHeight(&height);
123 
124  SetDisplayArea(x, y, width, height);
125  ResizeVideo();
126  }
127  else {
128  LOG(("Not resizing video: no video box"));
129  }
130  }
131  else {
132  LOG(("Not resizing video: in fullscreen mode"));
133  }
134 }
135 
136 void
138 {
139  LOG(("Display area set to %d,%d %d,%d", x, y, width, height));
140  mDisplayX = x;
141  mDisplayY = y;
144 }
145 
146 void
148 {
149  LOG(("Resizing: %d, %d, %d, %d", mDisplayX, mDisplayY,
151 
152  // We can draw anywhere in the passed area.
153  // Now, calculate the area to use that will maintain the desired
154  // display-aspect-ratio.
155 
156  // First, we see if it'll fit if we use all available vertical space.
157  // If it doesn't, we use all the available horizontal space.
158  int height = mDisplayHeight;
160  int x, y;
161 
162  if (width <= mDisplayWidth) {
163  // It fits; now offset appropriately.
164  x = mDisplayX + (mDisplayWidth - width)/2;
165  y = mDisplayY;
166  }
167  else {
168  // it didn't fit this way, so use the other.
169  width = mDisplayWidth;
170  height = mDisplayWidth * mDARDenom / mDARNum;
171  x = mDisplayX;
172  y = mDisplayY + (mDisplayHeight - height)/2;
173  }
174 
175  MoveVideoWindow(x, y, width, height);
176 }
177 
178 void
179 BasePlatformInterface::SetDisplayAspectRatio(int aNumerator, int aDenominator)
180 {
181  mDARNum = aNumerator;
182  mDARDenom = aDenominator;
183 
184  ResizeVideo();
185 }
186 
187 void
189 {
190  GstElement *element = NULL;
191  GstXOverlay *xoverlay = NULL;
192 
193  if (GST_IS_BIN (mVideoSink)) {
194  /* Get the actual implementing object from the bin */
195  element = gst_bin_get_by_interface(GST_BIN (mVideoSink),
196  GST_TYPE_X_OVERLAY);
197  }
198  else {
199  element = mVideoSink;
200  }
201 
202  if (GST_IS_X_OVERLAY (element)) {
203  xoverlay = GST_X_OVERLAY (element);
204  LOG(("xoverlay interface found, setting video window"));
205  }
206  else {
207  LOG(("No xoverlay interface found, cannot set video window"));
208  return;
209  }
210 
211  SetXOverlayWindowID(xoverlay);
212 
213  ResizeToWindow();
214 }
215 
216 nsresult
217 BasePlatformInterface::SetVideoBox(nsIBoxObject *aVideoBox, nsIWidget *aWidget)
218 {
219  mVideoBox = aVideoBox;
220  mWidget = aWidget;
221 
222  return NS_OK;
223 }
224 
225 /*virtual*/ nsresult
227 {
228  NS_ENSURE_ARG_POINTER(aDocument);
230  return NS_OK;
231 }
232 
233 nsresult
235 {
236  NS_ENSURE_ARG_POINTER(aMouseEvent);
237 
238  nsresult rv = NS_ERROR_UNEXPECTED;
239  nsCOMPtr<nsIDOMDocumentEvent> docEvent = do_QueryInterface(mDocument, &rv);
240  NS_ENSURE_SUCCESS(rv, rv);
241 
242  nsCOMPtr<nsIDOMEvent> event;
243  rv = docEvent->CreateEvent(NS_LITERAL_STRING("mouseevent"),
244  getter_AddRefs(event));
245  NS_ENSURE_SUCCESS(rv, rv);
246 
247  nsCOMPtr<nsIDOMMouseEvent> mouseEvent = do_QueryInterface(event, &rv);
248  NS_ENSURE_SUCCESS(rv, rv);
249 
250  mouseEvent.forget(aMouseEvent);
251 
252  return NS_OK;
253 }
254 
255 nsresult
256 BasePlatformInterface::CreateDOMKeyEvent(nsIDOMKeyEvent **aKeyEvent)
257 {
258  NS_ENSURE_ARG_POINTER(aKeyEvent);
259 
260  nsresult rv = NS_ERROR_UNEXPECTED;
261  nsCOMPtr<nsIDOMDocumentEvent> docEvent = do_QueryInterface(mDocument, &rv);
262  NS_ENSURE_SUCCESS(rv, rv);
263 
264  nsCOMPtr<nsIDOMEvent> event;
265  rv = docEvent->CreateEvent(NS_LITERAL_STRING("keyevents"),
266  getter_AddRefs(event));
267  NS_ENSURE_SUCCESS(rv, rv);
268 
269  nsCOMPtr<nsIDOMKeyEvent> keyEvent = do_QueryInterface(event, &rv);
270  NS_ENSURE_SUCCESS(rv, rv);
271 
272  keyEvent.forget(aKeyEvent);
273 
274  return NS_OK;
275 }
276 
277 nsresult
279 {
280  NS_ENSURE_ARG_POINTER(aEvent);
281 
282  nsresult rv = NS_ERROR_UNEXPECTED;
283  nsCOMPtr<nsIDOMEventTarget> eventTarget(do_QueryInterface(mDocument, &rv ));
284  NS_ENSURE_SUCCESS( rv, rv );
285 
286  PRBool dummy = PR_FALSE;
287  rv = eventTarget->DispatchEvent(aEvent, &dummy);
288  NS_ENSURE_SUCCESS(rv, rv);
289 
290  return NS_OK;
291 }
return NS_OK
virtual void UnFullScreen()=0
var event
void SetDisplayAspectRatio(int aNumerator, int aDenominator)
nsresult DispatchDOMEvent(nsIDOMEvent *aEvent)
function width(ele) rect(ele).width
virtual nsresult SetVideoBox(nsIBoxObject *aVideoBox, nsIWidget *aWidget)
virtual void SetXOverlayWindowID(GstXOverlay *aXOverlay)=0
void SetFullscreen(bool aFullscreen)
void SetDisplayArea(int x, int y, int width, int height)
_collectFormDataForFrame aDocument
virtual nsresult SetDocument(nsIDOMDocument *aDocument)
nsresult CreateDOMMouseEvent(nsIDOMMouseEvent **aMouseEvent)
BasePlatformInterface(sbGStreamerMediacore *aCore)
this _document false
Definition: FeedWriter.js:1085
_updateDatepicker height
nsCOMPtr< nsIWidget > mWidget
virtual void MoveVideoWindow(int x, int y, int width, int height)=0
nsCOMPtr< nsIBoxObject > mVideoBox
nsCOMPtr< nsIDOMDocument > mDocument
#define LOG(args)
virtual void PrepareVideoWindow(GstMessage *aMessage)
virtual void FullScreen()=0
nsresult CreateDOMKeyEvent(nsIDOMKeyEvent **aKeyEvent)