• 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 #include "gst_venc_mpeg4.h"
17 
18 G_DEFINE_TYPE(GstVencMpeg4, gst_venc_mpeg4, GST_TYPE_VENC_BASE);
19 
20 static GstCaps *gst_venc_mpeg4_get_caps(GstVencBase *self, GstVideoCodecState *state);
21 
gst_venc_mpeg4_class_init(GstVencMpeg4Class * klass)22 static void gst_venc_mpeg4_class_init(GstVencMpeg4Class *klass)
23 {
24     GST_DEBUG_OBJECT(klass, "Init mpeg4 class");
25     g_return_if_fail(klass != nullptr);
26     GstElementClass *element_class = GST_ELEMENT_CLASS(klass);
27     GstVencBaseClass *base_class = GST_VENC_BASE_CLASS(klass);
28     base_class->get_caps = gst_venc_mpeg4_get_caps;
29 
30     gst_element_class_set_static_metadata(element_class,
31         "Hardware Driver Interface H.265 Video Encoder",
32         "Codec/Encoder/Video/Hardware",
33         "Decode H.265 video streams",
34         "OpenHarmony");
35     const gchar *src_caps_string = "video/mpeg, "
36         "mpegversion=(int) 4, "
37         "systemstream=(boolean) false, "
38         "width=(int) [1,MAX], " "height=(int) [1,MAX]";
39     GstCaps *src_caps = gst_caps_from_string(src_caps_string);
40 
41     if (src_caps != nullptr) {
42         GstPadTemplate *src_templ = gst_pad_template_new("src", GST_PAD_SRC, GST_PAD_ALWAYS, src_caps);
43         gst_element_class_add_pad_template(element_class, src_templ);
44         gst_caps_unref(src_caps);
45     }
46 }
47 
gst_venc_mpeg4_init(GstVencMpeg4 * self)48 static void gst_venc_mpeg4_init(GstVencMpeg4 *self)
49 {
50     (void)self;
51 }
52 
gst_venc_mpeg4_get_caps(GstVencBase * self,GstVideoCodecState * state)53 static GstCaps *gst_venc_mpeg4_get_caps(GstVencBase *self, GstVideoCodecState *state)
54 {
55     (void)state;
56     g_return_val_if_fail(self != nullptr, nullptr);
57     GstCaps *caps = gst_caps_new_simple("video/mpeg",
58         "mpegversion", G_TYPE_INT, 4,
59         "systemstream", G_TYPE_BOOLEAN, FALSE,
60         "width", G_TYPE_INT, self->width,
61         "height", G_TYPE_INT, self->height, nullptr);
62     return caps;
63 }