• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef PLAYER_SINKPROVIDER_H
17 #define PLAYER_SINKPROVIDER_H
18 
19 #include <cstdint>
20 #include <memory>
21 #include <mutex>
22 #include <gst/gst.h>
23 #include "gst_mem_sink.h"
24 #include "gst_subtitle_sink.h"
25 #include "playbin_sink_provider.h"
26 #include "i_player_engine.h"
27 
28 namespace OHOS {
29 namespace Media {
30 class PlayerSinkProvider : public PlayBinSinkProvider, public NoCopyable {
31 public:
32     explicit PlayerSinkProvider(const sptr<Surface> &surface);
33     ~PlayerSinkProvider();
34 
35     SinkPtr CreateAudioSink() override;
36     SinkPtr CreateVideoSink() override;
37     SinkPtr CreateSubtitleSink() override;
38     SinkPtr GetVideoSink() override;
39 
40     void SetAppInfo(int32_t uid, int32_t pid, uint32_t tokenId) override;
41     void SetVideoScaleType(const uint32_t videoScaleType) override;
42     void SetMsgNotifier(PlayBinMsgNotifier notifier) override;
43 
44 private:
45     const sptr<Surface> GetProducerSurface() const;
46     GstElement *DoCreateAudioSink(const GstCaps *caps, const gpointer userData);
47     GstElement *DoCreateVideoSink(const GstCaps *caps, const gpointer userData);
48     GstElement *DoCreateSubtitleSink(const gpointer userData);
49     bool EnableKpiAVSyncLog() const;
50     bool EnableOptRenderDelay() const;
51     void SetFirstRenderFrameFlag(bool firstRenderFrame);
52     bool GetFirstRenderFrameFlag() const;
53     void OnFirstRenderFrame();
54     static GstFlowReturn SubtitleUpdated(GstBuffer *sample, gpointer userData);
55     void OnSubtitleUpdated(const Format &subtitle);
56     void HandleSubtitleBuffer(GstBuffer *sample, Format &subtitle);
57     static GstPadProbeReturn SinkPadProbeCb(GstPad *pad, GstPadProbeInfo *info, gpointer userData);
58     static void AudioSinkSegmentUpdatedCb();
59     static void EosCb(GstMemSink *memSink, gpointer userData);
60     static GstFlowReturn NewPrerollCb(GstMemSink *memSink, GstBuffer *sample, gpointer userData);
61     static GstFlowReturn NewSampleCb(GstMemSink *memSink, GstBuffer *sample, gpointer userData);
62     static void FirstRenderFrame(gpointer userData);
63 
64     GstElement *audioSink_ = nullptr;
65     GstElement *videoSink_ = nullptr;
66     GstElement *subtitleSink_ = nullptr;
67     GstCaps *audioCaps_ = nullptr;
68     GstCaps *videoCaps_ = nullptr;
69     sptr<Surface> producerSurface_ = nullptr;
70     uint32_t queueSize_ = 0;
71     uint32_t tokenId_ = 0;
72     int32_t uid_ = 0;
73     int32_t pid_ = 0;
74     uint32_t videoScaleType_ = 0;
75     bool firstRenderFrame_ = true;
76     PlayBinMsgNotifier notifier_ = nullptr;
77     std::mutex mutex_;
78 };
79 }
80 }
81 
82 #endif // PLAYER_SINKPROVIDER_H
83