| 1 | /* |
| 2 | * Copyright (C) 2013 Cable Television Laboratories, Inc. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in the |
| 12 | * documentation and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY |
| 15 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 16 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 17 | * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| 18 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 19 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 20 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
| 21 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 23 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #include "config.h" |
| 27 | #if ENABLE(VIDEO) && USE(GSTREAMER) && ENABLE(VIDEO_TRACK) |
| 28 | |
| 29 | #include "TextSinkGStreamer.h" |
| 30 | |
| 31 | GST_DEBUG_CATEGORY_STATIC(webkitTextSinkDebug); |
| 32 | #define GST_CAT_DEFAULT webkitTextSinkDebug |
| 33 | |
| 34 | #define webkit_text_sink_parent_class parent_class |
| 35 | G_DEFINE_TYPE_WITH_CODE(WebKitTextSink, webkit_text_sink, GST_TYPE_APP_SINK, |
| 36 | GST_DEBUG_CATEGORY_INIT(webkitTextSinkDebug, "webkittextsink" , 0, |
| 37 | "webkit text sink" )); |
| 38 | |
| 39 | enum { |
| 40 | Prop0, |
| 41 | PropSync, |
| 42 | PropLast |
| 43 | }; |
| 44 | |
| 45 | static void webkit_text_sink_init(WebKitTextSink* sink) |
| 46 | { |
| 47 | /* We want to get cues as quickly as possible so WebKit has time to handle them, |
| 48 | * and we don't want cues to block when they come in the wrong order. */ |
| 49 | gst_base_sink_set_sync(GST_BASE_SINK(sink), false); |
| 50 | } |
| 51 | |
| 52 | static void webkitTextSinkGetProperty(GObject*, guint /* propertyId */, |
| 53 | GValue*, GParamSpec*) |
| 54 | { |
| 55 | /* Do nothing with PropSync */ |
| 56 | } |
| 57 | |
| 58 | static void webkitTextSinkSetProperty(GObject*, guint /* propertyId */, |
| 59 | const GValue*, GParamSpec*) |
| 60 | { |
| 61 | /* Do nothing with PropSync */ |
| 62 | } |
| 63 | |
| 64 | static gboolean webkitTextSinkQuery(GstElement *element, GstQuery *query) |
| 65 | { |
| 66 | switch (GST_QUERY_TYPE(query)) { |
| 67 | case GST_QUERY_DURATION: |
| 68 | case GST_QUERY_POSITION: |
| 69 | /* Ignore duration and position because we don't want the seek bar to be |
| 70 | * based on where the cues are. */ |
| 71 | return false; |
| 72 | default: |
| 73 | WebKitTextSink* sink = WEBKIT_TEXT_SINK(element); |
| 74 | GstElement* parent = GST_ELEMENT(&sink->parent); |
| 75 | return GST_ELEMENT_CLASS(parent_class)->query(parent, query); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | static void webkit_text_sink_class_init(WebKitTextSinkClass* klass) |
| 80 | { |
| 81 | GObjectClass* gobjectClass = G_OBJECT_CLASS(klass); |
| 82 | GstElementClass* elementClass = GST_ELEMENT_CLASS(klass); |
| 83 | |
| 84 | gst_element_class_set_metadata(elementClass, "WebKit text sink" , "Generic" , |
| 85 | "An appsink that ignores the sync property and position and duration queries" , |
| 86 | "Brendan Long <b.long@cablelabs.com>" ); |
| 87 | |
| 88 | gobjectClass->get_property = GST_DEBUG_FUNCPTR(webkitTextSinkGetProperty); |
| 89 | gobjectClass->set_property = GST_DEBUG_FUNCPTR(webkitTextSinkSetProperty); |
| 90 | elementClass->query = GST_DEBUG_FUNCPTR(webkitTextSinkQuery); |
| 91 | |
| 92 | /* Override "sync" so playsink doesn't mess with our appsink */ |
| 93 | g_object_class_override_property(gobjectClass, PropSync, "sync" ); |
| 94 | } |
| 95 | |
| 96 | GstElement* webkitTextSinkNew() |
| 97 | { |
| 98 | return GST_ELEMENT(g_object_new(WEBKIT_TYPE_TEXT_SINK, nullptr)); |
| 99 | } |
| 100 | |
| 101 | #endif // ENABLE(VIDEO) && USE(GSTREAMER) && ENABLE(VIDEO_TRACK) |
| 102 | |