1/*
2 * Copyright (C) 2016 Metrological Group B.V.
3 * Copyright (C) 2016, 2017, 2018 Igalia S.L
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * aint with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20
21#pragma once
22
23#if ENABLE(VIDEO) && USE(GSTREAMER)
24
25#include "FloatSize.h"
26#include "GStreamerCommon.h"
27#include "MediaSample.h"
28#include <wtf/text/AtomicString.h>
29
30namespace WebCore {
31
32class MediaSampleGStreamer final : public MediaSample {
33public:
34 static Ref<MediaSampleGStreamer> create(GRefPtr<GstSample>&& sample, const FloatSize& presentationSize, const AtomicString& trackId)
35 {
36 return adoptRef(*new MediaSampleGStreamer(WTFMove(sample), presentationSize, trackId));
37 }
38
39 static Ref<MediaSampleGStreamer> createFakeSample(GstCaps*, MediaTime pts, MediaTime dts, MediaTime duration, const FloatSize& presentationSize, const AtomicString& trackId);
40
41 void applyPtsOffset(MediaTime);
42 MediaTime presentationTime() const override { return m_pts; }
43 MediaTime decodeTime() const override { return m_dts; }
44 MediaTime duration() const override { return m_duration; }
45 AtomicString trackID() const override { return m_trackId; }
46 void setTrackID(const String& trackId) override { m_trackId = trackId; }
47 size_t sizeInBytes() const override { return m_size; }
48 FloatSize presentationSize() const override { return m_presentationSize; }
49 void offsetTimestampsBy(const MediaTime&) override;
50 void setTimestamps(const MediaTime&, const MediaTime&) override { }
51 bool isDivisable() const override { return false; }
52 std::pair<RefPtr<MediaSample>, RefPtr<MediaSample>> divide(const MediaTime&) override { return { nullptr, nullptr }; }
53 Ref<MediaSample> createNonDisplayingCopy() const override;
54 SampleFlags flags() const override { return m_flags; }
55 PlatformSample platformSample() override;
56 void dump(PrintStream&) const override;
57
58private:
59 MediaSampleGStreamer(GRefPtr<GstSample>&&, const FloatSize& presentationSize, const AtomicString& trackId);
60 MediaSampleGStreamer(const FloatSize& presentationSize, const AtomicString& trackId);
61 virtual ~MediaSampleGStreamer() = default;
62
63 MediaTime m_pts;
64 MediaTime m_dts;
65 MediaTime m_duration;
66 AtomicString m_trackId;
67 size_t m_size { 0 };
68 GRefPtr<GstSample> m_sample;
69 FloatSize m_presentationSize;
70 MediaSample::SampleFlags m_flags { MediaSample::IsSync };
71};
72
73} // namespace WebCore.
74
75#endif // ENABLE(VIDEO) && USE(GSTREAMER)
76