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 "XASeekItfAdaptation.h" |
|
22 |
|
23 /* |
|
24 * XAresult XASeekItfAdapt_SetPosition(XAAdaptationBaseCtx *bCtx, XAmillisecond pos, XAuint32 seekMode) |
|
25 * @param XAAdaptationBaseCtx *bCtx - Adaptation context, this will be casted to correct type regarding to contextID value |
|
26 * XAmillisecond pos - Position to be set in Milliseconds |
|
27 * XAuint32 seekMode - Preferred seek mode |
|
28 * @return XAresult ret - Success value |
|
29 */ |
|
30 XAresult XASeekItfAdapt_SetPosition(XAAdaptationBaseCtx *bCtx, XAmillisecond pos, XAuint32 seekMode) |
|
31 { |
|
32 XAresult ret = XA_RESULT_SUCCESS; |
|
33 XAMediaPlayerAdaptationCtx* mCtx = (XAMediaPlayerAdaptationCtx*) bCtx; |
|
34 gint64 gstSeekPos = pos * GST_MSECOND; |
|
35 XAmillisecond newPosMs=0; |
|
36 GstFormat format = GST_FORMAT_TIME; |
|
37 GstSeekFlags seekFlags = GST_SEEK_FLAG_FLUSH; |
|
38 DEBUG_API_A2("->XASeekItfAdapt_SetPosition (pos %ld ms, mode=%d)", pos, (int)seekMode); |
|
39 if(!bCtx || bCtx->ctxId != XAMediaPlayerAdaptation) |
|
40 { |
|
41 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
42 DEBUG_API("<-XASeekItfAdapt_SetPosition"); |
|
43 /* invalid parameter */ |
|
44 return XA_RESULT_PARAMETER_INVALID; |
|
45 } |
|
46 |
|
47 if( GST_STATE(bCtx->bin) < GST_STATE_PAUSED ) |
|
48 { /* This should not happen */ |
|
49 DEBUG_ERR("Gst not prerolled - can not seek!!"); |
|
50 DEBUG_API("<-XASeekItfAdapt_SetPosition"); |
|
51 return XA_RESULT_INTERNAL_ERROR; |
|
52 } |
|
53 |
|
54 if ( seekMode == XA_SEEKMODE_FAST ) |
|
55 { |
|
56 seekFlags |= GST_SEEK_FLAG_KEY_UNIT; |
|
57 } |
|
58 else |
|
59 { |
|
60 seekFlags |= GST_SEEK_FLAG_ACCURATE; |
|
61 } |
|
62 |
|
63 XAAdaptationBase_PrepareAsyncWait(bCtx); |
|
64 DEBUG_INFO("Send gst_element_seek"); |
|
65 mCtx->lastpos = gstSeekPos; |
|
66 if ( !gst_element_seek( bCtx->bin, mCtx->playrate, GST_FORMAT_TIME, seekFlags, |
|
67 GST_SEEK_TYPE_SET, gstSeekPos, |
|
68 GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE ) ) |
|
69 { |
|
70 DEBUG_ERR("WARN: gst reports seek not handled"); |
|
71 } |
|
72 /* flushed seeks always asynchronous */ |
|
73 XAAdaptationBase_StartAsyncWait(bCtx); |
|
74 DEBUG_INFO("Seek handled.") |
|
75 bCtx->waitingasyncop = XA_BOOLEAN_FALSE; |
|
76 /* update new position to playitf */ |
|
77 { |
|
78 XAAdaptEvent event = {XA_PLAYITFEVENTS, XA_ADAPT_POSITION_UPDATE_EVT, 1, NULL}; |
|
79 if ( !gst_element_query_position( GST_ELEMENT(bCtx->bin), &format, &mCtx->lastpos ) ) |
|
80 { |
|
81 DEBUG_ERR("WARNING: could not get position from GST") |
|
82 } |
|
83 DEBUG_INFO_A1("Current position %"GST_TIME_FORMAT, GST_TIME_ARGS(mCtx->lastpos)); |
|
84 newPosMs = GST_TIME_AS_MSECONDS(mCtx->lastpos); |
|
85 event.data = &newPosMs; |
|
86 XAAdaptationBase_SendAdaptEvents(bCtx, &event ); |
|
87 } |
|
88 |
|
89 ret = XA_RESULT_SUCCESS; |
|
90 |
|
91 DEBUG_API("<-XASeekItfAdapt_SetPosition"); |
|
92 return ret; |
|
93 } |
|
94 |
|
95 /* |
|
96 * XAresult XASeekItfAdapt_SetLoop(void *bCtx, AdaptationContextIDS ctxIDs, XAboolean loopEnable, XAmillisecond startPos, |
|
97 * XAmillisecond endPos) |
|
98 * @param XAAdaptationBaseCtx *bCtx - Adaptation context, this will be casted to correct type regarding to contextID value |
|
99 * XAboolean loopEnable - Enable/Disable looping |
|
100 * XAmillisecond startPos - Loop start position in milliseconds |
|
101 * XAmillisecond endPos - Loop end position in milliseconds |
|
102 * @return XAresult ret - Success value |
|
103 */ |
|
104 XAresult XASeekItfAdapt_SetLoop(XAAdaptationBaseCtx *bCtx, XAboolean loopEnable, XAmillisecond startPos, |
|
105 XAmillisecond endPos) |
|
106 { |
|
107 XAresult ret = XA_RESULT_SUCCESS; |
|
108 XAMediaPlayerAdaptationCtx* mCtx = (XAMediaPlayerAdaptationCtx*) bCtx; |
|
109 GstFormat format = GST_FORMAT_TIME; |
|
110 |
|
111 DEBUG_API_A3("->XASeekItfAdapt_SetLoop (enable=%d, start=%ld, stop=%ld)", (int)loopEnable, startPos, endPos); |
|
112 if(!bCtx || bCtx->ctxId != XAMediaPlayerAdaptation) |
|
113 { |
|
114 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
115 DEBUG_API("<-XASeekItfAdapt_SetLoop"); |
|
116 /* invalid parameter */ |
|
117 return XA_RESULT_PARAMETER_INVALID; |
|
118 } |
|
119 |
|
120 if( loopEnable ) |
|
121 { |
|
122 if(endPos==XA_TIME_UNKNOWN) |
|
123 { |
|
124 mCtx->loopend = GST_CLOCK_TIME_NONE; |
|
125 } |
|
126 else |
|
127 { |
|
128 mCtx->loopend = (endPos*GST_MSECOND); |
|
129 DEBUG_INFO_A1("Set looping to %ld", mCtx->loopend); |
|
130 } |
|
131 DEBUG_INFO_A2("Enable looping from %"GST_TIME_FORMAT" to %"GST_TIME_FORMAT, |
|
132 GST_TIME_ARGS(mCtx->loopstart), GST_TIME_ARGS(mCtx->loopend)); |
|
133 mCtx->loopstart = (startPos*GST_MSECOND); |
|
134 if ( !gst_element_query_position( GST_ELEMENT(bCtx->bin), &format, &(mCtx->lastpos) ) ) |
|
135 { |
|
136 DEBUG_ERR("WARNING: could not get position from GST") |
|
137 } |
|
138 DEBUG_INFO_A1("current head position %"GST_TIME_FORMAT"",GST_TIME_ARGS(mCtx->lastpos)); |
|
139 mCtx->loopingenabled = XA_BOOLEAN_TRUE; |
|
140 XAMediaPlayerAdapt_UpdatePositionCbTimer(mCtx); |
|
141 } |
|
142 else |
|
143 { |
|
144 DEBUG_INFO("Disable looping"); |
|
145 mCtx->loopstart = 0; |
|
146 mCtx->loopend = GST_CLOCK_TIME_NONE; |
|
147 mCtx->loopingenabled = XA_BOOLEAN_FALSE; |
|
148 XAMediaPlayerAdapt_UpdatePositionCbTimer(mCtx); |
|
149 } |
|
150 |
|
151 DEBUG_API("<-XASeekItfAdapt_SetLoop"); |
|
152 return ret; |
|
153 } |
|