modify enigma2 for mediaplayer.
[vuplus_openembedded] / recipes / enigma2 / enigma2 / vuplus / enigma2_vuplus_mediaplayer.patch
1 diff --git a/lib/python/Plugins/Extensions/MediaPlayer/plugin.py b/lib/python/Plugins/Extensions/MediaPlayer/plugin.py
2 index 7363e5e..3fa22a2 100755
3 --- a/lib/python/Plugins/Extensions/MediaPlayer/plugin.py
4 +++ b/lib/python/Plugins/Extensions/MediaPlayer/plugin.py
5 @@ -7,7 +7,7 @@ from Screens.HelpMenu import HelpableScreen
6  from Screens.MessageBox import MessageBox
7  from Screens.InputBox import InputBox
8  from Screens.ChoiceBox import ChoiceBox
9 -from Screens.InfoBarGenerics import InfoBarSeek, InfoBarAudioSelection, InfoBarCueSheetSupport, InfoBarNotifications, InfoBarSubtitleSupport
10 +from Screens.InfoBarGenerics import InfoBarSeek, InfoBarAudioSelection, InfoBarCueSheetSupport, InfoBarNotifications, InfoBarSubtitleSupport, InfoBarPVRState
11  from Components.ActionMap import NumberActionMap, HelpableActionMap
12  from Components.Label import Label
13  from Components.Pixmap import Pixmap,MultiPixmap
14 @@ -87,7 +87,7 @@ class MediaPixmap(Pixmap):
15                 self.coverArtFileName = "/tmp/.id3coverart"
16                 self.picload.startDecode(self.coverArtFileName)
17  
18 -class MediaPlayer(Screen, InfoBarBase, InfoBarSeek, InfoBarAudioSelection, InfoBarCueSheetSupport, InfoBarNotifications, InfoBarSubtitleSupport, HelpableScreen):
19 +class MediaPlayer(Screen, InfoBarBase, InfoBarSeek, InfoBarAudioSelection, InfoBarCueSheetSupport, InfoBarNotifications, InfoBarSubtitleSupport, InfoBarPVRState, HelpableScreen):
20         ALLOW_SUSPEND = True
21         ENABLE_RESUME_SUPPORT = True
22  
23 @@ -201,6 +201,10 @@ class MediaPlayer(Screen, InfoBarBase, InfoBarSeek, InfoBarAudioSelection, InfoB
24  
25                 InfoBarSeek.__init__(self, actionmap = "MediaPlayerSeekActions")
26  
27 +               InfoBarPVRState.__init__(self)
28 +               self.__hideTimer = eTimer()
29 +               self.__hideTimer.callback.append(self.__hideMediaPlayerState)
30 +
31                 self.onClose.append(self.delMPTimer)
32                 self.onClose.append(self.__onClose)
33  
34 @@ -234,6 +238,14 @@ class MediaPlayer(Screen, InfoBarBase, InfoBarSeek, InfoBarAudioSelection, InfoB
35                                 iPlayableService.evUser+13: self["coverArt"].embeddedCoverArt
36                         })
37  
38 +       def _mayShow(self):
39 +               self.pvrStateDialog.show()
40 +               if self.seekstate == self.SEEK_STATE_PLAY and not self.shown:
41 +                       self.__hideTimer.start(5*1000, True)
42 +
43 +       def __hideMediaPlayerState(self):
44 +               self.pvrStateDialog.hide()
45 +
46         def doNothing(self):
47                 pass
48  
49 @@ -762,6 +774,7 @@ class MediaPlayer(Screen, InfoBarBase, InfoBarSeek, InfoBarAudioSelection, InfoB
50                         self.playlist.updateList()
51                         if len(self.playlist) == 1:
52                                 self.changeEntry(0)
53 +                               self.switchToPlayList()
54  
55         def addPlaylistParser(self, parser, extension):
56                 self.playlistparsers[extension] = parser
57 diff --git a/lib/python/Screens/InfoBarGenerics.py b/lib/python/Screens/InfoBarGenerics.py
58 index 6619bbc..d1bfa90 100755
59 --- a/lib/python/Screens/InfoBarGenerics.py
60 +++ b/lib/python/Screens/InfoBarGenerics.py
61 @@ -946,14 +946,17 @@ class InfoBarSeek:
62         def seekFwd(self):
63                 seek = self.getSeek()
64                 if seek and not (seek.isCurrentlySeekable() & 2):
65 -                       if not self.fast_winding_hint_message_showed and (seek.isCurrentlySeekable() & 1):
66 -                               self.session.open(MessageBox, _("No fast winding possible yet.. but you can use the number buttons to skip forward/backward!"), MessageBox.TYPE_INFO, timeout=10)
67 -                               self.fast_winding_hint_message_showed = True
68 -                               return
69 -                       return 0 # trade as unhandled action
70 +                       media = 1
71 +               else:
72 +                       media = 0
73 +#                      if not self.fast_winding_hint_message_showed and (seek.isCurrentlySeekable() & 1):
74 +#                              self.session.open(MessageBox, _("No fast winding possible yet.. but you can use the number buttons to skip forward/backward!"), MessageBox.TYPE_INFO, timeout=10)
75 +#                              self.fast_winding_hint_message_showed = True
76 +#                              return
77 +#                      return 0 # trade as unhandled action
78                 if self.seekstate == self.SEEK_STATE_PLAY:
79                         self.setSeekState(self.makeStateForward(int(config.seek.enter_forward.value)))
80 -               elif self.seekstate == self.SEEK_STATE_PAUSE:
81 +               elif self.seekstate == self.SEEK_STATE_PAUSE and media==0:
82                         if len(config.seek.speeds_slowmotion.value):
83                                 self.setSeekState(self.makeStateSlowMotion(config.seek.speeds_slowmotion.value[-1]))
84                         else:
85 @@ -964,7 +967,11 @@ class InfoBarSeek:
86                         speed = self.seekstate[1]
87                         if self.seekstate[2]:
88                                 speed /= self.seekstate[2]
89 -                       speed = self.getHigher(speed, config.seek.speeds_forward.value) or config.seek.speeds_forward.value[-1]
90 +                       if media==1 and speed == 8:
91 +                               speed = 8
92 +                               return 0 # trade as unhandled action
93 +                       else:
94 +                               speed = self.getHigher(speed, config.seek.speeds_forward.value) or config.seek.speeds_forward.value[-1]
95                         self.setSeekState(self.makeStateForward(speed))
96                 elif self.isStateBackward(self.seekstate):
97                         speed = -self.seekstate[1]
98 @@ -982,18 +989,27 @@ class InfoBarSeek:
99         def seekBack(self):
100                 seek = self.getSeek()
101                 if seek and not (seek.isCurrentlySeekable() & 2):
102 -                       if not self.fast_winding_hint_message_showed and (seek.isCurrentlySeekable() & 1):
103 -                               self.session.open(MessageBox, _("No fast winding possible yet.. but you can use the number buttons to skip forward/backward!"), MessageBox.TYPE_INFO, timeout=10)
104 +                       media = 1
105 +               else:
106 +                       media = 0
107 +#                      if not self.fast_winding_hint_message_showed and (seek.isCurrentlySeekable() & 1):
108 +#                              self.session.open(MessageBox, _("No fast winding possible yet.. but you can use the number buttons to skip forward/backward!"), MessageBox.TYPE_INFO, timeout=10)
109 +#                              self.fast_winding_hint_message_showed = True
110 +#                              return
111 +#                      return 0 # trade as unhandled action
112 +               seekstate = self.seekstate
113 +               if seekstate == self.SEEK_STATE_PLAY and media==0:
114 +                       self.setSeekState(self.makeStateBackward(int(config.seek.enter_backward.value)))
115 +               elif seekstate == self.SEEK_STATE_PLAY and media ==1:
116 +                       if not self.fast_winding_hint_message_showed:
117 +                               self.session.open(MessageBox, _("No rewinding possible yet.. but you can use the number buttons to skip forward/backward!"), MessageBox.TYPE_INFO, timeout=10)
118                                 self.fast_winding_hint_message_showed = True
119                                 return
120                         return 0 # trade as unhandled action
121 -               seekstate = self.seekstate
122 -               if seekstate == self.SEEK_STATE_PLAY:
123 -                       self.setSeekState(self.makeStateBackward(int(config.seek.enter_backward.value)))
124                 elif seekstate == self.SEEK_STATE_EOF:
125                         self.setSeekState(self.makeStateBackward(int(config.seek.enter_backward.value)))
126                         self.doSeekRelative(-6)
127 -               elif seekstate == self.SEEK_STATE_PAUSE:
128 +               elif seekstate == self.SEEK_STATE_PAUSE and media==0:
129                         self.doSeekRelative(-1)
130                 elif self.isStateForward(seekstate):
131                         speed = seekstate[1]
132 diff --git a/lib/service/servicemp3.cpp b/lib/service/servicemp3.cpp
133 old mode 100644
134 new mode 100755
135 index 9c24d4b..87d7f65
136 --- a/lib/service/servicemp3.cpp
137 +++ b/lib/service/servicemp3.cpp
138 @@ -234,6 +234,8 @@ eServiceMP3::eServiceMP3(eServiceReference ref)
139         m_aspect = m_width = m_height = m_framerate = m_progressive = -1;
140  
141         m_state = stIdle;
142 +       m_event_on=FALSE;
143 +       m_cur_rate=1.0;
144         eDebug("eServiceMP3::construct!");
145  
146         const char *filename = m_ref.path.c_str();
147 @@ -516,8 +518,14 @@ RESULT eServiceMP3::unpause()
148         if (!m_gst_playbin || m_state != stRunning)
149                 return -1;
150  
151 -       gst_element_set_state(m_gst_playbin, GST_STATE_PLAYING);
152 -
153 +       if(m_cur_rate!=1.0)
154 +       {       
155 +               trickSeek(1);
156 +               gst_element_set_state(m_gst_playbin, GST_STATE_PLAYING);
157 +       }else if (gst_element_set_state(m_gst_playbin, GST_STATE_PLAYING)==2){
158 +               eDebug("eServiceMP3::unpause : the state change will happen asunchronously");
159 +               trickSeek(1);
160 +       }
161         return 0;
162  }
163  
164 @@ -551,7 +559,7 @@ RESULT eServiceMP3::seekToImpl(pts_t to)
165  {
166                 /* convert pts to nanoseconds */
167         gint64 time_nanoseconds = to * 11111LL;
168 -       if (!gst_element_seek (m_gst_playbin, 1.0, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH,
169 +       if (!gst_element_seek (m_gst_playbin, m_cur_rate, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH,
170                 GST_SEEK_TYPE_SET, time_nanoseconds,
171                 GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE))
172         {
173 @@ -568,11 +576,13 @@ RESULT eServiceMP3::seekTo(pts_t to)
174  
175         if (m_gst_playbin) {
176                 eSingleLocker l(m_subs_to_pull_lock); // this is needed to dont handle incomming subtitles during seek!
177 +               m_event_on = TRUE;
178                 if (!(ret = seekToImpl(to)))
179                 {
180                         m_subtitle_pages.clear();
181                         m_subs_to_pull = 0;
182                 }
183 +               m_event_on = FALSE;
184         }
185  
186         return ret;
187 @@ -585,20 +595,25 @@ RESULT eServiceMP3::trickSeek(gdouble ratio)
188                 return -1;
189         if (!ratio)
190                 return seekRelative(0, 0);
191 +       
192 +       eSingleLocker l(m_subs_to_pull_lock);
193 +       m_event_on=TRUE;
194  
195         GstEvent *s_event;
196         int flags;
197         flags = GST_SEEK_FLAG_NONE;
198         flags |= GST_SEEK_FLAG_FLUSH;
199  //     flags |= GstSeekFlags (GST_SEEK_FLAG_ACCURATE);
200 -       flags |= GST_SEEK_FLAG_KEY_UNIT;
201 +//     flags |= GST_SEEK_FLAG_KEY_UNIT;
202  //     flags |= GstSeekFlags (GST_SEEK_FLAG_SEGMENT);
203  //     flags |= GstSeekFlags (GST_SEEK_FLAG_SKIP);
204  
205         GstFormat fmt = GST_FORMAT_TIME;
206 -       gint64 pos, len;
207 +       gint64 len;
208 +       pts_t pos;
209         gst_element_query_duration(m_gst_playbin, &fmt, &len);
210 -       gst_element_query_position(m_gst_playbin, &fmt, &pos);
211 +       getPlayPosition(pos);
212 +       pos=pos*11111;
213  
214         if ( ratio >= 0 )
215         {
216 @@ -616,7 +631,10 @@ RESULT eServiceMP3::trickSeek(gdouble ratio)
217                 eDebug("eServiceMP3::trickSeek failed");
218                 return -1;
219         }
220 -
221 +       m_subtitle_pages.clear();
222 +       m_subs_to_pull = 0;
223 +       m_event_on=FALSE;
224 +       m_cur_rate=ratio;
225         return 0;
226  }
227  
228 @@ -1500,9 +1518,11 @@ eAutoInitPtr<eServiceFactoryMP3> init_eServiceFactoryMP3(eAutoInitNumbers::servi
229  void eServiceMP3::gstCBsubtitleAvail(GstElement *appsink, gpointer user_data)
230  {
231         eServiceMP3 *_this = (eServiceMP3*)user_data;
232 -       eSingleLocker l(_this->m_subs_to_pull_lock);
233 -       ++_this->m_subs_to_pull;
234 -       _this->m_pump.send(2);
235 +       if(!_this->m_event_on){
236 +               eSingleLocker l(_this->m_subs_to_pull_lock);
237 +               ++_this->m_subs_to_pull;
238 +               _this->m_pump.send(2);
239 +       }
240  }
241  
242  void eServiceMP3::pullSubtitle()
243 @@ -1511,6 +1531,8 @@ void eServiceMP3::pullSubtitle()
244         g_object_get (G_OBJECT (m_gst_playbin), "text-sink", &sink, NULL);
245         if (sink)
246         {
247 +               if(m_event_on)
248 +                       return;
249                 while (m_subs_to_pull && m_subtitle_pages.size() < 2)
250                 {
251                         GstBuffer *buffer;
252 diff --git a/lib/service/servicemp3.h b/lib/service/servicemp3.h
253 old mode 100644
254 new mode 100755
255 index 01f7cf7..1d981b1
256 --- a/lib/service/servicemp3.h
257 +++ b/lib/service/servicemp3.h
258 @@ -227,6 +227,10 @@ private:
259         gint m_aspect, m_width, m_height, m_framerate, m_progressive;
260         std::string m_useragent;
261         RESULT trickSeek(gdouble ratio);
262 +
263 +       double m_cur_rate; 
264 +       bool m_event_on; 
265 +       
266  };
267  #endif
268