Advertisement
Guest User

Untitled

a guest
Jun 19th, 2012
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 38.77 KB | None | 0 0
  1. From 234a24a13099540dffafea33d3983327fe4e1c8c Mon Sep 17 00:00:00 2001
  2. From: Danilo Cesar Lemes de Paula <danilo.cesar@collabora.co.uk>
  3. Date: Tue, 19 Jun 2012 14:13:14 -0300
  4. Subject: [PATCH] Adding new mediaPlayer
  5.  
  6. ---
  7. Source/WebCore/platform/graphics/MediaPlayer.cpp   |  104 +++-
  8.  Source/WebCore/platform/graphics/MediaPlayer.h     |   10 +-
  9.  .../gstreamer/MediaPlayerPrivateGStreamer.cpp      |   15 +
  10.  .../gstreamer/MediaPlayerPrivateGStreamer.h        |    3 +
  11.  .../StreamMediaPlayerPrivateGStreamer.cpp          |  622 ++++++++++++++++++++
  12.  .../gstreamer/StreamMediaPlayerPrivateGStreamer.h  |  153 +++++
  13.  6 files changed, 902 insertions(+), 5 deletions(-)
  14.  create mode 100644 Source/WebCore/platform/graphics/gstreamer/StreamMediaPlayerPrivateGStreamer.cpp
  15.  create mode 100644 Source/WebCore/platform/graphics/gstreamer/StreamMediaPlayerPrivateGStreamer.h
  16.  
  17. diff --git a/Source/WebCore/platform/graphics/MediaPlayer.cpp b/Source/WebCore/platform/graphics/MediaPlayer.cpp
  18. index 7d845ac..e746b88 100644
  19. --- a/Source/WebCore/platform/graphics/MediaPlayer.cpp
  20. +++ b/Source/WebCore/platform/graphics/MediaPlayer.cpp
  21. @@ -46,6 +46,9 @@
  22.  
  23.  #if USE(GSTREAMER)
  24.  #include "MediaPlayerPrivateGStreamer.h"
  25. +#if ENABLE(MEDIA_STREAM)
  26. +#include "StreamMediaPlayerPrivateGStreamer.h"
  27. +#endif
  28.  #define PlatformMediaEngineClassName MediaPlayerPrivateGStreamer
  29.  #endif
  30.  
  31. @@ -175,29 +178,54 @@ static PassOwnPtr<MediaPlayerPrivateInterface> createNullMediaPlayer(MediaPlayer
  32.  struct MediaPlayerFactory {
  33.      WTF_MAKE_NONCOPYABLE(MediaPlayerFactory); WTF_MAKE_FAST_ALLOCATED;
  34.  public:
  35. +#if ENABLE(MEDIA_STREAM)
  36. +    MediaPlayerFactory(CreateMediaEnginePlayer constructor, MediaEngineSupportedTypes getSupportedTypes, MediaEngineSupportsType supportsTypeAndCodecs, MediaEngineSupportsProtocol supportsProtocol,
  37. +        MediaEngineGetSitesInMediaCache getSitesInMediaCache, MediaEngineClearMediaCache clearMediaCache, MediaEngineClearMediaCacheForSite clearMediaCacheForSite)
  38. +        : constructor(constructor)
  39. +        , getSupportedTypes(getSupportedTypes)
  40. +        , supportsTypeAndCodecs(supportsTypeAndCodecs)
  41. +        , supportsProtocol(supportsProtocol)
  42. +        , getSitesInMediaCache(getSitesInMediaCache)
  43. +        , clearMediaCache(clearMediaCache)
  44. +        , clearMediaCacheForSite(clearMediaCacheForSite)
  45. +    {
  46. +    }
  47. +#else
  48.      MediaPlayerFactory(CreateMediaEnginePlayer constructor, MediaEngineSupportedTypes getSupportedTypes, MediaEngineSupportsType supportsTypeAndCodecs,
  49. -        MediaEngineGetSitesInMediaCache getSitesInMediaCache, MediaEngineClearMediaCache clearMediaCache, MediaEngineClearMediaCacheForSite clearMediaCacheForSite)
  50. +        MediaEngineGetSitesInMediaCache getSitesInMediaCache, MediaEngineClearMediaCache clearMediaCache, MediaEngineClearMediaCacheForSite clearMediaCacheForSite)
  51.          : constructor(constructor)
  52.          , getSupportedTypes(getSupportedTypes)
  53.          , supportsTypeAndCodecs(supportsTypeAndCodecs)
  54.          , getSitesInMediaCache(getSitesInMediaCache)
  55.          , clearMediaCache(clearMediaCache)
  56.          , clearMediaCacheForSite(clearMediaCacheForSite)
  57. -
  58.      {
  59.      }
  60. +#endif
  61.  
  62.      CreateMediaEnginePlayer constructor;
  63.      MediaEngineSupportedTypes getSupportedTypes;
  64.      MediaEngineSupportsType supportsTypeAndCodecs;
  65. +#if ENABLE(MEDIA_STREAM)
  66. +    MediaEngineSupportsProtocol supportsProtocol;
  67. +#endif
  68.      MediaEngineGetSitesInMediaCache getSitesInMediaCache;
  69.      MediaEngineClearMediaCache clearMediaCache;
  70.      MediaEngineClearMediaCacheForSite clearMediaCacheForSite;
  71.  };
  72.  
  73. +#if ENABLE(MEDIA_STREAM)
  74. +static void addMediaEngine(CreateMediaEnginePlayer, MediaEngineSupportedTypes, MediaEngineSupportsType, MediaEngineSupportsProtocol, MediaEngineGetSitesInMediaCache, MediaEngineClearMediaCache, MediaEngineClearMediaCacheForSite);
  75. +#else
  76.  static void addMediaEngine(CreateMediaEnginePlayer, MediaEngineSupportedTypes, MediaEngineSupportsType, MediaEngineGetSitesInMediaCache, MediaEngineClearMediaCache, MediaEngineClearMediaCacheForSite);
  77. +#endif
  78. +
  79.  static MediaPlayerFactory* bestMediaEngineForTypeAndCodecs(const String& type, const String& codecs, const String& keySystem, MediaPlayerFactory* current = 0);
  80. +#if ENABLE(MEDIA_STREAM)
  81. +static MediaPlayerFactory* bestMediaEngineForProtocolAndTypeAndCodecs(const String& type, const String& codecs, const String& keySystem, const String &protocol, MediaPlayerFactory* current = 0);
  82. +#else
  83.  static MediaPlayerFactory* nextMediaEngine(MediaPlayerFactory* current);
  84. +#endif
  85.  
  86.  static Vector<MediaPlayerFactory*>& installedMediaEngines()
  87.  {
  88. @@ -207,6 +235,10 @@ static Vector<MediaPlayerFactory*>& installedMediaEngines()
  89.      if (!enginesQueried) {
  90.          enginesQueried = true;
  91.  
  92. +#if USE(GSTREAMER) && ENABLE(MEDIA_STREAM)
  93. +        StreamMediaPlayerPrivateGStreamer::registerMediaEngine(addMediaEngine);
  94. +#endif
  95. +
  96.  #if USE(AVFOUNDATION)
  97.          if (Settings::isAVFoundationEnabled()) {
  98.  #if PLATFORM(MAC)
  99. @@ -225,6 +257,19 @@ static Vector<MediaPlayerFactory*>& installedMediaEngines()
  100.      return installedEngines;
  101.  }
  102.  
  103. +
  104. +#if ENABLE(MEDIA_STREAM)
  105. +static void addMediaEngine(CreateMediaEnginePlayer constructor, MediaEngineSupportedTypes getSupportedTypes, MediaEngineSupportsType supportsType, MediaEngineSupportsProtocol supportsProtocol,
  106. +    MediaEngineGetSitesInMediaCache getSitesInMediaCache, MediaEngineClearMediaCache clearMediaCache, MediaEngineClearMediaCacheForSite clearMediaCacheForSite)
  107. +{
  108. +    ASSERT(constructor);
  109. +    ASSERT(getSupportedTypes);
  110. +    ASSERT(supportsType);
  111. +    ASSERT(supportsProtocol);
  112. +
  113. +    installedMediaEngines().append(new MediaPlayerFactory(constructor, getSupportedTypes, supportsType, supportsProtocol, getSitesInMediaCache, clearMediaCache, clearMediaCacheForSite));
  114. +}
  115. +#else
  116.  static void addMediaEngine(CreateMediaEnginePlayer constructor, MediaEngineSupportedTypes getSupportedTypes, MediaEngineSupportsType supportsType,
  117.      MediaEngineGetSitesInMediaCache getSitesInMediaCache, MediaEngineClearMediaCache clearMediaCache, MediaEngineClearMediaCacheForSite clearMediaCacheForSite)
  118.  {
  119. @@ -234,6 +279,7 @@ static void addMediaEngine(CreateMediaEnginePlayer constructor, MediaEngineSuppo
  120.  
  121.      installedMediaEngines().append(new MediaPlayerFactory(constructor, getSupportedTypes, supportsType, getSitesInMediaCache, clearMediaCache, clearMediaCacheForSite));
  122.  }
  123. +#endif
  124.  
  125.  static const AtomicString& applicationOctetStream()
  126.  {
  127. @@ -295,6 +341,51 @@ static MediaPlayerFactory* bestMediaEngineForTypeAndCodecs(const String& type, c
  128.      return engine;
  129.  }
  130.  
  131. +#if ENABLE(MEDIA_STREAM)
  132. +static MediaPlayerFactory* bestMediaEngineForProtocolAndTypeAndCodecs(const String& type, const String& codecs, const String& keySystem, const String &url, MediaPlayerFactory* current)
  133. +{
  134. +    Vector<MediaPlayerFactory*>& engines = installedMediaEngines();
  135. +    if (engines.isEmpty())
  136. +        return 0;
  137. +
  138. +    // 4.8.10.3 MIME types - In the absence of a specification to the contrary, the MIME type "application/octet-stream"
  139. +    // when used with parameters, e.g. "application/octet-stream;codecs=theora", is a type that the user agent knows
  140. +    // it cannot render.
  141. +    if (type == applicationOctetStream()) {
  142. +        if (!codecs.isEmpty())
  143. +            return 0;
  144. +    }
  145. +
  146. +    MediaPlayerFactory* engine = 0;
  147. +    MediaPlayer::SupportsType supported = MediaPlayer::IsNotSupported;
  148. +    unsigned count = engines.size();
  149. +    for (unsigned ndx = 0; ndx < count; ndx++) {
  150. +        if (current) {
  151. +            if (current == engines[ndx])
  152. +                current = 0;
  153. +            continue;
  154. +        }
  155. +        if (engines[ndx]->supportsProtocol(url) == MediaPlayer::IsSupported) {
  156. +            supported = MediaPlayer::IsSupported;
  157. +            engine = engines[ndx];
  158. +        } else {
  159. +#if ENABLE(ENCRYPTED_MEDIA)
  160. +                MediaPlayer::SupportsType engineSupport = engines[ndx]->supportsTypeAndCodecs(type, codecs, keySystem);
  161. +#else
  162. +                UNUSED_PARAM(keySystem);
  163. +                ASSERT(keySystem.isEmpty());
  164. +                MediaPlayer::SupportsType engineSupport = engines[ndx]->supportsTypeAndCodecs(type, codecs);
  165. +#endif
  166. +            if (engineSupport > supported) {
  167. +                supported = engineSupport;
  168. +                engine = engines[ndx];
  169. +            }
  170. +        }
  171. +    }
  172. +
  173. +    return engine;
  174. +}
  175. +#else
  176.  static MediaPlayerFactory* nextMediaEngine(MediaPlayerFactory* current)
  177.  {
  178.      Vector<MediaPlayerFactory*>& engines = installedMediaEngines();
  179. @@ -310,6 +401,7 @@ static MediaPlayerFactory* nextMediaEngine(MediaPlayerFactory* current)
  180.  
  181.      return engines[currentIndex + 1];
  182.  }
  183. +#endif
  184.  
  185.  // media player
  186.  
  187. @@ -382,12 +474,18 @@ void MediaPlayer::loadWithNextMediaEngine(MediaPlayerFactory* current)
  188.  {
  189.      MediaPlayerFactory* engine = 0;
  190.  
  191. +    LOG (MediaStream, "=========== content type %s", m_contentMIMEType.utf8().data());
  192. +
  193. +#if ENABLE(MEDIA_STREAM)
  194. +    engine = bestMediaEngineForProtocolAndTypeAndCodecs(m_contentMIMEType, m_contentTypeCodecs, m_keySystem, m_url, current);
  195. +#else
  196.      if (!m_contentMIMEType.isEmpty())
  197.          engine = bestMediaEngineForTypeAndCodecs(m_contentMIMEType, m_contentTypeCodecs, m_keySystem, current);
  198.  
  199.      // If no MIME type is specified or the type was inferred from the file extension, just use the next engine.
  200.      if (!engine && (m_contentMIMEType.isEmpty() || m_contentMIMETypeWasInferredFromExtension))
  201.          engine = nextMediaEngine(current);
  202. +#endif
  203.  
  204.      // Don't delete and recreate the player unless it comes from a different engine.
  205.      if (!engine) {
  206. @@ -418,7 +516,7 @@ void MediaPlayer::loadWithNextMediaEngine(MediaPlayerFactory* current)
  207.              m_mediaPlayerClient->mediaPlayerResourceNotSupported(this);
  208.          }
  209.      }
  210. -}    
  211. +}
  212.  
  213.  bool MediaPlayer::hasAvailableVideoFrame() const
  214.  {
  215. diff --git a/Source/WebCore/platform/graphics/MediaPlayer.h b/Source/WebCore/platform/graphics/MediaPlayer.h
  216. index 6c722a0..e6d0658 100644
  217. --- a/Source/WebCore/platform/graphics/MediaPlayer.h
  218. +++ b/Source/WebCore/platform/graphics/MediaPlayer.h
  219. @@ -431,9 +431,15 @@ typedef void (*MediaEngineGetSitesInMediaCache)(Vector<String>&);
  220.  typedef void (*MediaEngineClearMediaCache)();
  221.  typedef void (*MediaEngineClearMediaCacheForSite)(const String&);
  222.  
  223. -typedef void (*MediaEngineRegistrar)(CreateMediaEnginePlayer, MediaEngineSupportedTypes, MediaEngineSupportsType,
  224. -    MediaEngineGetSitesInMediaCache, MediaEngineClearMediaCache, MediaEngineClearMediaCacheForSite);
  225. +#if ENABLE(MEDIA_STREAM)
  226. +typedef MediaPlayer::SupportsType (*MediaEngineSupportsProtocol)(const String& url);
  227.  
  228. +typedef void (*MediaEngineRegistrar)(CreateMediaEnginePlayer, MediaEngineSupportedTypes, MediaEngineSupportsType, MediaEngineSupportsProtocol,
  229. +    MediaEngineGetSitesInMediaCache, MediaEngineClearMediaCache, MediaEngineClearMediaCacheForSite);
  230. +#else
  231. +typedef void (*MediaEngineRegistrar)(CreateMediaEnginePlayer, MediaEngineSupportedTypes, MediaEngineSupportsType,
  232. +    MediaEngineGetSitesInMediaCache, MediaEngineClearMediaCache, MediaEngineClearMediaCacheForSite);
  233. +#endif
  234.  
  235.  }
  236.  
  237. diff --git a/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp b/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp
  238. index 839708e..d3ae420 100644
  239. --- a/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp
  240. +++ b/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp
  241. @@ -173,7 +173,11 @@ PassOwnPtr<MediaPlayerPrivateInterface> MediaPlayerPrivateGStreamer::create(Medi
  242.  void MediaPlayerPrivateGStreamer::registerMediaEngine(MediaEngineRegistrar registrar)
  243.  {
  244.      if (isAvailable())
  245. +#if ENABLE(MEDIA_STREAM)
  246. +        registrar(create, getSupportedTypes, supportsType, supportsProtocol, 0, 0, 0);
  247. +#else
  248.          registrar(create, getSupportedTypes, supportsType, 0, 0, 0);
  249. +#endif
  250.  }
  251.  
  252.  bool initializeGStreamerAndRegisterWebKitElements()
  253. @@ -1453,6 +1457,17 @@ void MediaPlayerPrivateGStreamer::loadingFailed(MediaPlayer::NetworkState error)
  254.      }
  255.  }
  256.  
  257. +#if ENABLE(MEDIA_STREAM)
  258. +MediaPlayer::SupportsType MediaPlayerPrivateGStreamer::supportsProtocol(const String& url)
  259. +{
  260. +    return MediaPlayer::IsNotSupported;
  261. +}
  262. +#endif
  263. +
  264. +
  265.  void MediaPlayerPrivateGStreamer::setSize(const IntSize& size)
  266.  {
  267.      m_size = size;
  268. diff --git a/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h b/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h
  269. index 39ee9ce..63230c2 100644
  270. --- a/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h
  271. +++ b/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h
  272. @@ -131,6 +131,9 @@ class MediaPlayerPrivateGStreamer : public MediaPlayerPrivateInterface {
  273.  
  274.              static void getSupportedTypes(HashSet<String>&);
  275.              static MediaPlayer::SupportsType supportsType(const String& type, const String& codecs);
  276. +#if ENABLE(MEDIA_STREAM)
  277. +            static MediaPlayer::SupportsType supportsProtocol(const String& url);
  278. +#endif
  279.              static bool isAvailable();
  280.  
  281.              void updateAudioSink();
  282. diff --git a/Source/WebCore/platform/graphics/gstreamer/StreamMediaPlayerPrivateGStreamer.cpp b/Source/WebCore/platform/graphics/gstreamer/StreamMediaPlayerPrivateGStreamer.cpp
  283. new file mode 100644
  284. index 0000000..dc550b1
  285. --- /dev/null
  286. +++ b/Source/WebCore/platform/graphics/gstreamer/StreamMediaPlayerPrivateGStreamer.cpp
  287. @@ -0,0 +1,622 @@
  288. +/*
  289. + *  Copyright (C) 2012 Collabora Ltd. All rights reserved.
  290. + *
  291. + *  This library is free software; you can redistribute it and/or
  292. + *  modify it under the terms of the GNU Lesser General Public
  293. + *  License as published by the Free Software Foundation; either
  294. + *  version 2 of the License, or (at your option) any later version.
  295. + *
  296. + *  This library is distributed in the hope that it will be useful,
  297. + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  298. + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  299. + *  Lesser General Public License for more details.
  300. + *
  301. + *  You should have received a copy of the GNU Lesser General Public
  302. + *  License along with this library; if not, write to the Free Software
  303. + *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  304. + */
  305. +
  306. +
  307. +#include "config.h"
  308. +
  309. +#if ENABLE(MEDIA_STREAM) && USE(GSTREAMER)
  310. +
  311. +#include "StreamMediaPlayerPrivateGStreamer.h"
  312. +
  313. +#include "CentralPipelineUnit.h"
  314. +#include "MediaStream.h"
  315. +
  316. +#include "GraphicsContext.h"
  317. +#include "GraphicsTypes.h"
  318. +#include "GStreamerGWorld.h"
  319. +#include "ImageGStreamer.h"
  320. +#include "IntRect.h"
  321. +#include "KURL.h"
  322. +#include "MediaPlayer.h"
  323. +#include "MediaStreamRegistry.h"
  324. +#include "VideoSinkGStreamer.h"
  325. +#include "WebKitWebSourceGStreamer.h"
  326. +#include <wtf/gobject/GOwnPtr.h>
  327. +#include <gst/gst.h>
  328. +#include <gst/video/video.h>
  329. +#include <math.h>
  330. +
  331. +#include "Logging.h"
  332. +
  333. +namespace WebCore {
  334. +
  335. +void streamMediaPlayerPrivateVolumeChangedCallback(GObject* element, GParamSpec* pspec, gpointer data);
  336. +void streamMediaPlayerPrivateMuteChangedCallback(GObject* element, GParamSpec* pspec, gpointer data);
  337. +gboolean streamMediaPlayerPrivateVolumeChangeTimeoutCallback(StreamMediaPlayerPrivateGStreamer*);
  338. +gboolean streamMediaPlayerPrivateMuteChangeTimeoutCallback(StreamMediaPlayerPrivateGStreamer*);
  339. +
  340. +
  341. +static bool doGstInit();
  342. +
  343. +static int greatestCommonDivisor(int a, int b)
  344. +{
  345. +    while (b) {
  346. +        int temp = a;
  347. +        a = b;
  348. +        b = temp % b;
  349. +    }
  350. +
  351. +    return ABS(a);
  352. +}
  353. +
  354. +void streamMediaPlayerPrivateVolumeChangedCallback(GObject *element, GParamSpec *pspec, gpointer data)
  355. +{
  356. +    StreamMediaPlayerPrivateGStreamer* mp = reinterpret_cast<StreamMediaPlayerPrivateGStreamer*>(data);
  357. +    mp->volumeChanged();
  358. +}
  359. +
  360. +gboolean streamMediaPlayerPrivateVolumeChangeTimeoutCallback(StreamMediaPlayerPrivateGStreamer* player)
  361. +{
  362. +    player->notifyPlayerOfVolumeChange();
  363. +    return FALSE;
  364. +}
  365. +
  366. +void streamMediaPlayerPrivateMuteChangedCallback(GObject *element, GParamSpec *pspec, gpointer data)
  367. +{
  368. +    StreamMediaPlayerPrivateGStreamer* mp = reinterpret_cast<StreamMediaPlayerPrivateGStreamer*>(data);
  369. +    mp->muteChanged();
  370. +}
  371. +
  372. +gboolean streamMediaPlayerPrivateMuteChangeTimeoutCallback(StreamMediaPlayerPrivateGStreamer* player)
  373. +{
  374. +    player->notifyPlayerOfMute();
  375. +    return FALSE;
  376. +}
  377. +
  378. +
  379. +StreamMediaPlayerPrivateGStreamer::StreamMediaPlayerPrivateGStreamer(MediaPlayer* player)
  380. +    : m_player(player)
  381. +    , m_webkitVideoSink(0)
  382. +    , m_videoSinkBin(0)
  383. +    , m_audioSinkBin(0)
  384. +    , m_volume(0)
  385. +    , m_buffer(0)
  386. +    , m_networkState(MediaPlayer::Empty)
  387. +    , m_readyState(MediaPlayer::HaveNothing)
  388. +    , m_paused(true)
  389. +    , m_stopped(true)
  390. +    , m_volumeTimerHandler(0)
  391. +    , m_muteTimerHandler(0)
  392. +    , m_repaintCallbackHandlerId(0)
  393. +{
  394. +    //LOG(StreamAPI, "StreamAPI - Creating Stream media player");
  395. +
  396. +    if (doGstInit()) {
  397. +        createGSTVideoSinkBin();
  398. +        createGSTAudioSinkBin();
  399. +    }
  400. +}
  401. +
  402. +StreamMediaPlayerPrivateGStreamer::~StreamMediaPlayerPrivateGStreamer()
  403. +{
  404. +    LOG(MediaStream, "StreamMediaPlayerPrivateGStreamer destructor called.");
  405. +
  406. +    g_signal_handler_disconnect(m_webkitVideoSink, m_repaintCallbackHandlerId);
  407. +
  408. +    if (m_buffer)
  409. +        gst_buffer_unref(m_buffer);
  410. +    m_buffer = 0;
  411. +
  412. +    stop();
  413. +
  414. +    if (m_audioSinkBin) {
  415. +        gst_object_unref(m_audioSinkBin);
  416. +        m_audioSinkBin = 0;
  417. +    }
  418. +
  419. +    if (m_videoSinkBin) {
  420. +        gst_object_unref(m_videoSinkBin);
  421. +        m_videoSinkBin = 0;
  422. +    }
  423. +
  424. +    m_player = 0;
  425. +
  426. +    if (m_muteTimerHandler)
  427. +        g_source_remove(m_muteTimerHandler);
  428. +
  429. +    if (m_volumeTimerHandler)
  430. +        g_source_remove(m_volumeTimerHandler);
  431. +}
  432. +
  433. +void StreamMediaPlayerPrivateGStreamer::play()
  434. +{
  435. +    LOG(MediaStream, "StreamMediaPlayerPrivateGStreamer::play() called.");
  436. +    m_paused = false;
  437. +
  438. +    internalLoad();
  439. +}
  440. +
  441. +void StreamMediaPlayerPrivateGStreamer::pause()
  442. +{
  443. +    LOG(MediaStream, "StreamMediaPlayerPrivateGStreamer::pause() called.");
  444. +    m_paused = true;
  445. +    stop();
  446. +}
  447. +
  448. +
  449. +bool StreamMediaPlayerPrivateGStreamer::hasVideo() const
  450. +{
  451. +    return !m_videoSourceId.isEmpty();
  452. +}
  453. +
  454. +bool StreamMediaPlayerPrivateGStreamer::hasAudio() const
  455. +{
  456. +    return !m_audioSourceId.isEmpty();
  457. +}
  458. +
  459. +void StreamMediaPlayerPrivateGStreamer::setVolume(float volume)
  460. +{
  461. +    if (!m_volume)
  462. +        return;
  463. +    g_object_set(m_volume, "volume", static_cast<double>(volume), NULL);
  464. +}
  465. +
  466. +void StreamMediaPlayerPrivateGStreamer::notifyPlayerOfVolumeChange()
  467. +{
  468. +    m_volumeTimerHandler = 0;
  469. +
  470. +    if (!m_player || !m_volume)
  471. +        return;
  472. +    double volume;
  473. +    g_object_get(m_volume, "volume", &volume, NULL);
  474. +    m_player->volumeChanged(static_cast<float>(volume));
  475. +}
  476. +
  477. +void StreamMediaPlayerPrivateGStreamer::volumeChanged()
  478. +{
  479. +    if (m_volumeTimerHandler)
  480. +        g_source_remove(m_volumeTimerHandler);
  481. +    m_volumeTimerHandler = g_timeout_add(0, reinterpret_cast<GSourceFunc>(streamMediaPlayerPrivateVolumeChangeTimeoutCallback), this);
  482. +}
  483. +
  484. +
  485. +bool StreamMediaPlayerPrivateGStreamer::supportsMuting() const
  486. +{
  487. +    return true;
  488. +}
  489. +
  490. +void StreamMediaPlayerPrivateGStreamer::setMuted(bool muted)
  491. +{
  492. +    if (!m_volume)
  493. +        return;
  494. +
  495. +    g_object_set(m_volume, "mute", muted, NULL);
  496. +}
  497. +
  498. +void StreamMediaPlayerPrivateGStreamer::notifyPlayerOfMute()
  499. +{
  500. +    m_muteTimerHandler = 0;
  501. +
  502. +    if (!m_player || !m_volume)
  503. +        return;
  504. +
  505. +    gboolean muted;
  506. +    g_object_get(m_volume, "mute", &muted, NULL);
  507. +    m_player->muteChanged(static_cast<bool>(muted));
  508. +}
  509. +
  510. +void StreamMediaPlayerPrivateGStreamer::muteChanged()
  511. +{
  512. +    if (m_muteTimerHandler)
  513. +        g_source_remove(m_muteTimerHandler);
  514. +    m_muteTimerHandler = g_timeout_add(0, reinterpret_cast<GSourceFunc>(streamMediaPlayerPrivateMuteChangeTimeoutCallback), this);
  515. +}
  516. +
  517. +
  518. +void StreamMediaPlayerPrivateGStreamer::load(const String &url)
  519. +{
  520. +    //LOG(StreamAPI, "StreamAPI - Stream media player - load");
  521. +
  522. +    m_streamDescriptor = MediaStreamRegistry::registry().lookupMediaStreamDescriptor(url);
  523. +    if (!m_streamDescriptor || m_streamDescriptor->ended()) {
  524. +        loadingFailed(MediaPlayer::NetworkError);
  525. +        return;
  526. +    }
  527. +
  528. +    m_readyState = MediaPlayer::HaveNothing;
  529. +    m_networkState = MediaPlayer::Empty;
  530. +    m_player->networkStateChanged();
  531. +    m_player->readyStateChanged();
  532. +
  533. +    if (!internalLoad())
  534. +        return;
  535. +
  536. +    if (hasVideo()) {
  537. +        // Wait for first video frame to set HaveEnoughData
  538. +        m_readyState = MediaPlayer::HaveNothing;
  539. +    } else {
  540. +        m_readyState = MediaPlayer::HaveEnoughData;
  541. +    }
  542. +
  543. +    m_networkState = MediaPlayer::Loaded;
  544. +    m_player->networkStateChanged();
  545. +    m_player->readyStateChanged();
  546. +
  547. +}
  548. +
  549. +void StreamMediaPlayerPrivateGStreamer::loadingFailed(MediaPlayer::NetworkState error)
  550. +{
  551. +
  552. +    if (m_networkState != error) {
  553. +        m_networkState = error;
  554. +        m_player->networkStateChanged();
  555. +    }
  556. +    if (m_readyState != MediaPlayer::HaveNothing) {
  557. +        m_readyState = MediaPlayer::HaveNothing;
  558. +        m_player->readyStateChanged();
  559. +    }
  560. +}
  561. +
  562. +bool StreamMediaPlayerPrivateGStreamer::didLoadingProgress() const
  563. +{
  564. +    return true;
  565. +}
  566. +
  567. +bool StreamMediaPlayerPrivateGStreamer::internalLoad()
  568. +{
  569. +    if (m_stopped) {
  570. +        m_stopped = false;
  571. +        if (!m_streamDescriptor || m_streamDescriptor->ended()) {
  572. +            loadingFailed(MediaPlayer::NetworkError);
  573. +            return false;
  574. +        }
  575. +        return connectToGSTLiveStream(m_streamDescriptor.get());
  576. +    }
  577. +    return false;
  578. +}
  579. +
  580. +void StreamMediaPlayerPrivateGStreamer::stop()
  581. +{
  582. +    if (!m_stopped) {
  583. +        m_stopped = true;
  584. +        CentralPipelineUnit &cpu = centralPipelineUnit();
  585. +        if (!m_audioSourceId.isEmpty()) {
  586. +            LOG(MediaStream, "StreamMediaPlayerPrivateGStreamer stop: disconnecting audio");
  587. +            cpu.disconnectFromSource(m_audioSourceId, m_audioSinkBin);
  588. +        }
  589. +        if (!m_videoSourceId.isEmpty()) {
  590. +            LOG(MediaStream, "StreamMediaPlayerPrivateGStreamer stop: disconnecting video");
  591. +            cpu.disconnectFromSource(m_videoSourceId, m_videoSinkBin);
  592. +        }
  593. +        m_audioSourceId = "";
  594. +        m_videoSourceId = "";
  595. +    }
  596. +}
  597. +
  598. +
  599. +void mediaPlayerPrivateRepaintCallback(WebKitVideoSink*, GstBuffer *buffer, StreamMediaPlayerPrivateGStreamer* playerPrivate)
  600. +{
  601. +    g_return_if_fail(GST_IS_BUFFER(buffer));
  602. +
  603. +    if (!playerPrivate->m_buffer) {
  604. +        playerPrivate->m_readyState = MediaPlayer::HaveEnoughData;
  605. +        playerPrivate->m_player->readyStateChanged();
  606. +    }
  607. +
  608. +    if (!playerPrivate->m_paused || !playerPrivate->m_buffer) {
  609. +        gst_buffer_replace(&playerPrivate->m_buffer, buffer);
  610. +
  611. +        IntSize size = playerPrivate->calculateSize();
  612. +        playerPrivate->updateCurrentSize(size);
  613. +
  614. +        playerPrivate->repaint();
  615. +    }
  616. +}
  617. +
  618. +
  619. +PassOwnPtr<MediaPlayerPrivateInterface> StreamMediaPlayerPrivateGStreamer::create(MediaPlayer* player)
  620. +{
  621. +    return adoptPtr(new StreamMediaPlayerPrivateGStreamer(player));
  622. +}
  623. +
  624. +void StreamMediaPlayerPrivateGStreamer::registerMediaEngine(MediaEngineRegistrar registrar)
  625. +{
  626. +    if (isAvailable())
  627. +        registrar(create, getSupportedTypes, supportsType, supportsProtocol, 0, 0, 0);
  628. +}
  629. +
  630. +void StreamMediaPlayerPrivateGStreamer::getSupportedTypes(HashSet<String>& types)
  631. +{
  632. +    types.add(String("video/x-raw-yuv"));
  633. +    types.add(String("audio/x-raw-int"));
  634. +}
  635. +
  636. +MediaPlayer::SupportsType StreamMediaPlayerPrivateGStreamer::supportsType(const String& type, const String& codecs)
  637. +{
  638. +    return MediaPlayer::IsNotSupported;
  639. +}
  640. +
  641. +MediaPlayer::SupportsType StreamMediaPlayerPrivateGStreamer::supportsProtocol(const String& url)
  642. +{
  643. +    if (url.isNull() || url.isEmpty())
  644. +        return MediaPlayer::IsNotSupported;
  645. +
  646. +    return MediaStreamRegistry::registry().lookupMediaStreamDescriptor(url) ? MediaPlayer::IsSupported : MediaPlayer::IsNotSupported;
  647. +}
  648. +
  649. +
  650. +static bool gstInitialized = false;
  651. +
  652. +static bool doGstInit()
  653. +{
  654. +    if (!gstInitialized) {
  655. +        GOwnPtr<GError> error;
  656. +        gstInitialized = gst_init_check(0, 0, &error.outPtr());
  657. +    }
  658. +    return gstInitialized;
  659. +}
  660. +
  661. +
  662. +bool StreamMediaPlayerPrivateGStreamer::isAvailable()
  663. +{
  664. +
  665. +    if (!doGstInit())
  666. +        return false;
  667. +
  668. +    return true;
  669. +}
  670. +
  671. +
  672. +void StreamMediaPlayerPrivateGStreamer::repaint()
  673. +{
  674. +    m_player->repaint();
  675. +}
  676. +
  677. +void StreamMediaPlayerPrivateGStreamer::paint(GraphicsContext* context, const IntRect& rect)
  678. +{
  679. +    if (context->paintingDisabled())
  680. +        return;
  681. +
  682. +    if (!m_player->visible())
  683. +        return;
  684. +    if (!m_buffer)
  685. +        return;
  686. +
  687. +    RefPtr<ImageGStreamer> gstImage = ImageGStreamer::createImage(m_buffer);
  688. +    if (!gstImage)
  689. +        return;
  690. +
  691. +    context->drawImage(reinterpret_cast<Image*>(gstImage->image().get()), ColorSpaceSRGB,
  692. +                       rect, CompositeCopy, WebCore::DoNotRespectImageOrientation, false);
  693. +}
  694. +
  695. +
  696. +// Returns the size of the video
  697. +IntSize StreamMediaPlayerPrivateGStreamer::naturalSize() const
  698. +{
  699. +    return m_currentSize;
  700. +}
  701. +
  702. +bool StreamMediaPlayerPrivateGStreamer::supportsFullscreen() const
  703. +{
  704. +    return false;
  705. +}
  706. +
  707. +PlatformMedia StreamMediaPlayerPrivateGStreamer::platformMedia() const
  708. +{
  709. +    PlatformMedia p;
  710. +    p.type = PlatformMedia::GStreamerGWorldType;
  711. +    p.media.gstreamerGWorld = m_gstGWorld.get();
  712. +    return p;
  713. +}
  714. +
  715. +
  716. +void StreamMediaPlayerPrivateGStreamer::createGSTVideoSinkBin()
  717. +{
  718. +    LOG(MediaStream, "createGSTVideoSinkBin called");
  719. +    m_gstGWorld = GStreamerGWorld::createGWorld(0);
  720. +    m_webkitVideoSink = webkitVideoSinkNew(m_gstGWorld.get());
  721. +
  722. +    gchar* name = gst_element_get_name(m_webkitVideoSink);
  723. +    LOG(MediaStream, "m_webkitVideoSink=%p name=%s", m_webkitVideoSink, name);
  724. +
  725. +    m_repaintCallbackHandlerId = g_signal_connect(m_webkitVideoSink, "repaint-requested", G_CALLBACK(mediaPlayerPrivateRepaintCallback), this);
  726. +
  727. +    m_videoSinkBin = gst_bin_new(0);
  728. +    GstElement* colorspace = gst_element_factory_make("ffmpegcolorspace", 0);
  729. +    GstElement* videoTee = gst_element_factory_make("tee", "videoTee");
  730. +    GstElement* queue = gst_element_factory_make("queue", 0);
  731. +    GstElement* identity = gst_element_factory_make("identity", "videoValve");
  732. +
  733. +    // Take ownership.
  734. +    gst_object_ref_sink(m_videoSinkBin);
  735. +
  736. +    // Build a new video sink consisting of a bin containing a tee
  737. +    // (meant to distribute data to multiple video sinks) and our
  738. +    // internal video sink. For fullscreen we create an autovideosink
  739. +    // and initially block the data flow towards it and configure it
  740. +
  741. +    gst_bin_add_many(GST_BIN(m_videoSinkBin), colorspace, videoTee, queue, identity, m_webkitVideoSink, NULL);
  742. +
  743. +    gst_element_link(colorspace, videoTee);
  744. +    // Link a new src pad from tee to queue1.
  745. +    GstPad* srcPad = gst_element_get_request_pad(videoTee, "src%d");
  746. +    GstPad* sinkPad = gst_element_get_static_pad(queue, "sink");
  747. +    gst_pad_link(srcPad, sinkPad);
  748. +    gst_object_unref(GST_OBJECT(srcPad));
  749. +    gst_object_unref(GST_OBJECT(sinkPad));
  750. +    gst_element_link_many(queue, identity, m_webkitVideoSink, NULL);
  751. +
  752. +    g_object_set(m_webkitVideoSink, "async", FALSE, NULL);
  753. +
  754. +    // Add a ghostpad to the bin so it can proxy to tee.
  755. +    GstPad* pad = gst_element_get_static_pad(colorspace, "sink");
  756. +    gst_element_add_pad(m_videoSinkBin, gst_ghost_pad_new("sink", pad));
  757. +    gst_object_unref(GST_OBJECT(pad));
  758. +
  759. +}
  760. +
  761. +void StreamMediaPlayerPrivateGStreamer::createGSTAudioSinkBin()
  762. +{
  763. +
  764. +    m_audioSinkBin = gst_bin_new(0);
  765. +    gst_object_ref_sink(m_audioSinkBin);
  766. +
  767. +    m_volume = gst_element_factory_make("volume", "volume");
  768. +
  769. +    g_object_set(m_volume, "mute", m_player->muted(), "volume", m_player->volume(), NULL);
  770. +
  771. +    g_signal_connect(m_volume, "notify::volume", G_CALLBACK(streamMediaPlayerPrivateVolumeChangedCallback), this);
  772. +    g_signal_connect(m_volume, "notify::mute", G_CALLBACK(streamMediaPlayerPrivateMuteChangedCallback), this);
  773. +
  774. +
  775. +    GstElement *audioSink = gst_element_factory_make("autoaudiosink", 0);
  776. +    gst_bin_add_many(GST_BIN(m_audioSinkBin), m_volume, audioSink, NULL);
  777. +    gst_element_link_many(m_volume, audioSink, NULL);
  778. +
  779. +    GstPad* pad = gst_element_get_static_pad(m_volume, "sink");
  780. +    gst_element_add_pad(m_audioSinkBin, gst_ghost_pad_new("sink", pad));
  781. +    gst_object_unref(GST_OBJECT(pad));
  782. +}
  783. +
  784. +bool StreamMediaPlayerPrivateGStreamer::connectToGSTLiveStream(MediaStreamDescriptor* streamDescriptor)
  785. +{
  786. +    LOG(MediaStream, "connectToGSTLiveStream called");
  787. +    if (!streamDescriptor)
  788. +        return false;
  789. +
  790. +    // FIXME: Error handling.. this could fail.. and this method never returns false.
  791. +
  792. +    CentralPipelineUnit &cpu = centralPipelineUnit();
  793. +
  794. +    if (!m_audioSourceId.isEmpty()) {
  795. +        cpu.disconnectFromSource(m_audioSourceId, m_audioSinkBin);
  796. +        m_audioSourceId = "";
  797. +    }
  798. +
  799. +    if (!m_videoSourceId.isEmpty()) {
  800. +        cpu.disconnectFromSource(m_videoSourceId, m_videoSinkBin);
  801. +        m_videoSourceId = "";
  802. +    }
  803. +
  804. +    for (unsigned i = 0; i < streamDescriptor->numberOfAudioComponents(); i++) {
  805. +        MediaStreamComponent* component = streamDescriptor->audioComponent(i);
  806. +        if (!component->enabled())
  807. +            continue;
  808. +
  809. +        MediaStreamSource* source = component->source();
  810. +        if (source->type() == MediaStreamSource::TypeAudio) {
  811. +            if (cpu.connectToSource(source->id(), m_audioSinkBin)) {
  812. +                m_audioSourceId = source->id();
  813. +                // FIXME: Break since we don't support mixing of audio tracks yet.
  814. +                break;
  815. +            }
  816. +        }
  817. +    }
  818. +
  819. +    for (unsigned i = 0; i < streamDescriptor->numberOfVideoComponents(); i++) {
  820. +        MediaStreamComponent* component = streamDescriptor->videoComponent(i);
  821. +        if (!component->enabled())
  822. +            continue;
  823. +
  824. +        MediaStreamSource* source = component->source();
  825. +        if (source->type() == MediaStreamSource::TypeVideo) {
  826. +            if (cpu.connectToSource(source->id(), m_videoSinkBin)) {
  827. +                m_audioSourceId = source->id();
  828. +                // FIXME: Break since we don't support mixing of audio tracks yet.
  829. +                break;
  830. +            }
  831. +        }
  832. +    }
  833. +
  834. +    return true;
  835. +}
  836. +
  837. +IntSize StreamMediaPlayerPrivateGStreamer::calculateSize()
  838. +{
  839. +
  840. +    if (!hasVideo())
  841. +        return IntSize();
  842. +
  843. +    GstPad* pad = gst_element_get_static_pad(m_webkitVideoSink, "sink");
  844. +    if (!pad)
  845. +        return IntSize();
  846. +
  847. +    guint64 width = 0, height = 0;
  848. +    GstCaps* caps = GST_PAD_CAPS(pad);
  849. +    int pixelAspectRatioNumerator, pixelAspectRatioDenominator;
  850. +    int displayWidth, displayHeight, displayAspectRatioGCD;
  851. +    int originalWidth = 0, originalHeight = 0;
  852. +
  853. +    // TODO: handle possible clean aperture data. See
  854. +    // https://bugzilla.gnome.org/show_bug.cgi?id=596571
  855. +    // TODO: handle possible transformation matrix. See
  856. +    // https://bugzilla.gnome.org/show_bug.cgi?id=596326
  857. +
  858. +    // Get the video PAR and original size.
  859. +    if (!GST_IS_CAPS(caps) || !gst_caps_is_fixed(caps)
  860. +        || !gst_video_format_parse_caps(caps, 0, &originalWidth, &originalHeight)
  861. +        || !gst_video_parse_caps_pixel_aspect_ratio(caps, &pixelAspectRatioNumerator,
  862. +                                                    &pixelAspectRatioDenominator)) {
  863. +        gst_object_unref(GST_OBJECT(pad));
  864. +        return IntSize();
  865. +    }
  866. +
  867. +    gst_object_unref(GST_OBJECT(pad));
  868. +
  869. +    //LOG_VERBOSE(Media, "Original video size: %dx%d", originalWidth, originalHeight);
  870. +    //LOG_VERBOSE(Media, "Pixel aspect ratio: %d/%d", pixelAspectRatioNumerator, pixelAspectRatioDenominator);
  871. +
  872. +    // Calculate DAR based on PAR and video size.
  873. +    displayWidth = originalWidth * pixelAspectRatioNumerator;
  874. +    displayHeight = originalHeight * pixelAspectRatioDenominator;
  875. +
  876. +    // Divide display width and height by their GCD to avoid possible overflows.
  877. +    displayAspectRatioGCD = greatestCommonDivisor(displayWidth, displayHeight);
  878. +    displayWidth /= displayAspectRatioGCD;
  879. +    displayHeight /= displayAspectRatioGCD;
  880. +
  881. +    // Apply DAR to original video size. This is the same behavior as in xvimagesink's setcaps function.
  882. +    if (!(originalHeight % displayHeight)) {
  883. +        //LOG_VERBOSE(Media, "Keeping video original height");
  884. +        width = gst_util_uint64_scale_int(originalHeight, displayWidth, displayHeight);
  885. +        height = static_cast<guint64>(originalHeight);
  886. +    } else if (!(originalWidth % displayWidth)) {
  887. +        // LOG_VERBOSE(Media, "Keeping video original width");
  888. +        height = gst_util_uint64_scale_int(originalWidth, displayHeight, displayWidth);
  889. +        width = static_cast<guint64>(originalWidth);
  890. +    } else {
  891. +        // LOG_VERBOSE(Media, "Approximating while keeping original video height");
  892. +        width = gst_util_uint64_scale_int(originalHeight, displayWidth, displayHeight);
  893. +        height = static_cast<guint64>(originalHeight);
  894. +    }
  895. +
  896. +    // LOG_VERBOSE(Media, "Natural size: %" G_GUINT64_FORMAT "x%" G_GUINT64_FORMAT, width, height);
  897. +    return IntSize(static_cast<int>(width), static_cast<int>(height));
  898. +}
  899. +
  900. +void StreamMediaPlayerPrivateGStreamer::updateCurrentSize(IntSize& size)
  901. +{
  902. +    m_currentSize.setWidth(size.width());
  903. +    m_currentSize.setHeight(size.height());
  904. +    m_player->sizeChanged();
  905. +}
  906. +
  907. +} // namespace WebCore
  908. +
  909. +#endif // ENABLE(MEDIA_STREAM) && USE(GSTREAMER)
  910. diff --git a/Source/WebCore/platform/graphics/gstreamer/StreamMediaPlayerPrivateGStreamer.h b/Source/WebCore/platform/graphics/gstreamer/StreamMediaPlayerPrivateGStreamer.h
  911. new file mode 100644
  912. index 0000000..6c35346
  913. --- /dev/null
  914. +++ b/Source/WebCore/platform/graphics/gstreamer/StreamMediaPlayerPrivateGStreamer.h
  915. @@ -0,0 +1,153 @@
  916. +/*
  917. + *  Copyright (C) 2012 Collabora Ltd. All rights reserved.
  918. + *
  919. + *  This library is free software; you can redistribute it and/or
  920. + *  modify it under the terms of the GNU Lesser General Public
  921. + *  License as published by the Free Software Foundation; either
  922. + *  version 2 of the License, or (at your option) any later version.
  923. + *
  924. + *  This library is distributed in the hope that it will be useful,
  925. + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  926. + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  927. + *  Lesser General Public License for more details.
  928. + *
  929. + *  You should have received a copy of the GNU Lesser General Public
  930. + *  License along with this library; if not, write to the Free Software
  931. + *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  932. + */
  933. +
  934. +#ifndef StreamMediaPlayerPrivateGStreamer_h
  935. +#define StreamMediaPlayerPrivateGStreamer_h
  936. +
  937. +#if ENABLE(MEDIA_STREAM) && USE(GSTREAMER)
  938. +
  939. +#include "MediaPlayerPrivate.h"
  940. +#include "Timer.h"
  941. +#include "TimeRanges.h"
  942. +
  943. +#include <glib.h>
  944. +#include <gst/gst.h>
  945. +#include <wtf/Forward.h>
  946. +#include <wtf/Vector.h>
  947. +
  948. +typedef struct _WebKitVideoSink WebKitVideoSink;
  949. +
  950. +namespace WebCore {
  951. +
  952. +class StreamComponent;
  953. +class MediaStreamDescriptor;
  954. +class GStreamerGWorld;
  955. +
  956. +class StreamMediaPlayerPrivateGStreamer : public MediaPlayerPrivateInterface {
  957. +    friend void mediaPlayerPrivateRepaintCallback(WebKitVideoSink*, GstBuffer* buffer, StreamMediaPlayerPrivateGStreamer* playerPrivate);
  958. +public:
  959. +    ~StreamMediaPlayerPrivateGStreamer();
  960. +    static void registerMediaEngine(MediaEngineRegistrar);
  961. +
  962. +
  963. +    virtual void load(const String&);
  964. +    virtual void cancelLoad() { }
  965. +
  966. +    virtual void prepareToPlay() { }
  967. +    void play();
  968. +    void pause();
  969. +
  970. +    IntSize naturalSize() const;
  971. +
  972. +    bool hasVideo() const;
  973. +    bool hasAudio() const;
  974. +
  975. +    virtual void setVisible(bool) { }
  976. +
  977. +    virtual float duration() const { return 0; }
  978. +
  979. +    virtual float currentTime() const { return 0; }
  980. +    virtual void seek(float) { }
  981. +    virtual bool seeking() const { return false; }
  982. +
  983. +    virtual void setRate(float) { }
  984. +    virtual void setPreservesPitch(bool) { }
  985. +    virtual bool paused() const { return m_paused; }
  986. +
  987. +    void setVolume(float);
  988. +    void volumeChanged();
  989. +    void notifyPlayerOfVolumeChange();
  990. +
  991. +    bool supportsMuting() const;
  992. +    void setMuted(bool);
  993. +    void muteChanged();
  994. +    void notifyPlayerOfMute();
  995. +
  996. +
  997. +    virtual bool hasClosedCaptions() const { return false; }
  998. +    virtual void setClosedCaptionsVisible(bool) { };
  999. +
  1000. +    virtual MediaPlayer::NetworkState networkState() const { return m_networkState; }
  1001. +    virtual MediaPlayer::ReadyState readyState() const { return m_readyState; }
  1002. +
  1003. +    virtual float maxTimeSeekable() const { return 0; }
  1004. +    virtual PassRefPtr<TimeRanges> buffered() const { return TimeRanges::create(); }
  1005. +    bool didLoadingProgress() const;
  1006. +
  1007. +    virtual unsigned totalBytes() const { return 0; }
  1008. +    virtual unsigned bytesLoaded() const { return 0; }
  1009. +
  1010. +    virtual void setSize(const IntSize&) { }
  1011. +
  1012. +    void repaint();
  1013. +    virtual void paint(GraphicsContext*, const IntRect&);
  1014. +
  1015. +    virtual bool canLoadPoster() const { return false; }
  1016. +    virtual void setPoster(const String&) { }
  1017. +
  1018. +    virtual bool hasSingleSecurityOrigin() const { return true; }
  1019. +
  1020. +    bool supportsFullscreen() const;
  1021. +    PlatformMedia platformMedia() const;
  1022. +
  1023. +private:
  1024. +    StreamMediaPlayerPrivateGStreamer(MediaPlayer*);
  1025. +
  1026. +    static PassOwnPtr<MediaPlayerPrivateInterface> create(MediaPlayer* player);
  1027. +
  1028. +    static void getSupportedTypes(HashSet<String>&);
  1029. +    static MediaPlayer::SupportsType supportsType(const String& type, const String& codecs);
  1030. +    static MediaPlayer::SupportsType supportsProtocol(const String& url);
  1031. +    static bool isAvailable();
  1032. +    void createGSTAudioSinkBin();
  1033. +    void createGSTVideoSinkBin();
  1034. +    bool connectToGSTLiveStream(MediaStreamDescriptor*);
  1035. +    void loadingFailed(MediaPlayer::NetworkState error);
  1036. +    bool internalLoad();
  1037. +    void stop();
  1038. +    IntSize calculateSize();
  1039. +    void updateCurrentSize(IntSize&);
  1040. +
  1041. +private:
  1042. +     MediaPlayer* m_player;
  1043. +     GstElement* m_webkitVideoSink;
  1044. +     GstElement* m_videoSinkBin;
  1045. +     GstElement* m_audioSinkBin;
  1046. +     GstElement* m_volume;
  1047. +     GstBuffer* m_buffer;
  1048. +     MediaPlayer::NetworkState m_networkState;
  1049. +     MediaPlayer::ReadyState m_readyState;
  1050. +     bool m_paused;
  1051. +     bool m_stopped;
  1052. +     RefPtr<GStreamerGWorld> m_gstGWorld;
  1053. +     guint m_volumeTimerHandler;
  1054. +     guint m_muteTimerHandler;
  1055. +     String m_videoSourceId;
  1056. +     String m_audioSourceId;
  1057. +     RefPtr<MediaStreamDescriptor> m_streamDescriptor;
  1058. +     IntSize m_currentSize;
  1059. +     gulong m_repaintCallbackHandlerId;
  1060. +};
  1061. +
  1062. +
  1063. +
  1064. +} // namespace WebCore
  1065. +
  1066. +#endif // ENABLE(MEDIA_STREAM) && USE(GSTREAMER)
  1067. +
  1068. +#endif // StreamMediaPlayerPrivateGStreamer_h
  1069. --
  1070. 1.7.10
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement