• 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 GST_VDEC_BASE_H
17 #define GST_VDEC_BASE_H
18 
19 #include <vector>
20 #include <list>
21 #include <gst/video/gstvideodecoder.h>
22 #include "gst_shmem_allocator.h"
23 #include "gst_shmem_pool.h"
24 #include "i_gst_codec.h"
25 
26 #ifndef GST_API_EXPORT
27 #define GST_API_EXPORT __attribute__((visibility("default")))
28 #endif
29 
30 G_BEGIN_DECLS
31 
32 #define GST_TYPE_VDEC_BASE \
33     (gst_vdec_base_get_type())
34 #define GST_VDEC_BASE(obj) \
35     (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_VDEC_BASE, GstVdecBase))
36 #define GST_VDEC_BASE_CLASS(klass) \
37     (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_VDEC_BASE, GstVdecBaseClass))
38 #define GST_VDEC_BASE_GET_CLASS(obj) \
39     (G_TYPE_INSTANCE_GET_CLASS((obj), GST_TYPE_VDEC_BASE, GstVdecBaseClass))
40 #define GST_IS_VDEC_BASE(obj) \
41     (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_VDEC_BASE))
42 #define GST_IS_VDEC_BASE_CLASS(obj) \
43     (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_VDEC_BASE))
44 
45 typedef struct _GstVdecBase GstVdecBase;
46 typedef struct _GstVdecBaseClass GstVdecBaseClass;
47 typedef struct _GstVdecBasePort GstVdecBasePort;
48 typedef struct _DisplayRect DisplayRect;
49 typedef struct _ParseMeta ParseMeta;
50 
51 struct _GstVdecBasePort {
52     gint frame_rate;
53     gint width;
54     gint height;
55     guint min_buffer_cnt;
56     guint buffer_cnt;
57     guint buffer_size;
58     std::shared_ptr<OHOS::Media::AVSharedMemoryPool> av_shmem_pool;
59     GstShMemAllocator *allocator;
60     GstAllocationParams allocParams;
61     gint64 frame_cnt;
62     gint64 first_frame_time;
63     gint64 last_frame_time;
64     gboolean enable_dump;
65     FILE *dump_file;
66     gboolean first_frame;
67 };
68 
69 struct _DisplayRect {
70     gint x;
71     gint y;
72     gint width;
73     gint height;
74 };
75 
76 struct _ParseMeta {
77     GstMapInfo &src_info;
78     GstMapInfo &dts_info;
79     bool is_codec_data;
80     guint &copy_len;
81 };
82 
83 struct _GstVdecBase {
84     GstVideoDecoder parent;
85     std::shared_ptr<OHOS::Media::IGstCodec> decoder;
86     GMutex drain_lock;
87     GCond drain_cond;
88     gboolean draining;
89     GMutex lock;
90     gboolean flushing;
91     gboolean prepared;
92     gboolean idrframe;
93     GstVideoCodecState *input_state;
94     GstVideoCodecState *output_state;
95     std::vector<GstVideoFormat> formats;
96     GstVideoFormat format;
97     OHOS::Media::GstCompressionFormat compress_format;
98     gboolean is_codec_outbuffer;
99     GstVdecBasePort input;
100     GstVdecBasePort output;
101     gfloat frame_rate;
102     gfloat seek_frame_rate;
103     gint width;
104     gint height;
105     gint memtype;
106     guint64 usage;
107     GstBufferPool *inpool;
108     GstBufferPool *outpool;
109     guint coding_outbuf_cnt;
110     guint out_buffer_cnt;
111     guint out_buffer_max_cnt;
112     std::list<GstClockTime> pts_list;
113     GstClockTime last_pts;
114     gboolean flushing_stoping;
115     gboolean decoder_start;
116     gint stride;
117     gint stride_height;
118     gint real_stride;
119     gint real_stride_height;
120     DisplayRect rect;
121     gboolean pre_init_pool;
122     gboolean performance_mode;
123     gboolean player_scene;
124     gboolean resolution_changed;
125     GMutex format_changed_lock;
126     gboolean unsupport_format_changed;
127     GstCaps *sink_caps;
128     gboolean input_need_ashmem;
129     gboolean has_set_format;
130     gboolean player_mode;
131     gboolean metadata_mode;
132     gboolean is_support_swap_width_height;
133     gboolean codec_data_update;
134     gboolean is_free_codec_buffers;
135     gboolean is_eos_state;
136     GstBuffer *codec_data;
137 };
138 
139 struct _GstVdecBaseClass {
140     GstVideoDecoderClass parentClass;
141     std::shared_ptr<OHOS::Media::IGstCodec> (*create_codec)(GstElementClass *kclass);
142     GstBuffer *(*handle_slice_buffer)(GstVdecBase *self,
143         GstBuffer *buffer, bool &ready_push, bool is_finish);
144     void (*flush_cache_slice_buffer)(GstVdecBase *self);
145     gboolean (*input_need_copy)();
146     gboolean (*support_swap_width_height)(GstElementClass *kclass);
147     gboolean (*parser)(GstVdecBase *base, ParseMeta &meta);
148     gboolean (*bypass_frame)(GstVdecBase *base, GstVideoCodecFrame *frame);
149 };
150 
151 GST_API_EXPORT GType gst_vdec_base_get_type(void);
152 
153 G_END_DECLS
154 
155 #endif /* GST_VDEC_BASE_H */
156