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 "XAAdaptation.h" |
|
20 #include "XAMediaPlayerAdaptCtx.h" |
|
21 #include "XADynamicSourceItfAdaptation.h" |
|
22 |
|
23 /* |
|
24 * XAresult XADynamicSourceItfAdapt_SetSource(XAAdaptationBaseCtx *bCtx, XADataSource *pDataSource) |
|
25 * @param XAAdaptationBaseCtx *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(XAAdaptationBaseCtx *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->ctxId == XAMediaPlayerAdaptation || bCtx->ctxId == XAMDAdaptation ) |
|
39 { |
|
40 XAMediaPlayerAdaptationCtx* mCtx = (XAMediaPlayerAdaptationCtx*) bCtx; |
|
41 GstStateChangeReturn gret; |
|
42 GstState origState; |
|
43 GstElement* newSource = XAAdaptationBase_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 XAAdaptationBase_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 XAAdaptationBase_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 gst_element_link(mCtx->source, mCtx->codecbin); |
|
75 mCtx->xaSource = pDataSource; |
|
76 |
|
77 /* restore pipeline state */ |
|
78 bCtx->binWantedState = origState; |
|
79 DEBUG_INFO_A1("Changing pipeline back to state %s",gst_element_state_get_name(origState)); |
|
80 XAAdaptationBase_PrepareAsyncWait(bCtx); |
|
81 gret = gst_element_set_state( GST_ELEMENT(bCtx->bin), bCtx->binWantedState); |
|
82 if( gret == GST_STATE_CHANGE_ASYNC ) |
|
83 { |
|
84 DEBUG_INFO("Wait for state change"); |
|
85 XAAdaptationBase_StartAsyncWait(bCtx); |
|
86 } |
|
87 else if( gret == GST_STATE_CHANGE_FAILURE ) |
|
88 { |
|
89 DEBUG_ERR("State change FAILED"); |
|
90 return XA_RESULT_INTERNAL_ERROR; |
|
91 } |
|
92 bCtx->waitingasyncop = XA_BOOLEAN_FALSE; |
|
93 DEBUG_INFO_A1("Pipeline in state %s",gst_element_state_get_name(GST_STATE(bCtx->bin))); |
|
94 |
|
95 if( GST_STATE(bCtx->bin) > GST_STATE_READY ) |
|
96 { /* let (possible) extraction itf to know new tags */ |
|
97 XAAdaptEvent event = {XA_METADATAEVENTS, XA_ADAPT_MDE_TAGS_AVAILABLE, 0, NULL }; |
|
98 XAAdaptationBase_SendAdaptEvents(bCtx, &event ); |
|
99 } |
|
100 } |
|
101 DEBUG_API("<-XADynamicSourceItfAdapt_SetSource"); |
|
102 return ret; |
|
103 } |
|