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#pragma once
27
28#if ENABLE(VIDEO) && USE(GSTREAMER) && ENABLE(VIDEO_TRACK)
29
30#include "GStreamerCommon.h"
31#include "MainThreadNotifier.h"
32#include <gst/gst.h>
33#include <wtf/Lock.h>
34#include <wtf/text/WTFString.h>
35
36namespace WebCore {
37
38class TrackPrivateBase;
39
40class TrackPrivateBaseGStreamer {
41public:
42 virtual ~TrackPrivateBaseGStreamer();
43
44 enum TrackType {
45 Audio,
46 Video,
47 Text,
48 Unknown
49 };
50
51 GstPad* pad() const { return m_pad.get(); }
52
53 virtual void disconnect();
54
55 virtual void setActive(bool) { }
56
57 void setIndex(int index) { m_index = index; }
58
59#if GST_CHECK_VERSION(1, 10, 0)
60 GstStream* stream()
61 {
62 return m_stream.get();
63 }
64#endif
65
66protected:
67 TrackPrivateBaseGStreamer(TrackPrivateBase* owner, gint index, GRefPtr<GstPad>);
68#if GST_CHECK_VERSION(1, 10, 0)
69 TrackPrivateBaseGStreamer(TrackPrivateBase* owner, gint index, GRefPtr<GstStream>);
70#endif
71 void notifyTrackOfActiveChanged();
72 void notifyTrackOfTagsChanged();
73
74 enum MainThreadNotification {
75 ActiveChanged = 1 << 0,
76 TagsChanged = 1 << 1,
77 NewSample = 1 << 2,
78 StreamChanged = 1 << 3
79 };
80
81 Ref<MainThreadNotifier<MainThreadNotification>> m_notifier;
82 gint m_index;
83 AtomicString m_label;
84 AtomicString m_language;
85 GRefPtr<GstPad> m_pad;
86#if GST_CHECK_VERSION(1, 10, 0)
87 GRefPtr<GstStream> m_stream;
88#endif
89
90private:
91 bool getLanguageCode(GstTagList* tags, AtomicString& value);
92
93 template<class StringType>
94 bool getTag(GstTagList* tags, const gchar* tagName, StringType& value);
95
96 static void activeChangedCallback(TrackPrivateBaseGStreamer*);
97 static void tagsChangedCallback(TrackPrivateBaseGStreamer*);
98
99 void tagsChanged();
100
101 TrackPrivateBase* m_owner;
102 Lock m_tagMutex;
103 GRefPtr<GstTagList> m_tags;
104};
105
106} // namespace WebCore
107
108#endif // ENABLE(VIDEO) && USE(GSTREAMER) && ENABLE(VIDEO_TRACK)
109