1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <string.h> |
|
19 #include <gst.h> |
|
20 #include "XAEngineAdaptCtx.h" |
|
21 #include "XAAdaptation.h" |
|
22 |
|
23 /* |
|
24 * gboolean XAEngineAdapt_GstBusCb( GstBus *bus, GstMessage *message, gpointer data ) |
|
25 * MediaPlayer Gst-bus message handler (Callback) |
|
26 */ |
|
27 gboolean XAEngineAdapt_GstBusCb( GstBus *bus, GstMessage *message, gpointer data ) |
|
28 { |
|
29 XAEngineAdaptationCtx* mCtx = (XAEngineAdaptationCtx*)data; |
|
30 DEBUG_API("->XAEngineAdapt_GstBusCb"); |
|
31 |
|
32 /* only listen to pipeline messages */ |
|
33 if(GST_MESSAGE_SRC(message)==(GstObject*)(mCtx->baseObj.bin) ) |
|
34 { |
|
35 DEBUG_API_A2("->XAEngineAdapt_GstBusCb:\"%s\" from object \"%s\"", |
|
36 GST_MESSAGE_TYPE_NAME(message), GST_OBJECT_NAME(GST_MESSAGE_SRC(message))); |
|
37 } |
|
38 |
|
39 DEBUG_API("<-XAEngineAdapt_GstBusCb"); |
|
40 return TRUE; |
|
41 } |
|
42 |
|
43 /* |
|
44 * XAAdaptationBaseCtx* XAEngineAdapt_Create() |
|
45 * Allocates memory for Engine Adaptation Context and makes 1st phase initialization |
|
46 * @returns XAEngineAdaptationCtx* - Pointer to created context |
|
47 */ |
|
48 XAAdaptationBaseCtx* XAEngineAdapt_Create() |
|
49 { |
|
50 XAEngineAdaptationCtx *pSelf = NULL; |
|
51 DEBUG_API("->XAEngineAdapt_Create"); |
|
52 |
|
53 pSelf = calloc(1, sizeof(XAEngineAdaptationCtx)); |
|
54 if ( pSelf) |
|
55 { |
|
56 if( XAAdaptationBase_Init(&(pSelf->baseObj),XAEngineAdaptation) |
|
57 != XA_RESULT_SUCCESS ) |
|
58 { |
|
59 DEBUG_ERR("Failed to init base context!!!"); |
|
60 free(pSelf); |
|
61 pSelf = NULL; |
|
62 } |
|
63 else |
|
64 { |
|
65 /* Init internal variables */ |
|
66 } |
|
67 } |
|
68 |
|
69 DEBUG_API("<-XAEngineAdapt_Create"); |
|
70 return (XAAdaptationBaseCtx*)pSelf; |
|
71 } |
|
72 |
|
73 /* |
|
74 * XAresult XAEngineAdapt_PostInit() |
|
75 * 2nd phase initialization of engine Adaptation Context |
|
76 */ |
|
77 XAresult XAEngineAdapt_PostInit(XAAdaptationBaseCtx* bCtx) |
|
78 { |
|
79 XAresult ret = XA_RESULT_SUCCESS; |
|
80 GstStateChangeReturn gret = GST_STATE_CHANGE_SUCCESS; |
|
81 XAEngineAdaptationCtx* ctx = NULL; |
|
82 |
|
83 DEBUG_API("->XAEngineAdapt_PostInit"); |
|
84 if( !bCtx || bCtx->ctxId != XAEngineAdaptation ) |
|
85 { |
|
86 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
87 DEBUG_API("<-XAEngineAdapt_PostInit"); |
|
88 return XA_RESULT_PARAMETER_INVALID; |
|
89 } |
|
90 ctx = (XAEngineAdaptationCtx*)bCtx; |
|
91 |
|
92 if ( !ctx ) |
|
93 { |
|
94 DEBUG_ERR("XA_RESULT_INTERNAL_ERROR"); |
|
95 DEBUG_API("<-XAEngineAdapt_PostInit"); |
|
96 return XA_RESULT_INTERNAL_ERROR; |
|
97 } |
|
98 |
|
99 XAAdaptationBase_PostInit( &(ctx->baseObj) ); |
|
100 |
|
101 ctx->baseObj.bin = gst_pipeline_new("engine"); |
|
102 // gst_bin_add(GST_BIN(ctx->baseObj.bin), gst_element_factory_make( "alsamixer", "alsamixer")); |
|
103 |
|
104 if ( !ctx->baseObj.bin ) |
|
105 { |
|
106 DEBUG_ERR("Failed to create alsamixer"); |
|
107 DEBUG_ERR("XA_RESULT_INTERNAL_ERROR"); |
|
108 DEBUG_API("<-XAEngineAdapt_PostInit"); |
|
109 return XA_RESULT_INTERNAL_ERROR; |
|
110 } |
|
111 |
|
112 /* Create Gst bus listener. */ |
|
113 ret = XAAdaptationBase_InitGstListener(&(ctx->baseObj)); |
|
114 if( ret!=XA_RESULT_SUCCESS ) |
|
115 { |
|
116 DEBUG_ERR_A1("Bus listener creation failed!! - (%d)", ret); |
|
117 DEBUG_API("<-XAEngineAdapt_PostInit"); |
|
118 return ret; |
|
119 } |
|
120 |
|
121 /* Add Engine specific handler */ |
|
122 if(ctx->baseObj.bus) |
|
123 { |
|
124 ctx->baseObj.busCb = XAEngineAdapt_GstBusCb; |
|
125 } |
|
126 else |
|
127 { |
|
128 DEBUG_ERR("Failed to create message bus"); |
|
129 DEBUG_ERR("XA_RESULT_INTERNAL_ERROR"); |
|
130 DEBUG_API("<-XAEngineAdapt_PostInit"); |
|
131 return XA_RESULT_INTERNAL_ERROR; |
|
132 } |
|
133 |
|
134 /* roll up bin */ |
|
135 ctx->baseObj.binWantedState = GST_STATE_PAUSED; |
|
136 XAAdaptationBase_PrepareAsyncWait(&(ctx->baseObj)); |
|
137 gret = gst_element_set_state( GST_ELEMENT(ctx->baseObj.bin), ctx->baseObj.binWantedState); |
|
138 if( gret == GST_STATE_CHANGE_ASYNC ) |
|
139 { |
|
140 DEBUG_INFO("Wait for preroll"); |
|
141 XAAdaptationBase_StartAsyncWait(&(ctx->baseObj)); |
|
142 DEBUG_INFO("Preroll ready"); |
|
143 } |
|
144 ctx->baseObj.waitingasyncop = XA_BOOLEAN_FALSE; |
|
145 |
|
146 ret = XAStaticCapsAdapt_InitCaps(); |
|
147 |
|
148 DEBUG_API("<-XAEngineAdapt_PostInit"); |
|
149 return ret; |
|
150 } |
|
151 |
|
152 /* |
|
153 * void XAEngineAdapt_Destroy(XAEngineAdaptationCtx* ctx) |
|
154 * Destroys Engine Adaptation Context |
|
155 * @param ctx - Engine Adaptation context to be destroyed |
|
156 */ |
|
157 void XAEngineAdapt_Destroy(XAAdaptationBaseCtx* bCtx) |
|
158 { |
|
159 XAEngineAdaptationCtx* ctx = NULL; |
|
160 |
|
161 DEBUG_API("->XAEngineAdapt_Destroy"); |
|
162 if( !bCtx || bCtx->ctxId != XAEngineAdaptation ) |
|
163 { |
|
164 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
165 DEBUG_API("<-XAEngineAdapt_Destroy"); |
|
166 return; |
|
167 } |
|
168 ctx = (XAEngineAdaptationCtx*)bCtx; |
|
169 |
|
170 XAAdaptationBase_Free(&(ctx->baseObj)); |
|
171 |
|
172 /* gst_deinit(); */ |
|
173 |
|
174 free(ctx); |
|
175 ctx = NULL; |
|
176 |
|
177 DEBUG_API("<-XAEngineAdapt_Destroy"); |
|
178 } |
|