1 |
#include "sbGStreamerSimple.h" |
2 |
#include "nsIInterfaceRequestorUtils.h" |
3 |
|
4 |
#include "nsIWebNavigation.h" |
5 |
#include "nsIDOMDocument.h" |
6 |
#include "nsIDOMDocumentView.h" |
7 |
#include "nsIDOMXULElement.h" |
8 |
#include "nsIDOMAbstractView.h" |
9 |
#include "nsIDocShellTreeItem.h" |
10 |
#include "nsIDocShellTreeOwner.h" |
11 |
#include "nsIDOMEventTarget.h" |
12 |
#include "nsIDOMEvent.h" |
13 |
#include "nsIDOMEventListener.h" |
14 |
#include "nsIDOMWindow.h" |
15 |
#include "nsIDocument.h" |
16 |
#include "nsIScriptGlobalObject.h" |
17 |
#include "nsIBaseWindow.h" |
18 |
#include "nsIWidget.h" |
19 |
#include "nsIBoxObject.h" |
20 |
#include "nsString.h" |
21 |
#include "prlog.h" |
22 |
|
23 |
#if defined( PR_LOGGING ) |
24 |
extern PRLogModuleInfo* gGStreamerLog; |
25 |
#define LOG(args) PR_LOG(gGStreamerLog, PR_LOG_DEBUG, args) |
26 |
#else |
27 |
#define LOG(args) |
28 |
#endif |
29 |
|
30 |
NS_IMPL_ISUPPORTS2(sbGStreamerSimple, sbIGStreamerSimple, nsIDOMEventListener) |
31 |
|
32 |
static GstBusSyncReply |
33 |
syncHandlerHelper(GstBus* bus, GstMessage* message, gpointer data) |
34 |
{
|
35 |
sbGStreamerSimple* gsts = NS_STATIC_CAST(sbGStreamerSimple*, data); |
36 |
return gsts->SyncHandler(bus, message); |
37 |
} |
38 |
|
39 |
static void |
40 |
streamInfoSetHelper(GObject* obj, GParamSpec* pspec, sbGStreamerSimple* gsts) |
41 |
{
|
42 |
gsts->StreamInfoSet(obj, pspec); |
43 |
} |
44 |
|
45 |
static void |
46 |
capsSetHelper(GObject* obj, GParamSpec* pspec, sbGStreamerSimple* gsts) |
47 |
{
|
48 |
gsts->CapsSet(obj, pspec); |
49 |
} |
50 |
|
51 |
sbGStreamerSimple::sbGStreamerSimple() : |
52 |
mInitialized(PR_FALSE), |
53 |
mPlay(NULL), |
54 |
mBus(NULL), |
55 |
mPixelAspectRatioN(1), |
56 |
mPixelAspectRatioD(1), |
57 |
mVideoSink(NULL), |
58 |
mGdkWin(NULL), |
59 |
mIsAtEndOfStream(PR_TRUE), |
60 |
mLastErrorCode(0), |
61 |
mVideoOutputElement(nsnull), |
62 |
mDomWindow(nsnull) |
63 |
{
|
64 |
mArtist.Assign(EmptyString()); |
65 |
mAlbum.Assign(EmptyString()); |
66 |
mTitle.Assign(EmptyString()); |
67 |
mGenre.Assign(EmptyString()); |
68 |
} |
69 |
|
70 |
sbGStreamerSimple::~sbGStreamerSimple() |
71 |
{
|
72 |
if(mPlay != NULL && GST_IS_ELEMENT(mPlay)) {
|
73 |
gst_element_set_state(mPlay, GST_STATE_NULL); |
74 |
gst_object_unref(mPlay); |
75 |
mPlay = NULL; |
76 |
} |
77 |
|
78 |
// Do i need to close the video window? |
79 |
|
80 |
mDomWindow = nsnull; |
81 |
mVideoOutputElement = nsnull; |
82 |
} |
83 |
|
84 |
NS_IMETHODIMP |
85 |
sbGStreamerSimple::Init(nsIDOMXULElement* aVideoOutput) |
86 |
{
|
87 |
nsresult rv; |
88 |
|
89 |
if(mInitialized) {
|
90 |
return NS_OK; |
91 |
} |
92 |
|
93 |
if(aVideoOutput == nsnull) {
|
94 |
return NS_ERROR_INVALID_ARG; |
95 |
} |
96 |
|
97 |
mVideoOutputElement = aVideoOutput; |
98 |
|
99 |
// Get a handle to the xul element's native window |
100 |
nsCOMPtr<nsIDOMDocument> domDocument; |
101 |
rv = aVideoOutput->GetOwnerDocument(getter_AddRefs(domDocument)); |
102 |
NS_ENSURE_SUCCESS(rv, rv); |
103 |
|
104 |
nsCOMPtr<nsIDOMDocumentView> domDocumentView(do_QueryInterface(domDocument)); |
105 |
NS_ENSURE_TRUE(domDocumentView, NS_NOINTERFACE); |
106 |
|
107 |
nsCOMPtr<nsIDOMAbstractView> domAbstractView; |
108 |
rv = domDocumentView->GetDefaultView(getter_AddRefs(domAbstractView)); |
109 |
NS_ENSURE_SUCCESS(rv, rv); |
110 |
|
111 |
nsCOMPtr<nsIWebNavigation> webNavigation(do_GetInterface(domAbstractView)); |
112 |
nsCOMPtr<nsIDocShellTreeItem> docShellTreeItem(do_QueryInterface(webNavigation)); |
113 |
NS_ENSURE_TRUE(docShellTreeItem, NS_NOINTERFACE); |
114 |
|
115 |
nsCOMPtr<nsIDocShellTreeOwner> docShellTreeOwner; |
116 |
rv = docShellTreeItem->GetTreeOwner(getter_AddRefs(docShellTreeOwner)); |
117 |
NS_ENSURE_SUCCESS(rv, rv); |
118 |
|
119 |
nsCOMPtr<nsIBaseWindow> baseWindow = do_QueryInterface(docShellTreeOwner); |
|