-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathGstUtils.cpp
More file actions
160 lines (150 loc) · 4.71 KB
/
GstUtils.cpp
File metadata and controls
160 lines (150 loc) · 4.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
* If not stated otherwise in this file or this component's license file the
* following copyright and licenses apply:
*
* Copyright 2024 RDK Management
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "GstUtils.h"
#include <inttypes.h>
#include "PlayerUtils.h"
/**
* @brief Get the GStreamer Caps based on the provided format and platform.
*
* @param format The format of the GStreamer stream output.
* @param platform The platform type for which the caps are being generated.
* @return GstCaps* A pointer to the GstCaps object describing the capabilities of the media stream.
*/
GstCaps* GetCaps(GstStreamOutputFormat format)
{
GstCaps * caps = NULL;
std::shared_ptr<SocInterface> socInterface = SocInterface::CreateSocInterface();
switch (format)
{
case GST_FORMAT_MPEGTS:
caps = gst_caps_new_simple ("video/mpegts",
"systemstream", G_TYPE_BOOLEAN, TRUE,
"packetsize", G_TYPE_INT, 188, NULL);
break;
case GST_FORMAT_ISO_BMFF:
caps = gst_caps_new_simple("video/quicktime", NULL, NULL);
break;
case GST_FORMAT_AUDIO_ES_MP3:
caps = gst_caps_new_simple ("audio/mpeg",
"mpegversion", G_TYPE_INT, 1, NULL);
break;
case GST_FORMAT_AUDIO_ES_AAC:
caps = gst_caps_new_simple ("audio/mpeg",
"mpegversion", G_TYPE_INT, 2,
"stream-format", G_TYPE_STRING, "adts", NULL);
break;
case GST_FORMAT_AUDIO_ES_AAC_RAW:
caps = gst_caps_new_simple ("audio/mpeg",
"mpegversion", G_TYPE_INT, 4,
"framed", G_TYPE_BOOLEAN, TRUE,
"stream-format", G_TYPE_STRING, "raw", NULL);
break;
case GST_FORMAT_AUDIO_ES_AC3:
caps = gst_caps_new_simple ("audio/x-ac3", NULL, NULL);
break;
case GST_FORMAT_AUDIO_ES_AC4:
caps = gst_caps_new_simple ("audio/x-ac4", NULL, NULL);
break;
case GST_FORMAT_SUBTITLE_TTML:
caps = gst_caps_new_simple("application/ttml+xml", NULL, NULL);
break;
case GST_FORMAT_SUBTITLE_WEBVTT:
caps = gst_caps_new_simple("text/vtt", NULL, NULL);
break;
case GST_FORMAT_SUBTITLE_MP4:
caps = gst_caps_new_simple("application/mp4", NULL, NULL);
break;
case GST_FORMAT_AUDIO_ES_ATMOS:
// Todo :: a) Test with all platforms if atmos works
// b) Test to see if x-eac3 config is enough for atmos stream.
// if x-eac3 is enough then both switch cases can be combined
caps = gst_caps_new_simple ("audio/x-eac3", NULL, NULL);
break;
case GST_FORMAT_AUDIO_ES_EC3:
caps = gst_caps_new_simple ("audio/x-eac3", NULL, NULL);
break;
case GST_FORMAT_VIDEO_ES_H264:
caps = gst_caps_new_simple ("video/x-h264", NULL, NULL);
socInterface->SetH264Caps(caps);
break;
case GST_FORMAT_VIDEO_ES_HEVC:
caps = gst_caps_new_simple("video/x-h265", NULL, NULL);
socInterface->SetHevcCaps(caps);
break;
case GST_FORMAT_VIDEO_ES_MPEG2:
caps = gst_caps_new_simple ("video/mpeg",
"mpegversion", G_TYPE_INT, 2,
"systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
break; //CID:81305 - Using break statement
case GST_FORMAT_UNKNOWN:
g_print("Unknown format %d\n", format);
break;
case GST_FORMAT_INVALID:
default:
g_print("Unsupported format %d\n", format);
break;
}
return caps;
}
/**
* @brief Create GstBuffer with data copied from input data pointer
* @param data Pointer to the data to be copied into the GstBuffer
* @param size Size of the data to be copied
* @return GstBuffer* Pointer to the created GstBuffer containing the copied data
*/
GstBuffer* CreateGstBufferWithData(gconstpointer data, gsize size)
{
GstBuffer *buffer = gst_buffer_new_and_alloc(size);
if (buffer)
{
GstMapInfo map;
if (gst_buffer_map(buffer, &map, GST_MAP_WRITE))
{
memcpy(map.data, data, size);
gst_buffer_unmap(buffer, &map);
}
else
{
g_print("Failed to map GstBuffer for writing\n");
gst_buffer_unref(buffer);
buffer = NULL;
}
}
else
{
g_print("Failed to allocate GstBuffer of size %zu\n", size);
}
return buffer;
}
/**
* @brief Initialize the GStreamer library for the player CLI.
* @param argc A pointer to the argument count.
* @param argv A pointer to the argument vector.
*/
void PlayerCliGstInit(int *argc, char ***argv)
{
gst_init(argc,argv);
}
/**
* @brief Terminate the GStreamer library for the player CLI.
*/
void PlayerCliGstTerm()
{
gst_deinit();
}