sbDeviceStreamingHandler.cpp
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set sw=2 :miv */
3 /*
4  *=BEGIN SONGBIRD GPL
5  *
6  * This file is part of the Songbird web player.
7  *
8  * Copyright(c) 2005-2010 POTI, Inc.
9  * http://www.songbirdnest.com
10  *
11  * This file may be licensed under the terms of of the
12  * GNU General Public License Version 2 (the ``GPL'').
13  *
14  * Software distributed under the License is distributed
15  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
16  * express or implied. See the GPL for the specific language
17  * governing rights and limitations.
18  *
19  * You should have received a copy of the GPL along with this
20  * program. If not, go to http://www.gnu.org/licenses/gpl.html
21  * or write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23  *
24  *=END SONGBIRD GPL
25  */
26 
27 //------------------------------------------------------------------------------
28 //------------------------------------------------------------------------------
29 //
30 // Device streaming handler.
31 //
32 //------------------------------------------------------------------------------
33 //------------------------------------------------------------------------------
34 
40 //------------------------------------------------------------------------------
41 //
42 // Device streaming handler imported services.
43 //
44 //------------------------------------------------------------------------------
45 
46 // Self imports.
49 
50 // Local imports.
51 #include <nsIProxyObjectManager.h>
52 
53 // Mozilla imports.
54 #include <nsAutoLock.h>
55 #include <nsAutoPtr.h>
56 
57 
58 //------------------------------------------------------------------------------
59 //
60 // Device streaming handler nsISupports implementation.
61 //
62 //------------------------------------------------------------------------------
63 
66 
67 
68 //------------------------------------------------------------------------------
69 //
70 // Device streaming handler sbIMediaItemControllerListener implementation.
71 //
72 //------------------------------------------------------------------------------
73 
74 //-------------------------------------
75 //
76 // OnValidatePlaybackComplete
77 //
78 
79 NS_IMETHODIMP
80 sbDeviceStreamingHandler::OnValidatePlaybackComplete(sbIMediaItem* aMediaItem,
81  PRInt32 aResult)
82 {
83  nsAutoMonitor monitor(mCompleteNotifyMonitor);
84  mIsSupported =
86  ? PR_TRUE : PR_FALSE;
87  PR_AtomicSet(&mIsComplete, PR_TRUE);
88  monitor.Notify();
89 
90  return NS_OK;
91 }
92 
93 
94 //------------------------------------------------------------------------------
95 //
96 // Device streaming handler public services.
97 //
98 //------------------------------------------------------------------------------
99 
100 //-------------------------------------
101 //
102 // New
103 //
104 
105 /* static */ nsresult
107  (sbDeviceStreamingHandler** aDeviceStreamingHandler,
108  sbIMediaItem* aMediaItem,
109  PRMonitor* aCompleteNotifyMonitor)
110 {
111  // Validate arguments.
112  NS_ENSURE_ARG_POINTER(aDeviceStreamingHandler);
113  NS_ENSURE_ARG_POINTER(aMediaItem);
114  NS_ENSURE_ARG_POINTER(aCompleteNotifyMonitor);
115 
116  // Create the device streaming handler object.
117  nsRefPtr<sbDeviceStreamingHandler>
118  handler = new sbDeviceStreamingHandler(aMediaItem, aCompleteNotifyMonitor);
119  NS_ENSURE_TRUE(handler, NS_ERROR_OUT_OF_MEMORY);
120 
121  // Return results.
122  handler.forget(aDeviceStreamingHandler);
123 
124  return NS_OK;
125 }
126 
127 //-------------------------------------
128 //
129 // CheckTranserable
130 //
131 
132 nsresult
134 {
135  nsresult rv;
136 
137  nsCOMPtr<sbIMediaItemController> mediaItemController;
138  rv = mMediaItem->GetItemController(getter_AddRefs(mediaItemController));
139  NS_ENSURE_SUCCESS(rv, rv);
140 
141  // ValidatePlayback dispatch DOM event. This should be on the
142  // main thread.
143  nsCOMPtr<sbIMediaItemController> proxiedMediaItemController;
144  rv = do_GetProxyForObject(NS_PROXY_TO_MAIN_THREAD,
145  NS_GET_IID(sbIMediaItemController),
146  mediaItemController,
147  NS_PROXY_SYNC | NS_PROXY_ALWAYS,
148  getter_AddRefs(proxiedMediaItemController));
149  NS_ENSURE_SUCCESS(rv, rv);
150 
151  // FromUserAction == PR_TRUE, PromptLoginOnce == PR_TRUE
152  rv = proxiedMediaItemController->ValidateStreaming(mMediaItem,
153  PR_TRUE,
154  PR_TRUE,
155  this);
156  NS_ENSURE_SUCCESS(rv, rv);
157 
158  return NS_OK;
159 }
160 
161 
162 //-------------------------------------
163 //
164 // IsComplete
165 //
166 
167 PRBool
169 {
170  return mIsComplete;
171 }
172 
173 
174 //-------------------------------------
175 //
176 // IsStreamingItemSupported
177 //
178 
179 PRBool
181 {
182  return mIsSupported;
183 }
184 
185 
186 //-------------------------------------
187 //
188 // sbDeviceStreamingHandler
189 //
190 
192  (sbIMediaItem* aMediaItem,
193  PRMonitor* aCompleteNotifyMonitor)
194 : mCompleteNotifyMonitor(aCompleteNotifyMonitor),
195  mMediaItem(aMediaItem),
196  mIsComplete(PR_FALSE),
197  mIsSupported(PR_FALSE)
198 {
199 }
200 
201 
202 //-------------------------------------
203 //
204 // ~sbDeviceStreamingHandler
205 //
206 
208 {
209 }
210 
return NS_OK
sbDeviceStreamingHandler(sbIMediaItem *aMediaItem, PRMonitor *aCompleteNotifyMonitor)
nsresult do_GetProxyForObject(nsIEventTarget *aTarget, REFNSIID aIID, nsISupports *aObj, PRInt32 aProxyType, void **aProxyObject)
Interface to receive events from a mediaItemController.
const long VALIDATEPLAYBACKCOMPLETE_PROCEED
Result constant for onValidatePlaybackComplete used to proceed with playing the validated item...
NS_IMPL_THREADSAFE_ISUPPORTS1(sbDeviceStreamingHandler, sbIMediaItemControllerListener) NS_IMETHODIMP sbDeviceStreamingHandler
Interface that defines a single item of media in the system.
NS_DECL_ISUPPORTS static NS_DECL_SBIMEDIAITEMCONTROLLERLISTENER nsresult New(sbDeviceStreamingHandler **aDeviceStreamingHandler, sbIMediaItem *aMediaItem, PRMonitor *aCompleteNotifyMonitor)
GstMessage gpointer data sbGStreamerMessageHandler * handler
Interface that defines a mediaitem controller.
Songbird Device Streaming handler Definitions.