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_VENC_BASE_H 17 #define GST_VENC_BASE_H 18 19 #include <queue> 20 #include <gst/video/gstvideoencoder.h> 21 #include "gst_shmem_allocator.h" 22 #include "gst_shmem_pool.h" 23 #include "i_gst_codec.h" 24 25 #ifndef GST_API_EXPORT 26 #define GST_API_EXPORT __attribute__((visibility("default"))) 27 #endif 28 29 G_BEGIN_DECLS 30 31 #define GST_TYPE_VENC_BASE \ 32 (gst_venc_base_get_type()) 33 #define GST_VENC_BASE(obj) \ 34 (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_VENC_BASE, GstVencBase)) 35 #define GST_VENC_BASE_CLASS(klass) \ 36 (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_VENC_BASE, GstVencBaseClass)) 37 #define GST_VENC_BASE_GET_CLASS(obj) \ 38 (G_TYPE_INSTANCE_GET_CLASS((obj), GST_TYPE_VENC_BASE, GstVencBaseClass)) 39 #define GST_IS_VENC_BASE(obj) \ 40 (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_VENC_BASE)) 41 #define GST_IS_VENC_BASE_CLASS(obj) \ 42 (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_VENC_BASE)) 43 44 typedef struct _GstVencBase GstVencBase; 45 typedef struct _GstVencBaseClass GstVencBaseClass; 46 typedef struct _GstVencBasePort GstVencBasePort; 47 48 struct _GstVencBasePort { 49 gint frame_rate; 50 gint width; 51 gint height; 52 guint min_buffer_cnt; 53 guint buffer_cnt; 54 guint buffer_size; 55 std::shared_ptr<OHOS::Media::AVSharedMemoryPool> av_shmem_pool; 56 GstShMemAllocator *allocator; 57 gint64 frame_cnt; 58 gint64 first_frame_time; 59 gint64 last_frame_time; 60 }; 61 62 struct _GstVencBase { 63 GstVideoEncoder parent; 64 std::shared_ptr<OHOS::Media::IGstCodec> encoder; 65 GMutex drain_lock; 66 GCond drain_cond; 67 gboolean draining; 68 GMutex lock; 69 gboolean flushing; 70 gboolean prepared; 71 gboolean useBuffers; 72 GstVideoCodecState *input_state; 73 GstVideoCodecState *output_state; 74 std::vector<GstVideoFormat> formats; 75 GstVideoFormat format; 76 OHOS::Media::GstCompressionFormat compress_format; 77 gboolean is_codec_outbuffer; 78 GstVencBasePort input; 79 GstVencBasePort output; 80 gint frame_rate; 81 gint width; 82 gint height; 83 gint nstride; 84 gint nslice_height; 85 gint memtype; 86 guint64 usage; 87 guint bitrate; 88 GstBufferPool *inpool; 89 GstBufferPool *outpool; 90 guint coding_outbuf_cnt; 91 gboolean first_in_frame; 92 gboolean first_out_frame; 93 GstClockTime last_pts; 94 GstClockTime first_frame_pts; 95 guint i_frame_interval; 96 gboolean flushing_stopping; 97 gboolean encoder_start; 98 gint bitrate_mode; 99 gint codec_quality; 100 gint i_frame_interval_new; 101 gint codec_profile; 102 gint codec_level; 103 }; 104 105 struct _GstVencBaseClass { 106 GstVideoEncoderClass parent_class; 107 std::shared_ptr<OHOS::Media::IGstCodec> (*create_codec)(GstElementClass *kclass); 108 GstCaps *(*get_caps)(GstVencBase *self, GstVideoCodecState *state); 109 }; 110 111 GST_API_EXPORT GType gst_venc_base_get_type(void); 112 113 G_END_DECLS 114 115 #endif /* GST_VENC_BASE_H */ 116