一篇不错的gstream的component开发代码

http://publicsvn.songbirdnest.com/browser/trunk/components/mediacore/playback/gstreamer/src/sbGStreamerSimple.cpp?rev=2484

 

root/trunk/components/mediacore/playback/gstreamer/src/sbGStreamerSimple.cpp

Revision 2484, 16.3 kB (checked in by ben, 2 years ago)

Updating line ending restrictions

  • Property svn:eol-style set to LF
Line  
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);
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值