1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680
|
/*
* Copyright (C) 2007, 2009 Apple Inc. All rights reserved.
* Copyright (C) 2007 Collabora Ltd. All rights reserved.
* Copyright (C) 2007 Alp Toker <alp@atoker.com>
* Copyright (C) 2009 Gustavo Noronha Silva <gns@gnome.org>
* Copyright (C) 2009, 2010 Igalia S.L
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* aint with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "MediaPlayerPrivateGStreamerBase.h"
#if ENABLE(VIDEO) && USE(GSTREAMER)
#include "ColorSpace.h"
#include "FullscreenVideoControllerGStreamer.h"
#include "GStreamerGWorld.h"
#include "GStreamerUtilities.h"
#include "GStreamerVersioning.h"
#include "GraphicsContext.h"
#include "GraphicsTypes.h"
#include "ImageGStreamer.h"
#include "ImageOrientation.h"
#include "IntRect.h"
#include "Logging.h"
#include "MediaPlayer.h"
#include "NotImplemented.h"
#include "VideoSinkGStreamer.h"
#include "WebKitWebSourceGStreamer.h"
#include <gst/gst.h>
#include <gst/video/video.h>
#include <wtf/text/CString.h>
#ifdef GST_API_VERSION_1
#include <gst/audio/streamvolume.h>
#else
#include <gst/interfaces/streamvolume.h>
#endif
#if GST_CHECK_VERSION(1, 1, 0) && USE(ACCELERATED_COMPOSITING) && USE(TEXTURE_MAPPER_GL) && !USE(COORDINATED_GRAPHICS)
#include "TextureMapperGL.h"
#endif
GST_DEBUG_CATEGORY(webkit_media_player_debug);
#define GST_CAT_DEFAULT webkit_media_player_debug
using namespace std;
namespace WebCore {
static int greatestCommonDivisor(int a, int b)
{
while (b) {
int temp = a;
a = b;
b = temp % b;
}
return ABS(a);
}
static void mediaPlayerPrivateVolumeChangedCallback(GObject*, GParamSpec*, MediaPlayerPrivateGStreamerBase* player)
{
// This is called when m_volumeElement receives the notify::volume signal.
LOG_MEDIA_MESSAGE("Volume changed to: %f", player->volume());
player->volumeChanged();
}
static gboolean mediaPlayerPrivateVolumeChangeTimeoutCallback(MediaPlayerPrivateGStreamerBase* player)
{
// This is the callback of the timeout source created in ::volumeChanged.
player->notifyPlayerOfVolumeChange();
return FALSE;
}
static void mediaPlayerPrivateMuteChangedCallback(GObject*, GParamSpec*, MediaPlayerPrivateGStreamerBase* player)
{
// This is called when m_volumeElement receives the notify::mute signal.
player->muteChanged();
}
static gboolean mediaPlayerPrivateMuteChangeTimeoutCallback(MediaPlayerPrivateGStreamerBase* player)
{
// This is the callback of the timeout source created in ::muteChanged.
player->notifyPlayerOfMute();
return FALSE;
}
static void mediaPlayerPrivateRepaintCallback(WebKitVideoSink*, GstBuffer *buffer, MediaPlayerPrivateGStreamerBase* playerPrivate)
{
playerPrivate->triggerRepaint(buffer);
}
MediaPlayerPrivateGStreamerBase::MediaPlayerPrivateGStreamerBase(MediaPlayer* player)
: m_player(player)
, m_fpsSink(0)
, m_readyState(MediaPlayer::HaveNothing)
, m_networkState(MediaPlayer::Empty)
, m_buffer(0)
, m_volumeTimerHandler(0)
, m_muteTimerHandler(0)
, m_repaintHandler(0)
, m_volumeSignalHandler(0)
, m_muteSignalHandler(0)
{
#if GLIB_CHECK_VERSION(2, 31, 0)
m_bufferMutex = WTF::fastNew<GMutex>();
g_mutex_init(m_bufferMutex);
#else
m_bufferMutex = g_mutex_new();
#endif
}
MediaPlayerPrivateGStreamerBase::~MediaPlayerPrivateGStreamerBase()
{
g_signal_handler_disconnect(m_webkitVideoSink.get(), m_repaintHandler);
#if GLIB_CHECK_VERSION(2, 31, 0)
g_mutex_clear(m_bufferMutex);
WTF::fastDelete(m_bufferMutex);
#else
g_mutex_free(m_bufferMutex);
#endif
if (m_buffer)
gst_buffer_unref(m_buffer);
m_buffer = 0;
m_player = 0;
if (m_muteTimerHandler)
g_source_remove(m_muteTimerHandler);
if (m_volumeTimerHandler)
g_source_remove(m_volumeTimerHandler);
if (m_volumeSignalHandler) {
g_signal_handler_disconnect(m_volumeElement.get(), m_volumeSignalHandler);
m_volumeSignalHandler = 0;
}
if (m_muteSignalHandler) {
g_signal_handler_disconnect(m_volumeElement.get(), m_muteSignalHandler);
m_muteSignalHandler = 0;
}
#if USE(NATIVE_FULLSCREEN_VIDEO)
if (m_fullscreenVideoController)
exitFullscreen();
#endif
}
// Returns the size of the video
IntSize MediaPlayerPrivateGStreamerBase::naturalSize() const
{
if (!hasVideo())
return IntSize();
if (!m_videoSize.isEmpty())
return m_videoSize;
#ifdef GST_API_VERSION_1
GRefPtr<GstCaps> caps = currentVideoSinkCaps();
#else
g_mutex_lock(m_bufferMutex);
GRefPtr<GstCaps> caps = m_buffer ? GST_BUFFER_CAPS(m_buffer) : 0;
g_mutex_unlock(m_bufferMutex);
#endif
if (!caps)
return IntSize();
// TODO: handle possible clean aperture data. See
// https://bugzilla.gnome.org/show_bug.cgi?id=596571
// TODO: handle possible transformation matrix. See
// https://bugzilla.gnome.org/show_bug.cgi?id=596326
// Get the video PAR and original size, if this fails the
// video-sink has likely not yet negotiated its caps.
int pixelAspectRatioNumerator, pixelAspectRatioDenominator, stride;
IntSize originalSize;
GstVideoFormat format;
if (!getVideoSizeAndFormatFromCaps(caps.get(), originalSize, format, pixelAspectRatioNumerator, pixelAspectRatioDenominator, stride))
return IntSize();
LOG_MEDIA_MESSAGE("Original video size: %dx%d", originalSize.width(), originalSize.height());
LOG_MEDIA_MESSAGE("Pixel aspect ratio: %d/%d", pixelAspectRatioNumerator, pixelAspectRatioDenominator);
// Calculate DAR based on PAR and video size.
int displayWidth = originalSize.width() * pixelAspectRatioNumerator;
int displayHeight = originalSize.height() * pixelAspectRatioDenominator;
// Divide display width and height by their GCD to avoid possible overflows.
int displayAspectRatioGCD = greatestCommonDivisor(displayWidth, displayHeight);
displayWidth /= displayAspectRatioGCD;
displayHeight /= displayAspectRatioGCD;
// Apply DAR to original video size. This is the same behavior as in xvimagesink's setcaps function.
guint64 width = 0, height = 0;
if (!(originalSize.height() % displayHeight)) {
LOG_MEDIA_MESSAGE("Keeping video original height");
width = gst_util_uint64_scale_int(originalSize.height(), displayWidth, displayHeight);
height = static_cast<guint64>(originalSize.height());
} else if (!(originalSize.width() % displayWidth)) {
LOG_MEDIA_MESSAGE("Keeping video original width");
height = gst_util_uint64_scale_int(originalSize.width(), displayHeight, displayWidth);
width = static_cast<guint64>(originalSize.width());
} else {
LOG_MEDIA_MESSAGE("Approximating while keeping original video height");
width = gst_util_uint64_scale_int(originalSize.height(), displayWidth, displayHeight);
height = static_cast<guint64>(originalSize.height());
}
LOG_MEDIA_MESSAGE("Natural size: %" G_GUINT64_FORMAT "x%" G_GUINT64_FORMAT, width, height);
m_videoSize = IntSize(static_cast<int>(width), static_cast<int>(height));
return m_videoSize;
}
void MediaPlayerPrivateGStreamerBase::setVolume(float volume)
{
if (!m_volumeElement)
return;
LOG_MEDIA_MESSAGE("Setting volume: %f", volume);
gst_stream_volume_set_volume(m_volumeElement.get(), GST_STREAM_VOLUME_FORMAT_CUBIC, static_cast<double>(volume));
}
float MediaPlayerPrivateGStreamerBase::volume() const
{
if (!m_volumeElement)
return 0;
return gst_stream_volume_get_volume(m_volumeElement.get(), GST_STREAM_VOLUME_FORMAT_CUBIC);
}
void MediaPlayerPrivateGStreamerBase::notifyPlayerOfVolumeChange()
{
m_volumeTimerHandler = 0;
if (!m_player || !m_volumeElement)
return;
double volume;
volume = gst_stream_volume_get_volume(m_volumeElement.get(), GST_STREAM_VOLUME_FORMAT_CUBIC);
// get_volume() can return values superior to 1.0 if the user
// applies software user gain via third party application (GNOME
// volume control for instance).
volume = CLAMP(volume, 0.0, 1.0);
m_player->volumeChanged(static_cast<float>(volume));
}
void MediaPlayerPrivateGStreamerBase::volumeChanged()
{
if (m_volumeTimerHandler)
g_source_remove(m_volumeTimerHandler);
m_volumeTimerHandler = g_timeout_add(0, reinterpret_cast<GSourceFunc>(mediaPlayerPrivateVolumeChangeTimeoutCallback), this);
}
MediaPlayer::NetworkState MediaPlayerPrivateGStreamerBase::networkState() const
{
return m_networkState;
}
MediaPlayer::ReadyState MediaPlayerPrivateGStreamerBase::readyState() const
{
return m_readyState;
}
void MediaPlayerPrivateGStreamerBase::sizeChanged()
{
notImplemented();
}
void MediaPlayerPrivateGStreamerBase::setMuted(bool muted)
{
if (!m_volumeElement)
return;
g_object_set(m_volumeElement.get(), "mute", muted, NULL);
}
bool MediaPlayerPrivateGStreamerBase::muted() const
{
if (!m_volumeElement)
return false;
bool muted;
g_object_get(m_volumeElement.get(), "mute", &muted, NULL);
return muted;
}
void MediaPlayerPrivateGStreamerBase::notifyPlayerOfMute()
{
m_muteTimerHandler = 0;
if (!m_player || !m_volumeElement)
return;
gboolean muted;
g_object_get(m_volumeElement.get(), "mute", &muted, NULL);
m_player->muteChanged(static_cast<bool>(muted));
}
void MediaPlayerPrivateGStreamerBase::muteChanged()
{
if (m_muteTimerHandler)
g_source_remove(m_muteTimerHandler);
m_muteTimerHandler = g_timeout_add(0, reinterpret_cast<GSourceFunc>(mediaPlayerPrivateMuteChangeTimeoutCallback), this);
}
#if USE(ACCELERATED_COMPOSITING) && USE(TEXTURE_MAPPER_GL) && !USE(COORDINATED_GRAPHICS)
PassRefPtr<BitmapTexture> MediaPlayerPrivateGStreamerBase::updateTexture(TextureMapper* textureMapper)
{
g_mutex_lock(m_bufferMutex);
if (!m_buffer) {
g_mutex_unlock(m_bufferMutex);
return 0;
}
const void* srcData = 0;
#ifdef GST_API_VERSION_1
GRefPtr<GstCaps> caps = currentVideoSinkCaps();
#else
GRefPtr<GstCaps> caps = GST_BUFFER_CAPS(m_buffer);
#endif
if (!caps) {
g_mutex_unlock(m_bufferMutex);
return 0;
}
IntSize size;
GstVideoFormat format;
int pixelAspectRatioNumerator, pixelAspectRatioDenominator, stride;
if (!getVideoSizeAndFormatFromCaps(caps.get(), size, format, pixelAspectRatioNumerator, pixelAspectRatioDenominator, stride)) {
g_mutex_unlock(m_bufferMutex);
return 0;
}
RefPtr<BitmapTexture> texture = textureMapper->acquireTextureFromPool(size);
#if GST_CHECK_VERSION(1, 1, 0)
GstVideoGLTextureUploadMeta* meta;
if ((meta = gst_buffer_get_video_gl_texture_upload_meta(m_buffer))) {
if (meta->n_textures == 1) { // BRGx & BGRA formats use only one texture.
const BitmapTextureGL* textureGL = static_cast<const BitmapTextureGL*>(texture.get());
guint ids[4] = { textureGL->id(), 0, 0, 0 };
if (gst_video_gl_texture_upload_meta_upload(meta, ids)) {
g_mutex_unlock(m_bufferMutex);
return texture;
}
}
}
#endif
#ifdef GST_API_VERSION_1
GstMapInfo srcInfo;
gst_buffer_map(m_buffer, &srcInfo, GST_MAP_READ);
srcData = srcInfo.data;
#else
srcData = GST_BUFFER_DATA(m_buffer);
#endif
texture->updateContents(srcData, WebCore::IntRect(WebCore::IntPoint(0, 0), size), WebCore::IntPoint(0, 0), stride, BitmapTexture::UpdateCannotModifyOriginalImageData);
#ifdef GST_API_VERSION_1
gst_buffer_unmap(m_buffer, &srcInfo);
#endif
g_mutex_unlock(m_bufferMutex);
return texture;
}
#endif
void MediaPlayerPrivateGStreamerBase::triggerRepaint(GstBuffer* buffer)
{
g_return_if_fail(GST_IS_BUFFER(buffer));
g_mutex_lock(m_bufferMutex);
gst_buffer_replace(&m_buffer, buffer);
g_mutex_unlock(m_bufferMutex);
#if USE(ACCELERATED_COMPOSITING) && USE(TEXTURE_MAPPER_GL) && !USE(COORDINATED_GRAPHICS)
if (supportsAcceleratedRendering() && m_player->mediaPlayerClient()->mediaPlayerRenderingCanBeAccelerated(m_player) && client()) {
client()->setPlatformLayerNeedsDisplay();
return;
}
#endif
m_player->repaint();
}
void MediaPlayerPrivateGStreamerBase::setSize(const IntSize& size)
{
m_size = size;
}
void MediaPlayerPrivateGStreamerBase::paint(GraphicsContext* context, const IntRect& rect)
{
#if USE(ACCELERATED_COMPOSITING) && USE(TEXTURE_MAPPER_GL) && !USE(COORDINATED_GRAPHICS)
if (client())
return;
#endif
if (context->paintingDisabled())
return;
if (!m_player->visible())
return;
g_mutex_lock(m_bufferMutex);
if (!m_buffer) {
g_mutex_unlock(m_bufferMutex);
return;
}
#ifdef GST_API_VERSION_1
GRefPtr<GstCaps> caps = currentVideoSinkCaps();
#else
GRefPtr<GstCaps> caps = GST_BUFFER_CAPS(m_buffer);
#endif
if (!caps) {
g_mutex_unlock(m_bufferMutex);
return;
}
RefPtr<ImageGStreamer> gstImage = ImageGStreamer::createImage(m_buffer, caps.get());
if (!gstImage || !gstImage->image().get()) {
g_mutex_unlock(m_bufferMutex);
return;
}
context->drawImage(reinterpret_cast<Image*>(gstImage->image().get()), ColorSpaceSRGB,
rect, gstImage->rect(), CompositeCopy, DoNotRespectImageOrientation, true);
g_mutex_unlock(m_bufferMutex);
}
#if USE(ACCELERATED_COMPOSITING) && USE(TEXTURE_MAPPER_GL) && !USE(COORDINATED_GRAPHICS)
void MediaPlayerPrivateGStreamerBase::paintToTextureMapper(TextureMapper* textureMapper, const FloatRect& targetRect, const TransformationMatrix& matrix, float opacity)
{
if (textureMapper->accelerationMode() != TextureMapper::OpenGLMode)
return;
if (!m_player->visible())
return;
RefPtr<BitmapTexture> texture = updateTexture(textureMapper);
if (texture)
textureMapper->drawTexture(*texture.get(), targetRect, matrix, opacity);
}
#endif
#if USE(NATIVE_FULLSCREEN_VIDEO)
void MediaPlayerPrivateGStreamerBase::enterFullscreen()
{
ASSERT(!m_fullscreenVideoController);
m_fullscreenVideoController = FullscreenVideoControllerGStreamer::create(this);
if (m_fullscreenVideoController)
m_fullscreenVideoController->enterFullscreen();
}
void MediaPlayerPrivateGStreamerBase::exitFullscreen()
{
if (!m_fullscreenVideoController)
return;
m_fullscreenVideoController->exitFullscreen();
m_fullscreenVideoController.release();
}
#endif
bool MediaPlayerPrivateGStreamerBase::supportsFullscreen() const
{
return true;
}
PlatformMedia MediaPlayerPrivateGStreamerBase::platformMedia() const
{
#if USE(NATIVE_FULLSCREEN_VIDEO)
PlatformMedia p;
p.type = PlatformMedia::GStreamerGWorldType;
p.media.gstreamerGWorld = m_gstGWorld.get();
return p;
#else
return NoPlatformMedia;
#endif
}
MediaPlayer::MovieLoadType MediaPlayerPrivateGStreamerBase::movieLoadType() const
{
if (m_readyState == MediaPlayer::HaveNothing)
return MediaPlayer::Unknown;
if (isLiveStream())
return MediaPlayer::LiveStream;
return MediaPlayer::Download;
}
GRefPtr<GstCaps> MediaPlayerPrivateGStreamerBase::currentVideoSinkCaps() const
{
if (!m_webkitVideoSink)
return 0;
GstCaps* currentCaps = 0;
g_object_get(G_OBJECT(m_webkitVideoSink.get()), "current-caps", ¤tCaps, NULL);
return adoptGRef(currentCaps);
}
// This function creates and initializes some internal variables, and returns a
// pointer to the element that should receive the data flow first
GstElement* MediaPlayerPrivateGStreamerBase::createVideoSink(GstElement* pipeline)
{
if (!initializeGStreamer())
return 0;
#if USE(NATIVE_FULLSCREEN_VIDEO)
m_gstGWorld = GStreamerGWorld::createGWorld(pipeline);
m_webkitVideoSink = webkitVideoSinkNew(m_gstGWorld.get());
#else
UNUSED_PARAM(pipeline);
m_webkitVideoSink = webkitVideoSinkNew();
#endif
m_repaintHandler = g_signal_connect(m_webkitVideoSink.get(), "repaint-requested", G_CALLBACK(mediaPlayerPrivateRepaintCallback), this);
#if USE(NATIVE_FULLSCREEN_VIDEO)
// Build a new video sink consisting of a bin containing a tee
// (meant to distribute data to multiple video sinks) and our
// internal video sink. For fullscreen we create an autovideosink
// and initially block the data flow towards it and configure it
m_videoSinkBin = gst_bin_new("video-sink");
GstElement* videoTee = gst_element_factory_make("tee", "videoTee");
GstElement* queue = gst_element_factory_make("queue", 0);
#ifdef GST_API_VERSION_1
GRefPtr<GstPad> sinkPad = adoptGRef(gst_element_get_static_pad(videoTee, "sink"));
GST_OBJECT_FLAG_SET(GST_OBJECT(sinkPad.get()), GST_PAD_FLAG_PROXY_ALLOCATION);
#endif
gst_bin_add_many(GST_BIN(m_videoSinkBin.get()), videoTee, queue, NULL);
// Link a new src pad from tee to queue1.
gst_element_link_pads_full(videoTee, 0, queue, "sink", GST_PAD_LINK_CHECK_NOTHING);
#endif
GstElement* actualVideoSink = 0;
m_fpsSink = gst_element_factory_make("fpsdisplaysink", "sink");
if (m_fpsSink) {
// The verbose property has been added in -bad 0.10.22. Making
// this whole code depend on it because we don't want
// fpsdiplaysink to spit data on stdout.
GstElementFactory* factory = GST_ELEMENT_FACTORY(GST_ELEMENT_GET_CLASS(m_fpsSink)->elementfactory);
if (gst_plugin_feature_check_version(GST_PLUGIN_FEATURE(factory), 0, 10, 22)) {
g_object_set(m_fpsSink, "silent", TRUE , NULL);
// Turn off text overlay unless logging is enabled.
#if LOG_DISABLED
g_object_set(m_fpsSink, "text-overlay", FALSE , NULL);
#else
WTFLogChannel* channel = getChannelFromName("Media");
if (channel->state != WTFLogChannelOn)
g_object_set(m_fpsSink, "text-overlay", FALSE , NULL);
#endif // LOG_DISABLED
if (g_object_class_find_property(G_OBJECT_GET_CLASS(m_fpsSink), "video-sink")) {
g_object_set(m_fpsSink, "video-sink", m_webkitVideoSink.get(), NULL);
#if USE(NATIVE_FULLSCREEN_VIDEO)
gst_bin_add(GST_BIN(m_videoSinkBin.get()), m_fpsSink);
#endif
actualVideoSink = m_fpsSink;
} else
m_fpsSink = 0;
} else
m_fpsSink = 0;
}
if (!m_fpsSink) {
#if USE(NATIVE_FULLSCREEN_VIDEO)
gst_bin_add(GST_BIN(m_videoSinkBin.get()), m_webkitVideoSink.get());
#endif
actualVideoSink = m_webkitVideoSink.get();
}
ASSERT(actualVideoSink);
#if USE(NATIVE_FULLSCREEN_VIDEO)
// Faster elements linking.
gst_element_link_pads_full(queue, "src", actualVideoSink, "sink", GST_PAD_LINK_CHECK_NOTHING);
// Add a ghostpad to the bin so it can proxy to tee.
GRefPtr<GstPad> pad = adoptGRef(gst_element_get_static_pad(videoTee, "sink"));
gst_element_add_pad(m_videoSinkBin.get(), gst_ghost_pad_new("sink", pad.get()));
// Set the bin as video sink of playbin.
return m_videoSinkBin.get();
#else
return actualVideoSink;
#endif
}
void MediaPlayerPrivateGStreamerBase::setStreamVolumeElement(GstStreamVolume* volume)
{
ASSERT(!m_volumeElement);
m_volumeElement = volume;
// We don't set the initial volume because we trust the sink to keep it for us. See
// https://bugs.webkit.org/show_bug.cgi?id=118974 for more information.
if (!m_player->platformVolumeConfigurationRequired()) {
LOG_MEDIA_MESSAGE("Setting stream volume to %f", m_player->volume());
g_object_set(m_volumeElement.get(), "volume", m_player->volume(), NULL);
} else
LOG_MEDIA_MESSAGE("Not setting stream volume, trusting system one");
LOG_MEDIA_MESSAGE("Setting stream muted %d", m_player->muted());
g_object_set(m_volumeElement.get(), "mute", m_player->muted(), NULL);
m_volumeSignalHandler = g_signal_connect(m_volumeElement.get(), "notify::volume", G_CALLBACK(mediaPlayerPrivateVolumeChangedCallback), this);
m_muteSignalHandler = g_signal_connect(m_volumeElement.get(), "notify::mute", G_CALLBACK(mediaPlayerPrivateMuteChangedCallback), this);
}
unsigned MediaPlayerPrivateGStreamerBase::decodedFrameCount() const
{
guint64 decodedFrames = 0;
if (m_fpsSink)
g_object_get(m_fpsSink, "frames-rendered", &decodedFrames, NULL);
return static_cast<unsigned>(decodedFrames);
}
unsigned MediaPlayerPrivateGStreamerBase::droppedFrameCount() const
{
guint64 framesDropped = 0;
if (m_fpsSink)
g_object_get(m_fpsSink, "frames-dropped", &framesDropped, NULL);
return static_cast<unsigned>(framesDropped);
}
unsigned MediaPlayerPrivateGStreamerBase::audioDecodedByteCount() const
{
GstQuery* query = gst_query_new_position(GST_FORMAT_BYTES);
gint64 position = 0;
if (audioSink() && gst_element_query(audioSink(), query))
gst_query_parse_position(query, 0, &position);
gst_query_unref(query);
return static_cast<unsigned>(position);
}
unsigned MediaPlayerPrivateGStreamerBase::videoDecodedByteCount() const
{
GstQuery* query = gst_query_new_position(GST_FORMAT_BYTES);
gint64 position = 0;
if (gst_element_query(m_webkitVideoSink.get(), query))
gst_query_parse_position(query, 0, &position);
gst_query_unref(query);
return static_cast<unsigned>(position);
}
}
#endif // USE(GSTREAMER)
|