|
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 <gst.h> |
|
19 #include "xaadaptationgst.h" |
|
20 #include "xamediaplayeradaptctx.h" |
|
21 #include "xadynamicsourceitfadaptation.h" |
|
22 |
|
23 /* |
|
24 * XAresult XADynamicSourceItfAdapt_SetSource(XAAdaptationGstCtx *bCtx, XADataSource *pDataSource) |
|
25 * @param XAAdaptationGstCtx *bCtx - Adaptation context, this will be casted to correct type regarding to contextID value |
|
26 * @param XADataSource *pDataSource - new data source |
|
27 * @return XAresult ret - Success value |
|
28 */ |
|
29 XAresult XADynamicSourceItfAdapt_SetSource(XAAdaptationGstCtx *bCtx, XADataSource *pDataSource) |
|
30 { |
|
31 XAresult ret = XA_RESULT_SUCCESS; |
|
32 DEBUG_API("->XADynamicSourceItfAdapt_SetSource"); |
|
33 if( !bCtx || !pDataSource || !pDataSource->pLocator ) |
|
34 { |
|
35 DEBUG_ERR("Invalid NULL parameter"); |
|
36 ret = XA_RESULT_PARAMETER_INVALID; |
|
37 } |
|
38 else if(bCtx->baseObj.ctxId == XAMediaPlayerAdaptation || bCtx->baseObj.ctxId == XAMDAdaptation ) |
|
39 { |
|
40 XAMediaPlayerAdaptationCtx* mCtx = (XAMediaPlayerAdaptationCtx*) bCtx; |
|
41 GstStateChangeReturn gret; |
|
42 GstState origState; |
|
43 GstElement* newSource = XAAdaptationGst_CreateGstSource( pDataSource, "datasrc", &(mCtx->isobjsrc), NULL, NULL); |
|
44 if(!newSource) |
|
45 { |
|
46 DEBUG_ERR("Could not create data source!!!"); |
|
47 return XA_RESULT_CONTENT_NOT_FOUND; |
|
48 } |
|
49 DEBUG_INFO("Changing Playback Source"); |
|
50 /* store current state */ |
|
51 origState = GST_STATE(bCtx->bin); |
|
52 /* unroll pipeline */ |
|
53 bCtx->binWantedState = GST_STATE_NULL; |
|
54 XAAdaptationGst_PrepareAsyncWait(bCtx); |
|
55 gret = gst_element_set_state( GST_ELEMENT(bCtx->bin), bCtx->binWantedState); |
|
56 if( gret == GST_STATE_CHANGE_ASYNC ) |
|
57 { |
|
58 DEBUG_INFO("Wait for unroll"); |
|
59 XAAdaptationGst_StartAsyncWait(bCtx); |
|
60 DEBUG_INFO("Unroll ready"); |
|
61 } |
|
62 else if( gret == GST_STATE_CHANGE_FAILURE ) |
|
63 { /*not much we can do*/ |
|
64 DEBUG_ERR("WARNING: Failed to unroll pipeline!!") |
|
65 return XA_RESULT_INTERNAL_ERROR; |
|
66 } |
|
67 bCtx->waitingasyncop = XA_BOOLEAN_FALSE; |
|
68 |
|
69 /* set new source */ |
|
70 gst_element_unlink(mCtx->source,mCtx->codecbin); |
|
71 gst_bin_remove(GST_BIN(bCtx->bin), mCtx->source); |
|
72 mCtx->source = newSource; |
|
73 gst_bin_add(GST_BIN(bCtx->bin), mCtx->source); |
|
74 if(! gst_element_link(mCtx->source, mCtx->codecbin)) |
|
75 { |
|
76 DEBUG_ERR("Could not link source to codecbin!!"); |
|
77 return XA_RESULT_INTERNAL_ERROR; |
|
78 } |
|
79 mCtx->xaSource = pDataSource; |
|
80 |
|
81 /* restore pipeline state */ |
|
82 bCtx->binWantedState = origState; |
|
83 DEBUG_INFO_A1("Changing pipeline back to state %s",gst_element_state_get_name(origState)); |
|
84 XAAdaptationGst_PrepareAsyncWait(bCtx); |
|
85 gret = gst_element_set_state( GST_ELEMENT(bCtx->bin), bCtx->binWantedState); |
|
86 if( gret == GST_STATE_CHANGE_ASYNC ) |
|
87 { |
|
88 DEBUG_INFO("Wait for state change"); |
|
89 XAAdaptationGst_StartAsyncWait(bCtx); |
|
90 } |
|
91 else if( gret == GST_STATE_CHANGE_FAILURE ) |
|
92 { |
|
93 DEBUG_ERR("State change FAILED"); |
|
94 return XA_RESULT_INTERNAL_ERROR; |
|
95 } |
|
96 bCtx->waitingasyncop = XA_BOOLEAN_FALSE; |
|
97 DEBUG_INFO_A1("Pipeline in state %s",gst_element_state_get_name(GST_STATE(bCtx->bin))); |
|
98 |
|
99 if( GST_STATE(bCtx->bin) > GST_STATE_READY ) |
|
100 { /* let (possible) extraction itf to know new tags */ |
|
101 XAAdaptEvent event = {XA_METADATAEVENTS, XA_ADAPT_MDE_TAGS_AVAILABLE, 0, NULL }; |
|
102 XAAdaptationBase_SendAdaptEvents(&bCtx->baseObj, &event ); |
|
103 } |
|
104 } |
|
105 DEBUG_API("<-XADynamicSourceItfAdapt_SetSource"); |
|
106 return ret; |
|
107 } |