| 1 | /* |
| 2 | * Copyright (C) 2018 Metrological Group B.V. |
| 3 | * Copyright (C) 2018 Igalia S.L. All rights reserved. |
| 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 USE(GSTREAMER) && USE(LIBWEBRTC) |
| 24 | #include "GStreamerCommon.h" |
| 25 | #include "LibWebRTCMacros.h" |
| 26 | #include "webrtc/api/video/i420_buffer.h" |
| 27 | #include "webrtc/api/video/video_frame.h" |
| 28 | #include "webrtc/common_video/include/i420_buffer_pool.h" |
| 29 | #include "webrtc/common_video/include/video_frame_buffer.h" |
| 30 | #include "webrtc/rtc_base/refcountedobject.h" |
| 31 | |
| 32 | namespace WebCore { |
| 33 | |
| 34 | const GRefPtr<GstSample> GStreamerSampleFromLibWebRTCVideoFrame(const webrtc::VideoFrame&); |
| 35 | std::unique_ptr<webrtc::VideoFrame> LibWebRTCVideoFrameFromGStreamerSample(GstSample*, webrtc::VideoRotation, int64_t timestamp, int64_t renderTimeMs); |
| 36 | |
| 37 | class GStreamerVideoFrameLibWebRTC : public rtc::RefCountedObject<webrtc::VideoFrameBuffer> { |
| 38 | public: |
| 39 | GStreamerVideoFrameLibWebRTC(GstSample* sample, GstVideoInfo info) |
| 40 | : m_sample(adoptGRef(sample)) |
| 41 | , m_info(info) { } |
| 42 | |
| 43 | static rtc::scoped_refptr<webrtc::VideoFrameBuffer> create(GstSample*); |
| 44 | |
| 45 | GRefPtr<GstSample> getSample(); |
| 46 | rtc::scoped_refptr<webrtc::I420BufferInterface> ToI420() final; |
| 47 | |
| 48 | int width() const override { return GST_VIDEO_INFO_WIDTH(&m_info); } |
| 49 | int height() const override { return GST_VIDEO_INFO_HEIGHT(&m_info); } |
| 50 | |
| 51 | private: |
| 52 | webrtc::VideoFrameBuffer::Type type() const override; |
| 53 | |
| 54 | GRefPtr<GstSample> m_sample; |
| 55 | GstVideoInfo m_info; |
| 56 | webrtc::I420BufferPool m_bufferPool; |
| 57 | }; |
| 58 | } |
| 59 | |
| 60 | #endif // USE(GSTREAMER) && USE(LIBWEBRTC) |
| 61 | |