e970c5d69f8883e4195d1bbdc0ceab13232908a7
[platform/framework/web/chromium-efl.git] / tizen_src / impl / media / base / tizen / media_player_bridge_gstreamer.h
1 // Copyright 2014 Samsung Electronics Inc. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef MEDIA_TIZEN_MEDIA_PLAYER_BRIDGE_GSTREMEAR_H_
6 #define MEDIA_TIZEN_MEDIA_PLAYER_BRIDGE_GSTREMEAR_H_
7
8 #include <gst/gst.h>
9 #include <gst/pbutils/install-plugins.h>
10 #include <gst/pbutils/missing-plugins.h>
11
12 #if defined(TIZEN_MULTIMEDIA_PIXMAP_SUPPORT)
13 #include <Ecore.h>
14 #include <Ecore_X.h>
15 #endif
16
17 #include "base/memory/scoped_ptr.h"
18 #include "base/memory/weak_ptr.h"
19 #include "base/timer/timer.h"
20 #include "content/public/browser/browser_message_filter.h"
21 #include "media/base/ranges.h"
22 #include "media/base/tizen/media_player_tizen.h"
23 #include "media/base/video_frame.h"
24
25 #if defined(TIZEN_MULTIMEDIA_PIXMAP_SUPPORT)
26 #include "ui/gl/efl_pixmap.h"
27 #endif
28
29 namespace media {
30
31 class MEDIA_EXPORT MediaPlayerBridgeGstreamer
32     : public MediaPlayerTizen {
33  public:
34   MediaPlayerBridgeGstreamer(
35       int player_id,
36       const GURL& url,
37       double volume,
38       MediaPlayerManager* manager);
39   virtual ~MediaPlayerBridgeGstreamer();
40
41   // MediaPlayerTizen implementation.
42   virtual void Play() override;
43   virtual void Pause(bool is_media_related_action) override;
44   virtual void SetRate(double rate) override;
45   virtual void Seek(const double time) override;
46   virtual void SetVolume(double volume) override;
47   virtual double GetCurrentTime() override;
48   virtual void Destroy() override;
49
50   // Error handling API
51   void HandleError(media::MediaPlayerTizen::NetworkState state);
52
53   void HandleMessage(GstMessage* message);
54   void HandlePluginInstallerResult(GstInstallPluginsReturn result);
55   GstBuffer* PullBuffer();
56   void BufferReady(const GstBuffer* buffer);
57   void PrerollComplete();
58
59 #if defined(TIZEN_MULTIMEDIA_PIXMAP_SUPPORT)
60   void PlatformSurfaceUpdated();
61   int GetSurfaceID() const;
62 #endif
63
64  protected:
65   virtual void Release();
66
67  private:
68   // |duration_update_timer_| related
69   void OnCurrentTimeUpdateTimerFired();
70   void StartCurrentTimeUpdateTimer();
71   void StopCurrentTimeUpdateTimer();
72
73   // |Buffering_update_timer_| related
74   void OnBufferingUpdateTimerFired();
75   void StartBufferingUpdateTimer();
76   void StopBufferingUpdateTimer();
77
78   void UpdateStates();
79   void OnUpdateStates();
80   void UpdateDuration();
81   void UpdateMediaType();
82   void UpdateSeekState(bool state);
83
84   void OnPlaybackComplete();
85   void OnTimeChanged();
86
87   void FrameReady(const scoped_refptr<media::VideoFrame>& frame);
88   void GetFrameDetails();
89   void ProcessBufferingStats(GstMessage* message);
90   void GetBufferedTimeRanges();
91   bool SeekTo(gint64 position, float rate, GstSeekFlags seekType);
92
93   GstElement* GetVideoSink();
94   void PrepareForVideoFrame();
95
96 #if defined(TIZEN_MULTIMEDIA_PIXMAP_SUPPORT)
97   void PrepareForVideoSink();
98   void XWindowIdPrepared(GstMessage*);
99   bool IsXWindowHadleSet(){return pixmap_id_ ? true : false ;}
100   void SetPixmap();
101 #endif
102
103  private:
104   const scoped_refptr<base::MessageLoopProxy> main_loop_;
105   GstElement* gst_playbin_;
106   GstElement* gst_appsink_;
107   GURL url_;
108   double volume_;
109   gint gst_width_;
110   gint gst_height_;
111
112   bool is_prerolled_;
113   bool is_paused_;
114   double duration_;
115   double playback_rate_;
116   int buffered_;
117   guint32 video_format_;
118
119   int media_type_;
120   bool is_live_stream_;
121   bool is_file_url_;
122   bool is_end_reached_ ;
123   bool is_seeking_ ;
124   bool is_seek_pending_ ;
125   double seek_duration_;
126
127   bool error_occured_;
128   bool missing_plugins_;
129   bool is_pixmap_used_;
130
131 #if defined(TIZEN_MULTIMEDIA_PIXMAP_SUPPORT)
132   int pixmap_id_;
133   scoped_refptr<gfx::EflPixmap> efl_pixmap_;
134   Ecore_X_Damage m_damage;
135   Ecore_Event_Handler* m_damageHandler;
136 #endif
137   uint bufsize_sn12_;
138
139   base::SharedMemory shared_memory;
140   uint32 shared_memory_size;
141   base::SharedMemoryHandle foreign_memory_handle;
142
143   base::RepeatingTimer<MediaPlayerBridgeGstreamer> current_time_update_timer_;
144   base::RepeatingTimer<MediaPlayerBridgeGstreamer> buffering_update_timer_;
145
146   DISALLOW_COPY_AND_ASSIGN(MediaPlayerBridgeGstreamer);
147 };
148
149 }  // namespace media
150
151 #endif  // MEDIA_TIZEN_MEDIA_PLAYER_BRIDGE_GSTREMEAR_H_