2010-08-13 15:27:52 +00:00
|
|
|
/* GStreamer encoding profiles library
|
|
|
|
* Copyright (C) 2009-2010 Edward Hervey <edward.hervey@collabora.co.uk>
|
|
|
|
* (C) 2009-2010 Nokia Corporation
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-03 23:05:09 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2010-08-13 15:27:52 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:encoding-profile
|
2017-01-23 19:36:11 +00:00
|
|
|
* @title: GstEncodingProfile
|
2010-08-13 15:27:52 +00:00
|
|
|
* @short_description: Encoding profile library
|
2018-10-22 06:17:24 +00:00
|
|
|
* @symbols:
|
|
|
|
* - GstEncodingProfile
|
|
|
|
* - GstEncodingContainerProfile
|
|
|
|
* - GstEncodingVideoProfile
|
|
|
|
* - GstEncodingAudioProfile
|
2010-08-13 15:27:52 +00:00
|
|
|
*
|
|
|
|
* Functions to create and handle encoding profiles.
|
2016-12-16 14:11:57 +00:00
|
|
|
*
|
2020-11-20 21:35:49 +00:00
|
|
|
* Encoding profiles describe the media types and settings one wishes to use for
|
|
|
|
* an encoding process. The top-level profiles are commonly
|
2011-01-04 20:20:34 +00:00
|
|
|
* #GstEncodingContainerProfile(s) (which contains a user-readable name and
|
|
|
|
* description along with which container format to use). These, in turn,
|
|
|
|
* reference one or more #GstEncodingProfile(s) which indicate which encoding
|
|
|
|
* format should be used on each individual streams.
|
2016-12-16 14:11:57 +00:00
|
|
|
*
|
2020-11-20 21:35:49 +00:00
|
|
|
* #GstEncodingProfile(s) can be provided to the 'encodebin' element, which will
|
|
|
|
* take care of selecting and setting up the required elements to produce an
|
|
|
|
* output stream conforming to the specifications of the profile.
|
2016-12-16 14:11:57 +00:00
|
|
|
*
|
2020-11-20 21:35:49 +00:00
|
|
|
* The encoding profiles do not necessarily specify which #GstElement to use for
|
|
|
|
* the various encoding and muxing steps, as they allow to specifying the format
|
|
|
|
* one wishes to use.
|
2016-12-16 14:11:57 +00:00
|
|
|
*
|
2020-11-20 21:35:49 +00:00
|
|
|
* Encoding profiles can be created at runtime by the application or loaded from
|
|
|
|
* (and saved to) file using the #GstEncodingTarget API.
|
2016-12-16 14:11:57 +00:00
|
|
|
*
|
2020-11-20 21:35:49 +00:00
|
|
|
* ## The encoding profile serialization format
|
2016-12-16 14:11:57 +00:00
|
|
|
*
|
2020-11-20 21:35:49 +00:00
|
|
|
* Encoding profiles can be serialized to be used in the command line tools or
|
|
|
|
* to set it on other other #GObject-s using #gst_util_set_object_arg for
|
|
|
|
* example.
|
2016-12-23 17:23:48 +00:00
|
|
|
*
|
2020-11-20 21:35:49 +00:00
|
|
|
* The serialization format aims at being simple to understand although flexible
|
|
|
|
* enough to describe any possible encoding profile. There are several ways to
|
|
|
|
* describe the profile depending on the context but the general idea is that it
|
|
|
|
* is a colon separated list of EncodingProfiles descriptions, the first one
|
|
|
|
* needs to describe a #GstEncodingContainerProfile and the following ones
|
|
|
|
* describe elementary streams.
|
|
|
|
*
|
|
|
|
* ### Using encoders and muxer element factory name
|
2016-12-23 17:23:48 +00:00
|
|
|
*
|
2019-08-30 21:16:35 +00:00
|
|
|
* ```
|
2016-12-23 17:23:48 +00:00
|
|
|
* muxer_factory_name:video_encoder_factory_name:audio_encoder_factory_name
|
2019-08-30 21:16:35 +00:00
|
|
|
* ```
|
2016-12-23 17:23:48 +00:00
|
|
|
*
|
|
|
|
* For example to encode a stream into a WebM container, with an OGG audio
|
2020-11-20 21:35:49 +00:00
|
|
|
* stream and a VP8 video stream, the serialized #GstEncodingProfile looks like:
|
2016-12-23 17:23:48 +00:00
|
|
|
*
|
2019-08-30 21:16:35 +00:00
|
|
|
* ```
|
2016-12-23 17:23:48 +00:00
|
|
|
* webmmux:vp8enc:vorbisenc
|
2019-08-30 21:16:35 +00:00
|
|
|
* ```
|
2016-12-23 17:23:48 +00:00
|
|
|
*
|
2020-11-20 21:35:49 +00:00
|
|
|
* ### Define the encoding profile in a generic way using caps:
|
2016-12-16 14:11:57 +00:00
|
|
|
*
|
2019-08-30 21:16:35 +00:00
|
|
|
* ```
|
2016-12-23 17:23:48 +00:00
|
|
|
* muxer_source_caps:video_encoder_source_caps:audio_encoder_source_caps
|
2019-08-30 21:16:35 +00:00
|
|
|
* ```
|
2016-12-16 14:11:57 +00:00
|
|
|
*
|
|
|
|
* For example to encode a stream into a WebM container, with an OGG audio
|
2020-11-20 21:35:49 +00:00
|
|
|
* stream and a VP8 video stream, the serialized #GstEncodingProfile looks like:
|
2016-12-16 14:11:57 +00:00
|
|
|
*
|
2019-08-30 21:16:35 +00:00
|
|
|
* ```
|
2016-12-16 14:11:57 +00:00
|
|
|
* video/webm:video/x-vp8:audio/x-vorbis
|
2019-08-30 21:16:35 +00:00
|
|
|
* ```
|
2016-12-16 14:11:57 +00:00
|
|
|
*
|
2020-11-20 21:35:49 +00:00
|
|
|
* It is possible to mix caps and element type names so you can specify a
|
|
|
|
* specific video encoder while using caps for other encoders/muxer.
|
2016-12-23 17:23:48 +00:00
|
|
|
*
|
2020-11-20 21:35:49 +00:00
|
|
|
* ### Using preset
|
2016-12-23 17:23:48 +00:00
|
|
|
*
|
2016-12-16 14:11:57 +00:00
|
|
|
* You can also set the preset name of the encoding profile using the
|
|
|
|
* caps+preset_name syntax as in:
|
|
|
|
*
|
2019-08-30 21:16:35 +00:00
|
|
|
* ```
|
2016-12-16 14:11:57 +00:00
|
|
|
* video/webm:video/x-vp8+youtube-preset:audio/x-vorbis
|
2019-08-30 21:16:35 +00:00
|
|
|
* ```
|
2016-12-16 14:11:57 +00:00
|
|
|
*
|
2020-11-20 21:35:49 +00:00
|
|
|
* ### Setting properties on muxers or on the encoding profile itself
|
|
|
|
*
|
2020-11-20 21:35:49 +00:00
|
|
|
* Moreover, you can set the extra properties:
|
|
|
|
*
|
|
|
|
* * `|element-properties,property1=true` (See
|
|
|
|
* #gst_encoding_profile_set_element_properties)
|
|
|
|
* * `|presence=true` (See See #gst_encoding_profile_get_presence)
|
|
|
|
* * `|single-segment=true` (See #gst_encoding_profile_set_single_segment)
|
|
|
|
* * `|single-segment=true` (See
|
|
|
|
* #gst_encoding_video_profile_set_variableframerate)
|
|
|
|
*
|
|
|
|
* for example:
|
2016-12-16 14:11:57 +00:00
|
|
|
*
|
2019-08-30 21:16:35 +00:00
|
|
|
* ```
|
2020-11-20 21:35:49 +00:00
|
|
|
* video/webm:video/x-vp8|presence=1|element-properties,target-bitrate=500000:audio/x-vorbis
|
2019-08-30 21:16:35 +00:00
|
|
|
* ```
|
2016-12-16 14:11:57 +00:00
|
|
|
*
|
2020-11-20 21:35:49 +00:00
|
|
|
* ### Enforcing properties to the stream itself (video size, number of audio channels, etc..)
|
|
|
|
*
|
2016-12-16 14:11:57 +00:00
|
|
|
* You can also use the `restriction_caps->encoded_format_caps` syntax to
|
|
|
|
* specify the restriction caps to be set on a #GstEncodingProfile
|
|
|
|
*
|
|
|
|
* It corresponds to the restriction #GstCaps to apply before the encoder that
|
2020-11-20 21:35:49 +00:00
|
|
|
* will be used in the profile (See #gst_encoding_profile_get_restriction). The
|
|
|
|
* fields present in restriction caps are properties of the raw stream (that is,
|
|
|
|
* before encoding), such as height and width for video and depth and sampling
|
|
|
|
* rate for audio. This property does not make sense for muxers. See
|
|
|
|
* #gst_encoding_profile_get_restriction for more details.
|
2016-12-16 14:11:57 +00:00
|
|
|
*
|
|
|
|
* To force a video stream to be encoded with a Full HD resolution (using WebM
|
|
|
|
* as the container format, VP8 as the video codec and Vorbis as the audio
|
|
|
|
* codec), you should use:
|
|
|
|
*
|
2019-08-30 21:16:35 +00:00
|
|
|
* ```
|
2016-12-23 17:23:48 +00:00
|
|
|
* "video/webm:video/x-raw,width=1920,height=1080->video/x-vp8:audio/x-vorbis"
|
2019-08-30 21:16:35 +00:00
|
|
|
* ```
|
2016-12-23 17:23:48 +00:00
|
|
|
*
|
|
|
|
* > NOTE: Make sure to enclose into quotes to avoid '>' to be reinterpreted by
|
|
|
|
* > the shell.
|
|
|
|
*
|
2020-11-20 21:35:49 +00:00
|
|
|
* In the case you are specifying encoders directly, the following is also
|
|
|
|
* possible:
|
2016-12-23 17:23:48 +00:00
|
|
|
*
|
2019-08-30 21:16:35 +00:00
|
|
|
* ```
|
2020-11-20 21:35:49 +00:00
|
|
|
* matroskamux:x264enc,width=1920,height=1080:audio/x-vorbis
|
2019-08-30 21:16:35 +00:00
|
|
|
* ```
|
2016-12-23 17:23:48 +00:00
|
|
|
*
|
2020-11-20 21:35:49 +00:00
|
|
|
* ## Some serialized encoding formats examples
|
2016-12-16 14:11:57 +00:00
|
|
|
*
|
2020-11-20 21:35:49 +00:00
|
|
|
* ### MP3 audio and H264 in MP4**
|
2016-12-16 14:11:57 +00:00
|
|
|
*
|
2019-08-30 21:16:35 +00:00
|
|
|
* ```
|
2016-12-16 14:11:57 +00:00
|
|
|
* video/quicktime,variant=iso:video/x-h264:audio/mpeg,mpegversion=1,layer=3
|
2019-08-30 21:16:35 +00:00
|
|
|
* ```
|
2016-12-16 14:11:57 +00:00
|
|
|
*
|
2020-11-20 21:35:49 +00:00
|
|
|
* ### Vorbis and theora in OGG
|
2016-12-16 14:11:57 +00:00
|
|
|
*
|
2019-08-30 21:16:35 +00:00
|
|
|
* ```
|
2016-12-16 14:11:57 +00:00
|
|
|
* application/ogg:video/x-theora:audio/x-vorbis
|
2019-08-30 21:16:35 +00:00
|
|
|
* ```
|
2016-12-16 14:11:57 +00:00
|
|
|
*
|
2020-11-20 21:35:49 +00:00
|
|
|
* ### AC3 and H264 in MPEG-TS
|
2016-12-16 14:11:57 +00:00
|
|
|
*
|
2019-08-30 21:16:35 +00:00
|
|
|
* ```
|
2016-12-16 14:11:57 +00:00
|
|
|
* video/mpegts:video/x-h264:audio/x-ac3
|
2019-08-30 21:16:35 +00:00
|
|
|
* ```
|
2016-12-16 14:11:57 +00:00
|
|
|
*
|
2016-12-23 17:23:48 +00:00
|
|
|
* ## Loading a profile from encoding targets
|
|
|
|
*
|
2020-11-20 21:35:49 +00:00
|
|
|
* Anywhere you have to use a string to define a #GstEncodingProfile, you
|
|
|
|
* can use load it from a #GstEncodingTarget using the following syntaxes:
|
2016-12-23 17:23:48 +00:00
|
|
|
*
|
2019-08-30 21:16:35 +00:00
|
|
|
* ```
|
2016-12-23 17:23:48 +00:00
|
|
|
* target_name[/profilename/category]
|
2019-08-30 21:16:35 +00:00
|
|
|
* ```
|
2016-12-23 17:23:48 +00:00
|
|
|
*
|
|
|
|
* or
|
|
|
|
*
|
2019-08-30 21:16:35 +00:00
|
|
|
* ```
|
2016-12-23 17:23:48 +00:00
|
|
|
* /path/to/target.gep:profilename
|
2019-08-30 21:16:35 +00:00
|
|
|
* ```
|
2016-12-23 17:23:48 +00:00
|
|
|
*
|
2018-10-22 09:37:41 +00:00
|
|
|
* ## Examples
|
|
|
|
*
|
|
|
|
* ### Creating a profile
|
2016-12-16 14:11:57 +00:00
|
|
|
*
|
2019-08-30 21:16:35 +00:00
|
|
|
* ``` c
|
2010-08-13 15:27:52 +00:00
|
|
|
* #include <gst/pbutils/encoding-profile.h>
|
|
|
|
* ...
|
|
|
|
* GstEncodingProfile *
|
|
|
|
* create_ogg_theora_profile(void)
|
|
|
|
*{
|
|
|
|
* GstEncodingContainerProfile *prof;
|
|
|
|
* GstCaps *caps;
|
|
|
|
*
|
|
|
|
* caps = gst_caps_from_string("application/ogg");
|
|
|
|
* prof = gst_encoding_container_profile_new("Ogg audio/video",
|
|
|
|
* "Standard OGG/THEORA/VORBIS",
|
|
|
|
* caps, NULL);
|
|
|
|
* gst_caps_unref (caps);
|
|
|
|
*
|
|
|
|
* caps = gst_caps_from_string("video/x-theora");
|
2011-03-21 18:22:30 +00:00
|
|
|
* gst_encoding_container_profile_add_profile(prof,
|
2010-08-13 15:27:52 +00:00
|
|
|
* (GstEncodingProfile*) gst_encoding_video_profile_new(caps, NULL, NULL, 0));
|
|
|
|
* gst_caps_unref (caps);
|
|
|
|
*
|
|
|
|
* caps = gst_caps_from_string("audio/x-vorbis");
|
2011-03-21 18:22:30 +00:00
|
|
|
* gst_encoding_container_profile_add_profile(prof,
|
2010-08-13 15:27:52 +00:00
|
|
|
* (GstEncodingProfile*) gst_encoding_audio_profile_new(caps, NULL, NULL, 0));
|
|
|
|
* gst_caps_unref (caps);
|
|
|
|
*
|
|
|
|
* return (GstEncodingProfile*) prof;
|
|
|
|
*}
|
|
|
|
*
|
2019-08-30 21:16:35 +00:00
|
|
|
* ```
|
2016-12-16 14:11:57 +00:00
|
|
|
*
|
2018-10-22 09:37:41 +00:00
|
|
|
* ### Example: Using an encoder preset with a profile
|
2016-12-16 14:11:57 +00:00
|
|
|
*
|
2019-08-30 21:16:35 +00:00
|
|
|
* ``` c
|
2014-07-18 10:31:23 +00:00
|
|
|
* #include <gst/pbutils/encoding-profile.h>
|
|
|
|
* ...
|
|
|
|
* GstEncodingProfile *
|
|
|
|
* create_ogg_theora_profile(void)
|
|
|
|
*{
|
|
|
|
* GstEncodingVideoProfile *v;
|
|
|
|
* GstEncodingAudioProfile *a;
|
|
|
|
* GstEncodingContainerProfile *prof;
|
|
|
|
* GstCaps *caps;
|
|
|
|
* GstPreset *preset;
|
|
|
|
*
|
|
|
|
* caps = gst_caps_from_string ("application/ogg");
|
|
|
|
* prof = gst_encoding_container_profile_new ("Ogg audio/video",
|
|
|
|
* "Standard OGG/THEORA/VORBIS",
|
|
|
|
* caps, NULL);
|
|
|
|
* gst_caps_unref (caps);
|
|
|
|
*
|
|
|
|
* preset = GST_PRESET (gst_element_factory_make ("theoraenc", "theorapreset"));
|
|
|
|
* g_object_set (preset, "bitrate", 1000, NULL);
|
|
|
|
* // The preset will be saved on the filesystem,
|
|
|
|
* // so try to use a descriptive name
|
|
|
|
* gst_preset_save_preset (preset, "theora_bitrate_preset");
|
|
|
|
* gst_object_unref (preset);
|
|
|
|
*
|
|
|
|
* caps = gst_caps_from_string ("video/x-theora");
|
2019-04-16 11:08:30 +00:00
|
|
|
* v = gst_encoding_video_profile_new (caps, "theora_bitrate_preset", NULL, 0);
|
2014-07-18 10:31:23 +00:00
|
|
|
* gst_encoding_container_profile_add_profile (prof, (GstEncodingProfile*) v);
|
|
|
|
* gst_caps_unref (caps);
|
|
|
|
*
|
|
|
|
* caps = gst_caps_from_string ("audio/x-vorbis");
|
|
|
|
* a = gst_encoding_audio_profile_new (caps, NULL, NULL, 0);
|
|
|
|
* gst_encoding_container_profile_add_profile (prof, (GstEncodingProfile*) a);
|
|
|
|
* gst_caps_unref (caps);
|
|
|
|
*
|
|
|
|
* return (GstEncodingProfile*) prof;
|
|
|
|
*}
|
|
|
|
*
|
2019-08-30 21:16:35 +00:00
|
|
|
* ```
|
2016-12-16 14:11:57 +00:00
|
|
|
*
|
2018-10-22 09:37:41 +00:00
|
|
|
* ### Listing categories, targets and profiles
|
2016-12-16 14:11:57 +00:00
|
|
|
*
|
2019-08-30 21:16:35 +00:00
|
|
|
* ``` c
|
2010-08-13 15:27:52 +00:00
|
|
|
* #include <gst/pbutils/encoding-profile.h>
|
|
|
|
* ...
|
2011-01-03 18:07:45 +00:00
|
|
|
* GstEncodingProfile *prof;
|
|
|
|
* GList *categories, *tmpc;
|
|
|
|
* GList *targets, *tmpt;
|
|
|
|
* ...
|
2014-07-18 10:16:05 +00:00
|
|
|
* categories = gst_encoding_list_available_categories ();
|
2010-08-13 15:27:52 +00:00
|
|
|
*
|
2011-01-03 18:07:45 +00:00
|
|
|
* ... Show available categories to user ...
|
2010-08-13 15:27:52 +00:00
|
|
|
*
|
2011-01-03 18:07:45 +00:00
|
|
|
* for (tmpc = categories; tmpc; tmpc = tmpc->next) {
|
|
|
|
* gchar *category = (gchar *) tmpc->data;
|
2010-08-13 15:27:52 +00:00
|
|
|
*
|
2011-01-03 18:07:45 +00:00
|
|
|
* ... and we can list all targets within that category ...
|
2012-12-05 18:21:43 +00:00
|
|
|
*
|
2014-07-18 10:16:05 +00:00
|
|
|
* targets = gst_encoding_list_all_targets (category);
|
2010-08-13 15:27:52 +00:00
|
|
|
*
|
2011-01-03 18:07:45 +00:00
|
|
|
* ... and show a list to our users ...
|
|
|
|
*
|
|
|
|
* g_list_foreach (targets, (GFunc) gst_encoding_target_unref, NULL);
|
|
|
|
* g_list_free (targets);
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* g_list_foreach (categories, (GFunc) g_free, NULL);
|
|
|
|
* g_list_free (categories);
|
|
|
|
*
|
|
|
|
* ...
|
2019-08-30 21:16:35 +00:00
|
|
|
* ```
|
2010-08-13 15:27:52 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "encoding-profile.h"
|
2010-12-22 17:18:00 +00:00
|
|
|
#include "encoding-target.h"
|
2010-08-13 15:27:52 +00:00
|
|
|
|
2012-12-23 15:26:59 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2010-08-13 15:27:52 +00:00
|
|
|
/* GstEncodingProfile API */
|
2020-11-20 21:35:49 +00:00
|
|
|
#define PROFILE_LOCK(profile) (g_mutex_lock(&((GstEncodingProfile*)profile)->lock))
|
|
|
|
#define PROFILE_UNLOCK(profile) (g_mutex_unlock(&((GstEncodingProfile*)profile)->lock))
|
2010-08-13 15:27:52 +00:00
|
|
|
|
|
|
|
struct _GstEncodingProfile
|
|
|
|
{
|
2011-02-23 13:12:22 +00:00
|
|
|
GObject parent;
|
2010-08-13 15:27:52 +00:00
|
|
|
|
|
|
|
/*< public > */
|
|
|
|
gchar *name;
|
|
|
|
gchar *description;
|
|
|
|
GstCaps *format;
|
|
|
|
gchar *preset;
|
2012-12-05 18:21:43 +00:00
|
|
|
gchar *preset_name;
|
2010-08-13 15:27:52 +00:00
|
|
|
guint presence;
|
2014-11-16 14:54:56 +00:00
|
|
|
gboolean allow_dynamic_output;
|
2015-05-07 08:26:47 +00:00
|
|
|
gboolean enabled;
|
2019-08-30 21:16:35 +00:00
|
|
|
gboolean single_segment;
|
2020-11-20 21:35:49 +00:00
|
|
|
|
|
|
|
GMutex lock; // {
|
|
|
|
GstCaps *restriction;
|
|
|
|
GstStructure *element_properties;
|
|
|
|
// }
|
2010-08-13 15:27:52 +00:00
|
|
|
};
|
|
|
|
|
2012-03-14 14:51:22 +00:00
|
|
|
struct _GstEncodingProfileClass
|
|
|
|
{
|
|
|
|
GObjectClass parent_class;
|
2017-01-04 17:27:40 +00:00
|
|
|
|
|
|
|
void (*copy) (GstEncodingProfile * self, GstEncodingProfile * copy);
|
2012-03-14 14:51:22 +00:00
|
|
|
};
|
|
|
|
|
2013-10-07 17:52:00 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
FIRST_PROPERTY,
|
|
|
|
PROP_RESTRICTION_CAPS,
|
2020-11-20 21:35:49 +00:00
|
|
|
PROP_ELEMENT_PROPERTIES,
|
2013-10-07 17:52:00 +00:00
|
|
|
LAST_PROPERTY
|
|
|
|
};
|
|
|
|
|
|
|
|
static GParamSpec *_properties[LAST_PROPERTY];
|
|
|
|
|
2010-12-22 17:18:00 +00:00
|
|
|
static void string_to_profile_transform (const GValue * src_value,
|
|
|
|
GValue * dest_value);
|
|
|
|
static gboolean gst_encoding_profile_deserialize_valfunc (GValue * value,
|
|
|
|
const gchar * s);
|
2020-03-20 13:58:19 +00:00
|
|
|
static gchar *gst_encoding_profile_serialize_valfunc (GValue * value);
|
2010-12-22 17:18:00 +00:00
|
|
|
|
|
|
|
static void gst_encoding_profile_class_init (GstEncodingProfileClass * klass);
|
|
|
|
static gpointer gst_encoding_profile_parent_class = NULL;
|
2010-08-13 15:27:52 +00:00
|
|
|
|
|
|
|
static void
|
2010-12-22 17:18:00 +00:00
|
|
|
gst_encoding_profile_class_intern_init (gpointer klass)
|
|
|
|
{
|
|
|
|
gst_encoding_profile_parent_class = g_type_class_peek_parent (klass);
|
|
|
|
gst_encoding_profile_class_init ((GstEncodingProfileClass *) klass);
|
|
|
|
}
|
|
|
|
|
|
|
|
GType
|
|
|
|
gst_encoding_profile_get_type (void)
|
|
|
|
{
|
2021-03-18 08:18:36 +00:00
|
|
|
static gsize g_define_type_id_init = 0;
|
2010-12-22 17:18:00 +00:00
|
|
|
|
2021-03-18 08:18:36 +00:00
|
|
|
if (g_once_init_enter (&g_define_type_id_init)) {
|
2011-02-23 13:12:22 +00:00
|
|
|
GType g_define_type_id = g_type_register_static_simple (G_TYPE_OBJECT,
|
2010-12-22 17:18:00 +00:00
|
|
|
g_intern_static_string ("GstEncodingProfile"),
|
|
|
|
sizeof (GstEncodingProfileClass),
|
|
|
|
(GClassInitFunc) gst_encoding_profile_class_intern_init,
|
|
|
|
sizeof (GstEncodingProfile),
|
|
|
|
NULL,
|
|
|
|
(GTypeFlags) 0);
|
|
|
|
static GstValueTable gstvtable = {
|
|
|
|
G_TYPE_NONE,
|
|
|
|
(GstValueCompareFunc) NULL,
|
2020-03-20 13:58:19 +00:00
|
|
|
(GstValueSerializeFunc) gst_encoding_profile_serialize_valfunc,
|
2010-12-22 17:18:00 +00:00
|
|
|
(GstValueDeserializeFunc) gst_encoding_profile_deserialize_valfunc
|
|
|
|
};
|
|
|
|
|
|
|
|
gstvtable.type = g_define_type_id;
|
|
|
|
|
|
|
|
/* Register a STRING=>PROFILE GValueTransformFunc */
|
|
|
|
g_value_register_transform_func (G_TYPE_STRING, g_define_type_id,
|
|
|
|
string_to_profile_transform);
|
|
|
|
/* Register gst-specific GValue functions */
|
|
|
|
gst_value_register (&gstvtable);
|
|
|
|
|
2021-03-18 08:18:36 +00:00
|
|
|
g_once_init_leave (&g_define_type_id_init, g_define_type_id);
|
2010-12-22 17:18:00 +00:00
|
|
|
}
|
2021-03-18 08:18:36 +00:00
|
|
|
return g_define_type_id_init;
|
2010-08-13 15:27:52 +00:00
|
|
|
}
|
|
|
|
|
2013-10-07 17:52:00 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
_encoding_profile_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstEncodingProfile *prof = (GstEncodingProfile *) object;
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_RESTRICTION_CAPS:
|
|
|
|
gst_value_set_caps (value, prof->restriction);
|
|
|
|
break;
|
2020-11-20 21:35:49 +00:00
|
|
|
case PROP_ELEMENT_PROPERTIES:
|
|
|
|
PROFILE_LOCK (prof);
|
|
|
|
gst_value_set_structure (value, prof->element_properties);
|
|
|
|
PROFILE_UNLOCK (prof);
|
|
|
|
break;
|
2013-10-07 17:52:00 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_encoding_profile_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstEncodingProfile *prof = (GstEncodingProfile *) object;
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_RESTRICTION_CAPS:
|
|
|
|
gst_encoding_profile_set_restriction (prof, gst_caps_copy
|
|
|
|
(gst_value_get_caps (value)));
|
2013-12-30 16:30:15 +00:00
|
|
|
break;
|
2020-11-20 21:35:49 +00:00
|
|
|
case PROP_ELEMENT_PROPERTIES:
|
|
|
|
{
|
|
|
|
const GstStructure *structure = gst_value_get_structure (value);
|
|
|
|
|
|
|
|
gst_encoding_profile_set_element_properties (prof,
|
|
|
|
structure ? gst_structure_copy (structure) : NULL);
|
|
|
|
break;
|
|
|
|
}
|
2013-10-07 17:52:00 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-13 15:27:52 +00:00
|
|
|
static void
|
2011-02-23 13:12:22 +00:00
|
|
|
gst_encoding_profile_finalize (GObject * object)
|
2010-08-13 15:27:52 +00:00
|
|
|
{
|
2011-02-23 13:12:22 +00:00
|
|
|
GstEncodingProfile *prof = (GstEncodingProfile *) object;
|
2015-11-15 10:58:54 +00:00
|
|
|
g_free (prof->name);
|
2010-08-13 15:27:52 +00:00
|
|
|
if (prof->format)
|
|
|
|
gst_caps_unref (prof->format);
|
2015-11-15 10:58:54 +00:00
|
|
|
g_free (prof->preset);
|
|
|
|
g_free (prof->description);
|
2010-08-13 15:27:52 +00:00
|
|
|
if (prof->restriction)
|
|
|
|
gst_caps_unref (prof->restriction);
|
2015-11-15 10:58:54 +00:00
|
|
|
g_free (prof->preset_name);
|
2010-08-13 15:27:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-03-14 14:51:22 +00:00
|
|
|
gst_encoding_profile_class_init (GstEncodingProfileClass * klass)
|
2010-08-13 15:27:52 +00:00
|
|
|
{
|
2012-03-14 14:51:22 +00:00
|
|
|
GObjectClass *gobject_class = (GObjectClass *) klass;
|
|
|
|
|
|
|
|
gobject_class->finalize = gst_encoding_profile_finalize;
|
2013-10-07 17:52:00 +00:00
|
|
|
|
|
|
|
gobject_class->set_property = _encoding_profile_set_property;
|
|
|
|
gobject_class->get_property = _encoding_profile_get_property;
|
|
|
|
|
|
|
|
_properties[PROP_RESTRICTION_CAPS] =
|
|
|
|
g_param_spec_boxed ("restriction-caps", "Restriction caps",
|
|
|
|
"The restriction caps to use", GST_TYPE_CAPS,
|
2020-11-20 21:35:49 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GstEncodingProfile:element-properties:
|
|
|
|
*
|
|
|
|
* A #GstStructure defining the properties to be set to the element
|
|
|
|
* the profile represents.
|
|
|
|
*
|
|
|
|
* For example for `av1enc`:
|
|
|
|
*
|
|
|
|
* ```
|
|
|
|
* element-properties,row-mt=true, end-usage=vbr
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* Since: 1.20
|
|
|
|
*/
|
|
|
|
_properties[PROP_ELEMENT_PROPERTIES] =
|
|
|
|
g_param_spec_boxed ("element-properties", "Element properties",
|
|
|
|
"The element properties to use. "
|
|
|
|
"Example: {properties,boolean-prop=true,string-prop=\"hi\"}.",
|
|
|
|
GST_TYPE_STRUCTURE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
|
|
|
|
|
|
|
|
g_object_class_install_properties (gobject_class, LAST_PROPERTY, _properties);
|
2010-08-13 15:27:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_encoding_profile_get_name:
|
|
|
|
* @profile: a #GstEncodingProfile
|
|
|
|
*
|
|
|
|
* Returns: the name of the profile, can be %NULL.
|
|
|
|
*/
|
|
|
|
const gchar *
|
|
|
|
gst_encoding_profile_get_name (GstEncodingProfile * profile)
|
|
|
|
{
|
2016-12-15 19:10:55 +00:00
|
|
|
g_return_val_if_fail (GST_IS_ENCODING_PROFILE (profile), NULL);
|
|
|
|
|
2010-08-13 15:27:52 +00:00
|
|
|
return profile->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_encoding_profile_get_description:
|
|
|
|
* @profile: a #GstEncodingProfile
|
|
|
|
*
|
|
|
|
* Returns: the description of the profile, can be %NULL.
|
|
|
|
*/
|
|
|
|
const gchar *
|
|
|
|
gst_encoding_profile_get_description (GstEncodingProfile * profile)
|
|
|
|
{
|
2016-12-15 19:10:55 +00:00
|
|
|
g_return_val_if_fail (GST_IS_ENCODING_PROFILE (profile), NULL);
|
|
|
|
|
2010-08-13 15:27:52 +00:00
|
|
|
return profile->description;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_encoding_profile_get_format:
|
|
|
|
* @profile: a #GstEncodingProfile
|
|
|
|
*
|
2011-05-17 10:47:32 +00:00
|
|
|
* Returns: (transfer full): the #GstCaps corresponding to the media format used
|
|
|
|
* in the profile. Unref after usage.
|
2010-08-13 15:27:52 +00:00
|
|
|
*/
|
2011-05-17 10:47:32 +00:00
|
|
|
GstCaps *
|
2010-08-13 15:27:52 +00:00
|
|
|
gst_encoding_profile_get_format (GstEncodingProfile * profile)
|
|
|
|
{
|
2016-12-15 19:10:55 +00:00
|
|
|
g_return_val_if_fail (GST_IS_ENCODING_PROFILE (profile), NULL);
|
|
|
|
|
2011-05-17 10:47:32 +00:00
|
|
|
return (profile->format ? gst_caps_ref (profile->format) : NULL);
|
2010-08-13 15:27:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_encoding_profile_get_preset:
|
|
|
|
* @profile: a #GstEncodingProfile
|
|
|
|
*
|
2012-12-15 17:43:40 +00:00
|
|
|
* Returns: the name of the #GstPreset to be used in the profile.
|
|
|
|
* This is the name that has been set when saving the preset.
|
2010-08-13 15:27:52 +00:00
|
|
|
*/
|
|
|
|
const gchar *
|
|
|
|
gst_encoding_profile_get_preset (GstEncodingProfile * profile)
|
|
|
|
{
|
2016-12-15 19:10:55 +00:00
|
|
|
g_return_val_if_fail (GST_IS_ENCODING_PROFILE (profile), NULL);
|
|
|
|
|
2010-08-13 15:27:52 +00:00
|
|
|
return profile->preset;
|
|
|
|
}
|
|
|
|
|
2012-12-05 18:21:43 +00:00
|
|
|
/**
|
|
|
|
* gst_encoding_profile_get_preset_name:
|
|
|
|
* @profile: a #GstEncodingProfile
|
|
|
|
*
|
2012-12-15 17:43:40 +00:00
|
|
|
* Returns: the name of the #GstPreset factory to be used in the profile.
|
2012-12-05 18:21:43 +00:00
|
|
|
*/
|
|
|
|
const gchar *
|
|
|
|
gst_encoding_profile_get_preset_name (GstEncodingProfile * profile)
|
|
|
|
{
|
2016-12-15 19:10:55 +00:00
|
|
|
g_return_val_if_fail (GST_IS_ENCODING_PROFILE (profile), NULL);
|
|
|
|
|
2012-12-05 18:21:43 +00:00
|
|
|
return profile->preset_name;
|
|
|
|
}
|
|
|
|
|
2010-08-13 15:27:52 +00:00
|
|
|
/**
|
|
|
|
* gst_encoding_profile_get_presence:
|
|
|
|
* @profile: a #GstEncodingProfile
|
|
|
|
*
|
2011-01-04 20:20:34 +00:00
|
|
|
* Returns: The number of times the profile is used in its parent
|
|
|
|
* container profile. If 0, it is not a mandatory stream.
|
2010-08-13 15:27:52 +00:00
|
|
|
*/
|
2010-12-18 01:06:27 +00:00
|
|
|
guint
|
2010-08-13 15:27:52 +00:00
|
|
|
gst_encoding_profile_get_presence (GstEncodingProfile * profile)
|
|
|
|
{
|
2016-12-15 19:10:55 +00:00
|
|
|
g_return_val_if_fail (GST_IS_ENCODING_PROFILE (profile), 0);
|
|
|
|
|
2010-08-13 15:27:52 +00:00
|
|
|
return profile->presence;
|
|
|
|
}
|
|
|
|
|
2015-05-07 08:26:47 +00:00
|
|
|
/**
|
|
|
|
* gst_encoding_profile_get_enabled:
|
|
|
|
* @profile: a #GstEncodingProfile
|
|
|
|
*
|
2019-08-29 17:42:39 +00:00
|
|
|
* Returns: Whether @profile is enabled or not
|
2017-10-16 12:16:31 +00:00
|
|
|
*
|
2019-04-23 12:05:43 +00:00
|
|
|
* Since: 1.6
|
2015-05-07 08:26:47 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_encoding_profile_is_enabled (GstEncodingProfile * profile)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GST_IS_ENCODING_PROFILE (profile), FALSE);
|
|
|
|
|
|
|
|
return profile->enabled;
|
|
|
|
}
|
|
|
|
|
2010-08-13 15:27:52 +00:00
|
|
|
/**
|
|
|
|
* gst_encoding_profile_get_restriction:
|
|
|
|
* @profile: a #GstEncodingProfile
|
|
|
|
*
|
2011-05-17 10:47:32 +00:00
|
|
|
* Returns: (transfer full): The restriction #GstCaps to apply before the encoder
|
2011-01-04 20:20:34 +00:00
|
|
|
* that will be used in the profile. The fields present in restriction caps are
|
|
|
|
* properties of the raw stream (that is before encoding), such as height and
|
|
|
|
* width for video and depth and sampling rate for audio. Does not apply to
|
|
|
|
* #GstEncodingContainerProfile (since there is no corresponding raw stream).
|
2011-05-17 10:47:32 +00:00
|
|
|
* Can be %NULL. Unref after usage.
|
2010-08-13 15:27:52 +00:00
|
|
|
*/
|
2011-05-17 10:47:32 +00:00
|
|
|
GstCaps *
|
2010-08-13 15:27:52 +00:00
|
|
|
gst_encoding_profile_get_restriction (GstEncodingProfile * profile)
|
|
|
|
{
|
2016-12-15 19:10:55 +00:00
|
|
|
g_return_val_if_fail (GST_IS_ENCODING_PROFILE (profile), NULL);
|
|
|
|
|
|
|
|
|
2011-05-17 10:47:32 +00:00
|
|
|
return (profile->restriction ? gst_caps_ref (profile->restriction) : NULL);
|
2010-08-13 15:27:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_encoding_profile_set_name:
|
|
|
|
* @profile: a #GstEncodingProfile
|
2018-02-19 17:57:48 +00:00
|
|
|
* @name: (allow-none): the name to set on the profile
|
2010-08-13 15:27:52 +00:00
|
|
|
*
|
|
|
|
* Set @name as the given name for the @profile. A copy of @name will be made
|
|
|
|
* internally.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_encoding_profile_set_name (GstEncodingProfile * profile, const gchar * name)
|
|
|
|
{
|
2016-12-15 19:10:55 +00:00
|
|
|
g_return_if_fail (GST_IS_ENCODING_PROFILE (profile));
|
|
|
|
|
2015-11-15 10:58:54 +00:00
|
|
|
g_free (profile->name);
|
2010-08-13 15:27:52 +00:00
|
|
|
profile->name = g_strdup (name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_encoding_profile_set_description:
|
|
|
|
* @profile: a #GstEncodingProfile
|
2018-02-19 17:57:48 +00:00
|
|
|
* @description: (allow-none): the description to set on the profile
|
2010-08-13 15:27:52 +00:00
|
|
|
*
|
2011-12-14 12:28:26 +00:00
|
|
|
* Set @description as the given description for the @profile. A copy of
|
|
|
|
* @description will be made internally.
|
2010-08-13 15:27:52 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_encoding_profile_set_description (GstEncodingProfile * profile,
|
|
|
|
const gchar * description)
|
|
|
|
{
|
2016-12-15 19:10:55 +00:00
|
|
|
g_return_if_fail (GST_IS_ENCODING_PROFILE (profile));
|
|
|
|
|
2015-11-15 10:58:54 +00:00
|
|
|
g_free (profile->description);
|
2010-08-13 15:27:52 +00:00
|
|
|
profile->description = g_strdup (description);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_encoding_profile_set_format:
|
|
|
|
* @profile: a #GstEncodingProfile
|
2017-04-09 09:19:22 +00:00
|
|
|
* @format: (transfer none): the media format to use in the profile.
|
2010-08-13 15:27:52 +00:00
|
|
|
*
|
|
|
|
* Sets the media format used in the profile.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_encoding_profile_set_format (GstEncodingProfile * profile, GstCaps * format)
|
|
|
|
{
|
2016-12-15 19:10:55 +00:00
|
|
|
g_return_if_fail (GST_IS_ENCODING_PROFILE (profile));
|
|
|
|
|
2010-08-13 15:27:52 +00:00
|
|
|
if (profile->format)
|
|
|
|
gst_caps_unref (profile->format);
|
|
|
|
profile->format = gst_caps_ref (format);
|
|
|
|
}
|
|
|
|
|
2014-11-16 14:54:56 +00:00
|
|
|
/**
|
|
|
|
* gst_encoding_profile_get_allow_dynamic_output:
|
|
|
|
* @profile: a #GstEncodingProfile
|
|
|
|
*
|
|
|
|
* Get whether the format that has been negotiated in at some point can be renegotiated
|
|
|
|
* later during the encoding.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_encoding_profile_get_allow_dynamic_output (GstEncodingProfile * profile)
|
|
|
|
{
|
2016-12-15 19:10:55 +00:00
|
|
|
g_return_val_if_fail (GST_IS_ENCODING_PROFILE (profile), FALSE);
|
|
|
|
|
2014-11-16 14:54:56 +00:00
|
|
|
return profile->allow_dynamic_output;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_encoding_profile_set_allow_dynamic_output:
|
|
|
|
* @profile: a #GstEncodingProfile
|
|
|
|
* @allow_dynamic_output: Whether the format that has been negotiated first can be renegotiated
|
|
|
|
* during the encoding
|
|
|
|
*
|
|
|
|
* Sets whether the format that has been negotiated in at some point can be renegotiated
|
|
|
|
* later during the encoding.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_encoding_profile_set_allow_dynamic_output (GstEncodingProfile * profile,
|
|
|
|
gboolean allow_dynamic_output)
|
|
|
|
{
|
2016-12-15 19:10:55 +00:00
|
|
|
g_return_if_fail (GST_IS_ENCODING_PROFILE (profile));
|
|
|
|
|
2014-11-16 14:54:56 +00:00
|
|
|
profile->allow_dynamic_output = allow_dynamic_output;
|
|
|
|
}
|
|
|
|
|
2019-08-30 21:16:35 +00:00
|
|
|
/**
|
|
|
|
* gst_encoding_profile_get_single_segment:
|
|
|
|
* @profile: a #GstEncodingProfile
|
|
|
|
*
|
|
|
|
* Returns: #TRUE if the stream represented by @profile should use a single
|
|
|
|
* segment before the encoder, #FALSE otherwise. This means that buffers will be retimestamped
|
|
|
|
* and segments will be eat so as to appear as one segment.
|
2020-01-13 21:32:59 +00:00
|
|
|
*
|
|
|
|
* Since: 1.18
|
2019-08-30 21:16:35 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_encoding_profile_get_single_segment (GstEncodingProfile * profile)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GST_IS_ENCODING_PROFILE (profile), FALSE);
|
|
|
|
|
|
|
|
return profile->single_segment;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_encoding_profile_set_single_segment:
|
|
|
|
* @profile: a #GstEncodingProfile
|
2020-07-04 16:33:20 +00:00
|
|
|
* @single_segment: #TRUE if the stream represented by @profile should use a
|
|
|
|
* single segment before the encoder, #FALSE otherwise.
|
2019-08-30 21:16:35 +00:00
|
|
|
*
|
2020-07-04 16:33:20 +00:00
|
|
|
* If using a single segment, buffers will be retimestamped and segments will be
|
|
|
|
* eat so as to appear as one segment.
|
|
|
|
*
|
|
|
|
* > *NOTE*: Single segment is not property supported when using
|
|
|
|
* > #encodebin:avoid-reencoding
|
2020-01-13 21:32:59 +00:00
|
|
|
*
|
|
|
|
* Since: 1.18
|
2019-08-30 21:16:35 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_encoding_profile_set_single_segment (GstEncodingProfile * profile,
|
|
|
|
gboolean single_segment)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GST_IS_ENCODING_PROFILE (profile));
|
|
|
|
|
|
|
|
profile->single_segment = single_segment;
|
|
|
|
}
|
|
|
|
|
2010-08-13 15:27:52 +00:00
|
|
|
/**
|
|
|
|
* gst_encoding_profile_set_preset:
|
|
|
|
* @profile: a #GstEncodingProfile
|
2017-01-10 11:57:51 +00:00
|
|
|
* @preset: (nullable): the element preset to use
|
2010-08-13 15:27:52 +00:00
|
|
|
*
|
2012-12-05 18:21:43 +00:00
|
|
|
* Sets the name of the #GstElement that implements the #GstPreset interface
|
|
|
|
* to use for the profile.
|
2012-12-15 17:43:40 +00:00
|
|
|
* This is the name that has been set when saving the preset.
|
2010-08-13 15:27:52 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_encoding_profile_set_preset (GstEncodingProfile * profile,
|
|
|
|
const gchar * preset)
|
|
|
|
{
|
2016-12-15 19:10:55 +00:00
|
|
|
g_return_if_fail (GST_IS_ENCODING_PROFILE (profile));
|
|
|
|
|
2015-11-15 10:58:54 +00:00
|
|
|
g_free (profile->preset);
|
2010-08-13 15:27:52 +00:00
|
|
|
profile->preset = g_strdup (preset);
|
|
|
|
}
|
|
|
|
|
2012-12-05 18:21:43 +00:00
|
|
|
/**
|
2013-03-29 14:05:12 +00:00
|
|
|
* gst_encoding_profile_set_preset_name:
|
2012-12-05 18:21:43 +00:00
|
|
|
* @profile: a #GstEncodingProfile
|
2018-02-19 17:57:48 +00:00
|
|
|
* @preset_name: (allow-none): The name of the preset to use in this @profile.
|
2012-12-05 18:21:43 +00:00
|
|
|
*
|
2012-12-15 17:43:40 +00:00
|
|
|
* Sets the name of the #GstPreset's factory to be used in the profile.
|
2012-12-05 18:21:43 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_encoding_profile_set_preset_name (GstEncodingProfile * profile,
|
|
|
|
const gchar * preset_name)
|
|
|
|
{
|
2016-12-15 19:10:55 +00:00
|
|
|
g_return_if_fail (GST_IS_ENCODING_PROFILE (profile));
|
|
|
|
|
2015-11-15 10:58:54 +00:00
|
|
|
g_free (profile->preset_name);
|
2012-12-05 18:21:43 +00:00
|
|
|
profile->preset_name = g_strdup (preset_name);
|
|
|
|
}
|
|
|
|
|
2010-08-13 15:27:52 +00:00
|
|
|
/**
|
|
|
|
* gst_encoding_profile_set_presence:
|
|
|
|
* @profile: a #GstEncodingProfile
|
|
|
|
* @presence: the number of time the profile can be used
|
|
|
|
*
|
|
|
|
* Set the number of time the profile is used in its parent
|
|
|
|
* container profile. If 0, it is not a mandatory stream
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_encoding_profile_set_presence (GstEncodingProfile * profile, guint presence)
|
|
|
|
{
|
2016-12-15 19:10:55 +00:00
|
|
|
g_return_if_fail (GST_IS_ENCODING_PROFILE (profile));
|
|
|
|
|
2010-08-13 15:27:52 +00:00
|
|
|
profile->presence = presence;
|
|
|
|
}
|
|
|
|
|
2015-05-07 08:26:47 +00:00
|
|
|
/**
|
|
|
|
* gst_encoding_profile_set_enabled:
|
|
|
|
* @profile: a #GstEncodingProfile
|
2018-09-21 16:54:39 +00:00
|
|
|
* @enabled: %FALSE to disable @profile, %TRUE to enable it
|
2015-05-07 08:26:47 +00:00
|
|
|
*
|
|
|
|
* Set whether the profile should be used or not.
|
2017-10-16 12:16:31 +00:00
|
|
|
*
|
2019-04-23 12:05:43 +00:00
|
|
|
* Since: 1.6
|
2015-05-07 08:26:47 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_encoding_profile_set_enabled (GstEncodingProfile * profile,
|
|
|
|
gboolean enabled)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GST_IS_ENCODING_PROFILE (profile));
|
|
|
|
|
|
|
|
profile->enabled = enabled;
|
|
|
|
}
|
|
|
|
|
2010-08-13 15:27:52 +00:00
|
|
|
/**
|
|
|
|
* gst_encoding_profile_set_restriction:
|
|
|
|
* @profile: a #GstEncodingProfile
|
2018-02-19 17:57:48 +00:00
|
|
|
* @restriction: (allow-none) (transfer full): the restriction to apply
|
2010-08-13 15:27:52 +00:00
|
|
|
*
|
|
|
|
* Set the restriction #GstCaps to apply before the encoder
|
2014-01-13 14:32:23 +00:00
|
|
|
* that will be used in the profile. See gst_encoding_profile_get_restriction()
|
2011-01-04 20:20:34 +00:00
|
|
|
* for more about restrictions. Does not apply to #GstEncodingContainerProfile.
|
2010-08-13 15:27:52 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_encoding_profile_set_restriction (GstEncodingProfile * profile,
|
|
|
|
GstCaps * restriction)
|
|
|
|
{
|
2018-10-02 00:51:26 +00:00
|
|
|
g_return_if_fail (restriction == NULL || GST_IS_CAPS (restriction));
|
2016-12-15 19:10:55 +00:00
|
|
|
g_return_if_fail (GST_IS_ENCODING_PROFILE (profile));
|
|
|
|
|
2010-08-13 15:27:52 +00:00
|
|
|
if (profile->restriction)
|
|
|
|
gst_caps_unref (profile->restriction);
|
|
|
|
profile->restriction = restriction;
|
2013-10-07 17:52:00 +00:00
|
|
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (profile),
|
|
|
|
_properties[PROP_RESTRICTION_CAPS]);
|
2010-08-13 15:27:52 +00:00
|
|
|
}
|
|
|
|
|
2020-11-20 21:35:49 +00:00
|
|
|
/**
|
|
|
|
* gst_encoding_profile_set_element_properties:
|
|
|
|
* @self: a #GstEncodingProfile
|
|
|
|
* @element_properties: (transfer full): A #GstStructure defining the properties
|
|
|
|
* to be set to the element the profile represents.
|
|
|
|
*
|
|
|
|
* This allows setting the muxing/encoding element properties.
|
|
|
|
*
|
|
|
|
* **Set properties generically**
|
|
|
|
*
|
|
|
|
* ``` properties
|
|
|
|
* [element-properties, boolean-prop=true, string-prop="hi"]
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* **Mapping properties with well known element factories**
|
|
|
|
*
|
|
|
|
* ``` properties
|
|
|
|
* element-properties-map, map = {
|
|
|
|
* [openh264enc, gop-size=32, ],
|
|
|
|
* [x264enc, key-int-max=32, tune=zerolatency],
|
|
|
|
* }
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* Since: 1.20
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_encoding_profile_set_element_properties (GstEncodingProfile * self,
|
|
|
|
GstStructure * element_properties)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GST_IS_ENCODING_PROFILE (self));
|
|
|
|
g_return_if_fail (!element_properties
|
|
|
|
|| GST_IS_STRUCTURE (element_properties));
|
|
|
|
|
|
|
|
#ifndef G_DISABLE_CHECKS
|
|
|
|
if (element_properties &&
|
|
|
|
(gst_structure_has_name (element_properties, "element-properties-map")
|
|
|
|
|| gst_structure_has_name (element_properties, "properties-map")
|
|
|
|
|| gst_structure_has_name (element_properties, "map")))
|
|
|
|
g_return_if_fail (gst_structure_has_field_typed (element_properties, "map",
|
|
|
|
GST_TYPE_LIST));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
PROFILE_LOCK (self);
|
|
|
|
if (self->element_properties)
|
|
|
|
gst_structure_free (self->element_properties);
|
|
|
|
if (element_properties)
|
|
|
|
self->element_properties = element_properties;
|
|
|
|
else
|
|
|
|
self->element_properties = NULL;
|
|
|
|
PROFILE_UNLOCK (self);
|
|
|
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (self),
|
|
|
|
_properties[PROP_ELEMENT_PROPERTIES]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_encoding_profile_get_element_properties:
|
|
|
|
* @self: a #GstEncodingProfile
|
|
|
|
*
|
|
|
|
* Returns: (transfer full) (nullable): The properties that are going to be set on the underlying element
|
|
|
|
*
|
|
|
|
* Since: 1.20
|
|
|
|
*/
|
|
|
|
GstStructure *
|
|
|
|
gst_encoding_profile_get_element_properties (GstEncodingProfile * self)
|
|
|
|
{
|
|
|
|
GstStructure *res = NULL;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_ENCODING_PROFILE (self), NULL);
|
|
|
|
|
|
|
|
PROFILE_LOCK (self);
|
|
|
|
if (self->element_properties)
|
|
|
|
res = gst_structure_copy (self->element_properties);
|
|
|
|
PROFILE_UNLOCK (self);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2010-08-13 15:27:52 +00:00
|
|
|
/* Container profiles */
|
|
|
|
|
|
|
|
struct _GstEncodingContainerProfile
|
|
|
|
{
|
|
|
|
GstEncodingProfile parent;
|
|
|
|
|
|
|
|
GList *encodingprofiles;
|
|
|
|
};
|
|
|
|
|
2012-03-14 14:51:22 +00:00
|
|
|
struct _GstEncodingContainerProfileClass
|
|
|
|
{
|
|
|
|
GstEncodingProfileClass parent;
|
|
|
|
};
|
|
|
|
|
2010-08-13 15:27:52 +00:00
|
|
|
G_DEFINE_TYPE (GstEncodingContainerProfile, gst_encoding_container_profile,
|
|
|
|
GST_TYPE_ENCODING_PROFILE);
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_encoding_container_profile_init (GstEncodingContainerProfile * prof)
|
|
|
|
{
|
|
|
|
/* Nothing to initialize */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-02-23 13:12:22 +00:00
|
|
|
gst_encoding_container_profile_finalize (GObject * object)
|
2010-08-13 15:27:52 +00:00
|
|
|
{
|
2011-02-23 13:12:22 +00:00
|
|
|
GstEncodingContainerProfile *prof = (GstEncodingContainerProfile *) object;
|
|
|
|
|
2011-03-28 15:02:26 +00:00
|
|
|
g_list_foreach (prof->encodingprofiles, (GFunc) g_object_unref, NULL);
|
2010-08-13 15:27:52 +00:00
|
|
|
g_list_free (prof->encodingprofiles);
|
|
|
|
|
2011-02-23 13:12:22 +00:00
|
|
|
G_OBJECT_CLASS (gst_encoding_container_profile_parent_class)->finalize
|
|
|
|
((GObject *) prof);
|
2010-08-13 15:27:52 +00:00
|
|
|
}
|
|
|
|
|
2017-01-04 17:27:40 +00:00
|
|
|
static void
|
|
|
|
gst_encoding_container_profile_copy (GstEncodingProfile * profile,
|
|
|
|
GstEncodingProfile * copy_profile)
|
|
|
|
{
|
|
|
|
GstEncodingContainerProfile *self = GST_ENCODING_CONTAINER_PROFILE (profile),
|
|
|
|
*copy = GST_ENCODING_CONTAINER_PROFILE (copy_profile);
|
|
|
|
GList *tmp;
|
|
|
|
|
|
|
|
for (tmp = self->encodingprofiles; tmp; tmp = tmp->next) {
|
|
|
|
gst_encoding_container_profile_add_profile (copy,
|
|
|
|
gst_encoding_profile_copy (tmp->data));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-13 15:27:52 +00:00
|
|
|
static void
|
2012-03-14 14:51:22 +00:00
|
|
|
gst_encoding_container_profile_class_init (GstEncodingContainerProfileClass * k)
|
2010-08-13 15:27:52 +00:00
|
|
|
{
|
2012-03-14 14:51:22 +00:00
|
|
|
GObjectClass *gobject_class = (GObjectClass *) k;
|
|
|
|
|
|
|
|
gobject_class->finalize = gst_encoding_container_profile_finalize;
|
2017-01-04 17:27:40 +00:00
|
|
|
|
|
|
|
((GstEncodingProfileClass *) k)->copy = gst_encoding_container_profile_copy;
|
2010-08-13 15:27:52 +00:00
|
|
|
}
|
|
|
|
|
2011-11-10 11:47:51 +00:00
|
|
|
/**
|
|
|
|
* gst_encoding_container_profile_get_profiles:
|
|
|
|
* @profile: a #GstEncodingContainerProfile
|
|
|
|
*
|
|
|
|
* Returns: (element-type GstPbutils.EncodingProfile) (transfer none):
|
2011-12-30 19:24:09 +00:00
|
|
|
* the list of contained #GstEncodingProfile.
|
|
|
|
*/
|
2010-08-13 15:27:52 +00:00
|
|
|
const GList *
|
|
|
|
gst_encoding_container_profile_get_profiles (GstEncodingContainerProfile *
|
|
|
|
profile)
|
|
|
|
{
|
2016-12-15 19:10:55 +00:00
|
|
|
g_return_val_if_fail (GST_IS_ENCODING_CONTAINER_PROFILE (profile), NULL);
|
|
|
|
|
2010-08-13 15:27:52 +00:00
|
|
|
return profile->encodingprofiles;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Video profiles */
|
|
|
|
|
|
|
|
struct _GstEncodingVideoProfile
|
|
|
|
{
|
|
|
|
GstEncodingProfile parent;
|
|
|
|
|
|
|
|
guint pass;
|
|
|
|
gboolean variableframerate;
|
|
|
|
};
|
|
|
|
|
2012-03-14 14:51:22 +00:00
|
|
|
struct _GstEncodingVideoProfileClass
|
|
|
|
{
|
|
|
|
GstEncodingProfileClass parent;
|
|
|
|
};
|
|
|
|
|
2010-08-13 15:27:52 +00:00
|
|
|
G_DEFINE_TYPE (GstEncodingVideoProfile, gst_encoding_video_profile,
|
|
|
|
GST_TYPE_ENCODING_PROFILE);
|
|
|
|
|
2017-01-04 17:27:40 +00:00
|
|
|
static void
|
|
|
|
gst_encoding_video_profile_copy (GstEncodingProfile * profile,
|
|
|
|
GstEncodingProfile * copy_profile)
|
|
|
|
{
|
|
|
|
GstEncodingVideoProfile *self = GST_ENCODING_VIDEO_PROFILE (profile),
|
|
|
|
*copy = GST_ENCODING_VIDEO_PROFILE (copy_profile);
|
|
|
|
|
|
|
|
copy->pass = self->pass;
|
|
|
|
copy->variableframerate = self->variableframerate;
|
|
|
|
}
|
|
|
|
|
2010-08-13 15:27:52 +00:00
|
|
|
static void
|
|
|
|
gst_encoding_video_profile_init (GstEncodingVideoProfile * prof)
|
|
|
|
{
|
|
|
|
/* Nothing to initialize */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-03-14 14:51:22 +00:00
|
|
|
gst_encoding_video_profile_class_init (GstEncodingVideoProfileClass * klass)
|
2010-08-13 15:27:52 +00:00
|
|
|
{
|
2017-01-04 17:27:40 +00:00
|
|
|
((GstEncodingProfileClass *) klass)->copy = gst_encoding_video_profile_copy;
|
2010-08-13 15:27:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_encoding_video_profile_get_pass:
|
|
|
|
* @prof: a #GstEncodingVideoProfile
|
|
|
|
*
|
2011-12-21 10:58:53 +00:00
|
|
|
* Get the pass number if this is part of a multi-pass profile.
|
|
|
|
*
|
|
|
|
* Returns: The pass number. Starts at 1 for multi-pass. 0 if this is
|
|
|
|
* not a multi-pass profile
|
2011-11-30 06:23:07 +00:00
|
|
|
*/
|
2010-08-13 15:27:52 +00:00
|
|
|
guint
|
|
|
|
gst_encoding_video_profile_get_pass (GstEncodingVideoProfile * prof)
|
|
|
|
{
|
2016-12-15 19:10:55 +00:00
|
|
|
g_return_val_if_fail (GST_IS_ENCODING_VIDEO_PROFILE (prof), 0);
|
|
|
|
|
2010-08-13 15:27:52 +00:00
|
|
|
return prof->pass;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_encoding_video_profile_get_variableframerate:
|
|
|
|
* @prof: a #GstEncodingVideoProfile
|
|
|
|
*
|
2020-07-04 16:33:20 +00:00
|
|
|
* > *NOTE*: Fixed framerate won't be enforced when #encodebin:avoid-reencoding
|
|
|
|
* > is set.
|
|
|
|
*
|
2010-08-13 15:27:52 +00:00
|
|
|
* Returns: Whether non-constant video framerate is allowed for encoding.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_encoding_video_profile_get_variableframerate (GstEncodingVideoProfile *
|
|
|
|
prof)
|
|
|
|
{
|
2016-12-15 19:10:55 +00:00
|
|
|
g_return_val_if_fail (GST_IS_ENCODING_VIDEO_PROFILE (prof), FALSE);
|
|
|
|
|
2010-08-13 15:27:52 +00:00
|
|
|
return prof->variableframerate;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_encoding_video_profile_set_pass:
|
|
|
|
* @prof: a #GstEncodingVideoProfile
|
|
|
|
* @pass: the pass number for this profile
|
|
|
|
*
|
|
|
|
* Sets the pass number of this video profile. The first pass profile should have
|
|
|
|
* this value set to 1. If this video profile isn't part of a multi-pass profile,
|
|
|
|
* you may set it to 0 (the default value).
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_encoding_video_profile_set_pass (GstEncodingVideoProfile * prof, guint pass)
|
|
|
|
{
|
2016-12-15 19:10:55 +00:00
|
|
|
g_return_if_fail (GST_IS_ENCODING_VIDEO_PROFILE (prof));
|
|
|
|
|
2010-08-13 15:27:52 +00:00
|
|
|
prof->pass = pass;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_encoding_video_profile_set_variableframerate:
|
|
|
|
* @prof: a #GstEncodingVideoProfile
|
|
|
|
* @variableframerate: a boolean
|
|
|
|
*
|
2011-09-13 19:10:43 +00:00
|
|
|
* If set to %TRUE, then the incoming stream will be allowed to have non-constant
|
2010-08-13 15:27:52 +00:00
|
|
|
* framerate. If set to %FALSE (default value), then the incoming stream will
|
|
|
|
* be normalized by dropping/duplicating frames in order to produce a
|
|
|
|
* constance framerate.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_encoding_video_profile_set_variableframerate (GstEncodingVideoProfile *
|
|
|
|
prof, gboolean variableframerate)
|
|
|
|
{
|
2016-12-15 19:10:55 +00:00
|
|
|
g_return_if_fail (GST_IS_ENCODING_VIDEO_PROFILE (prof));
|
|
|
|
|
2010-08-13 15:27:52 +00:00
|
|
|
prof->variableframerate = variableframerate;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Audio profiles */
|
|
|
|
|
|
|
|
struct _GstEncodingAudioProfile
|
|
|
|
{
|
|
|
|
GstEncodingProfile parent;
|
|
|
|
};
|
|
|
|
|
2012-03-14 14:51:22 +00:00
|
|
|
struct _GstEncodingAudioProfileClass
|
|
|
|
{
|
|
|
|
GstEncodingProfileClass parent;
|
|
|
|
};
|
|
|
|
|
2010-08-13 15:27:52 +00:00
|
|
|
G_DEFINE_TYPE (GstEncodingAudioProfile, gst_encoding_audio_profile,
|
|
|
|
GST_TYPE_ENCODING_PROFILE);
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_encoding_audio_profile_init (GstEncodingAudioProfile * prof)
|
|
|
|
{
|
|
|
|
/* Nothing to initialize */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-03-14 14:51:22 +00:00
|
|
|
gst_encoding_audio_profile_class_init (GstEncodingAudioProfileClass * klass)
|
2010-08-13 15:27:52 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline gboolean
|
|
|
|
_gst_caps_is_equal_safe (GstCaps * a, GstCaps * b)
|
|
|
|
{
|
|
|
|
if (a == b)
|
|
|
|
return TRUE;
|
|
|
|
if ((a == NULL) || (b == NULL))
|
|
|
|
return FALSE;
|
|
|
|
return gst_caps_is_equal (a, b);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
_compare_container_encoding_profiles (GstEncodingContainerProfile * ca,
|
|
|
|
GstEncodingContainerProfile * cb)
|
|
|
|
{
|
|
|
|
GList *tmp;
|
|
|
|
|
|
|
|
if (g_list_length (ca->encodingprofiles) !=
|
|
|
|
g_list_length (cb->encodingprofiles))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
for (tmp = ca->encodingprofiles; tmp; tmp = tmp->next) {
|
|
|
|
GstEncodingProfile *prof = (GstEncodingProfile *) tmp->data;
|
|
|
|
if (!gst_encoding_container_profile_contains_profile (ca, prof))
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
_compare_encoding_profiles (const GstEncodingProfile * a,
|
|
|
|
const GstEncodingProfile * b)
|
|
|
|
{
|
|
|
|
if ((G_TYPE_FROM_INSTANCE (a) != G_TYPE_FROM_INSTANCE (b)) ||
|
|
|
|
!_gst_caps_is_equal_safe (a->format, b->format) ||
|
|
|
|
(g_strcmp0 (a->preset, b->preset) != 0) ||
|
2016-12-21 22:32:41 +00:00
|
|
|
(g_strcmp0 (a->preset_name, b->preset_name) != 0) ||
|
2010-08-13 15:27:52 +00:00
|
|
|
(g_strcmp0 (a->name, b->name) != 0) ||
|
|
|
|
(g_strcmp0 (a->description, b->description) != 0))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (GST_IS_ENCODING_CONTAINER_PROFILE (a))
|
|
|
|
return
|
|
|
|
_compare_container_encoding_profiles (GST_ENCODING_CONTAINER_PROFILE
|
|
|
|
(a), GST_ENCODING_CONTAINER_PROFILE (b));
|
|
|
|
|
|
|
|
if (GST_IS_ENCODING_VIDEO_PROFILE (a)) {
|
|
|
|
GstEncodingVideoProfile *va = (GstEncodingVideoProfile *) a;
|
|
|
|
GstEncodingVideoProfile *vb = (GstEncodingVideoProfile *) b;
|
|
|
|
|
|
|
|
if ((va->pass != vb->pass)
|
|
|
|
|| (va->variableframerate != vb->variableframerate))
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_encoding_container_profile_contains_profile:
|
|
|
|
* @container: a #GstEncodingContainerProfile
|
|
|
|
* @profile: a #GstEncodingProfile
|
|
|
|
*
|
|
|
|
* Checks if @container contains a #GstEncodingProfile identical to
|
|
|
|
* @profile.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if @container contains a #GstEncodingProfile identical
|
|
|
|
* to @profile, else %FALSE.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_encoding_container_profile_contains_profile (GstEncodingContainerProfile *
|
|
|
|
container, GstEncodingProfile * profile)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GST_IS_ENCODING_CONTAINER_PROFILE (container), FALSE);
|
|
|
|
g_return_val_if_fail (GST_IS_ENCODING_PROFILE (profile), FALSE);
|
|
|
|
|
|
|
|
return (g_list_find_custom (container->encodingprofiles, profile,
|
|
|
|
(GCompareFunc) _compare_encoding_profiles) != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_encoding_container_profile_add_profile:
|
|
|
|
* @container: the #GstEncodingContainerProfile to use
|
2012-07-23 21:08:13 +00:00
|
|
|
* @profile: (transfer full): the #GstEncodingProfile to add.
|
2010-08-13 15:27:52 +00:00
|
|
|
*
|
|
|
|
* Add a #GstEncodingProfile to the list of profiles handled by @container.
|
2012-12-05 18:21:43 +00:00
|
|
|
*
|
2010-08-13 15:27:52 +00:00
|
|
|
* No copy of @profile will be made, if you wish to use it elsewhere after this
|
|
|
|
* method you should increment its reference count.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the @stream was properly added, else %FALSE.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_encoding_container_profile_add_profile (GstEncodingContainerProfile *
|
|
|
|
container, GstEncodingProfile * profile)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GST_IS_ENCODING_CONTAINER_PROFILE (container), FALSE);
|
|
|
|
g_return_val_if_fail (GST_IS_ENCODING_PROFILE (profile), FALSE);
|
|
|
|
|
|
|
|
container->encodingprofiles =
|
|
|
|
g_list_append (container->encodingprofiles, profile);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstEncodingProfile *
|
|
|
|
common_creation (GType objtype, GstCaps * format, const gchar * preset,
|
|
|
|
const gchar * name, const gchar * description, GstCaps * restriction,
|
|
|
|
guint presence)
|
|
|
|
{
|
|
|
|
GstEncodingProfile *prof;
|
|
|
|
|
2011-02-23 13:12:22 +00:00
|
|
|
prof = (GstEncodingProfile *) g_object_new (objtype, NULL);
|
2010-08-13 15:27:52 +00:00
|
|
|
|
|
|
|
if (name)
|
|
|
|
prof->name = g_strdup (name);
|
|
|
|
if (description)
|
|
|
|
prof->description = g_strdup (description);
|
|
|
|
if (preset)
|
|
|
|
prof->preset = g_strdup (preset);
|
|
|
|
if (format)
|
|
|
|
prof->format = gst_caps_ref (format);
|
|
|
|
if (restriction)
|
|
|
|
prof->restriction = gst_caps_ref (restriction);
|
|
|
|
prof->presence = presence;
|
2012-12-05 18:21:43 +00:00
|
|
|
prof->preset_name = NULL;
|
2014-11-16 14:54:56 +00:00
|
|
|
prof->allow_dynamic_output = TRUE;
|
2015-05-07 08:26:47 +00:00
|
|
|
prof->enabled = TRUE;
|
2010-08-13 15:27:52 +00:00
|
|
|
|
|
|
|
return prof;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_encoding_container_profile_new:
|
2011-12-14 12:28:26 +00:00
|
|
|
* @name: (allow-none): The name of the container profile, can be %NULL
|
|
|
|
* @description: (allow-none): The description of the container profile,
|
|
|
|
* can be %NULL
|
2017-04-09 09:19:22 +00:00
|
|
|
* @format: (transfer none): The format to use for this profile
|
2012-12-05 18:22:42 +00:00
|
|
|
* @preset: (allow-none): The preset to use for this profile.
|
2010-08-13 15:27:52 +00:00
|
|
|
*
|
|
|
|
* Creates a new #GstEncodingContainerProfile.
|
|
|
|
*
|
|
|
|
* Returns: The newly created #GstEncodingContainerProfile.
|
|
|
|
*/
|
|
|
|
GstEncodingContainerProfile *
|
|
|
|
gst_encoding_container_profile_new (const gchar * name,
|
|
|
|
const gchar * description, GstCaps * format, const gchar * preset)
|
|
|
|
{
|
2010-12-21 12:08:15 +00:00
|
|
|
g_return_val_if_fail (GST_IS_CAPS (format), NULL);
|
|
|
|
|
2010-08-13 15:27:52 +00:00
|
|
|
return (GstEncodingContainerProfile *)
|
|
|
|
common_creation (GST_TYPE_ENCODING_CONTAINER_PROFILE, format, preset,
|
|
|
|
name, description, NULL, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_encoding_video_profile_new:
|
2017-04-09 09:19:22 +00:00
|
|
|
* @format: (transfer none): the #GstCaps
|
2017-10-03 21:31:18 +00:00
|
|
|
* @preset: (allow-none): the preset(s) to use on the encoder, can be %NULL
|
2012-12-04 16:16:09 +00:00
|
|
|
* @restriction: (allow-none): the #GstCaps used to restrict the input to the encoder, can be
|
2011-01-04 20:20:34 +00:00
|
|
|
* NULL. See gst_encoding_profile_get_restriction() for more details.
|
2010-08-13 15:27:52 +00:00
|
|
|
* @presence: the number of time this stream must be used. 0 means any number of
|
|
|
|
* times (including never)
|
|
|
|
*
|
|
|
|
* Creates a new #GstEncodingVideoProfile
|
|
|
|
*
|
|
|
|
* All provided allocatable arguments will be internally copied, so can be
|
|
|
|
* safely freed/unreferenced after calling this method.
|
|
|
|
*
|
|
|
|
* If you wish to control the pass number (in case of multi-pass scenarios),
|
|
|
|
* please refer to the gst_encoding_video_profile_set_pass() documentation.
|
|
|
|
*
|
|
|
|
* If you wish to use/force a constant framerate please refer to the
|
|
|
|
* gst_encoding_video_profile_set_variableframerate() documentation.
|
|
|
|
*
|
|
|
|
* Returns: the newly created #GstEncodingVideoProfile.
|
|
|
|
*/
|
|
|
|
GstEncodingVideoProfile *
|
|
|
|
gst_encoding_video_profile_new (GstCaps * format, const gchar * preset,
|
|
|
|
GstCaps * restriction, guint presence)
|
|
|
|
{
|
|
|
|
return (GstEncodingVideoProfile *)
|
|
|
|
common_creation (GST_TYPE_ENCODING_VIDEO_PROFILE, format, preset, NULL,
|
|
|
|
NULL, restriction, presence);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_encoding_audio_profile_new:
|
2017-04-09 09:19:22 +00:00
|
|
|
* @format: (transfer none): the #GstCaps
|
2017-10-03 21:31:18 +00:00
|
|
|
* @preset: (allow-none): the preset(s) to use on the encoder, can be %NULL
|
2011-12-14 17:34:55 +00:00
|
|
|
* @restriction: (allow-none): the #GstCaps used to restrict the input to the encoder, can be
|
2011-01-04 20:20:34 +00:00
|
|
|
* NULL. See gst_encoding_profile_get_restriction() for more details.
|
2010-08-13 15:27:52 +00:00
|
|
|
* @presence: the number of time this stream must be used. 0 means any number of
|
|
|
|
* times (including never)
|
|
|
|
*
|
|
|
|
* Creates a new #GstEncodingAudioProfile
|
|
|
|
*
|
|
|
|
* All provided allocatable arguments will be internally copied, so can be
|
|
|
|
* safely freed/unreferenced after calling this method.
|
|
|
|
*
|
|
|
|
* Returns: the newly created #GstEncodingAudioProfile.
|
|
|
|
*/
|
|
|
|
GstEncodingAudioProfile *
|
|
|
|
gst_encoding_audio_profile_new (GstCaps * format, const gchar * preset,
|
|
|
|
GstCaps * restriction, guint presence)
|
|
|
|
{
|
|
|
|
return (GstEncodingAudioProfile *)
|
|
|
|
common_creation (GST_TYPE_ENCODING_AUDIO_PROFILE, format, preset, NULL,
|
|
|
|
NULL, restriction, presence);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_encoding_profile_is_equal:
|
|
|
|
* @a: a #GstEncodingProfile
|
|
|
|
* @b: a #GstEncodingProfile
|
|
|
|
*
|
|
|
|
* Checks whether the two #GstEncodingProfile are equal
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if @a and @b are equal, else %FALSE.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_encoding_profile_is_equal (GstEncodingProfile * a, GstEncodingProfile * b)
|
|
|
|
{
|
2016-12-15 19:10:55 +00:00
|
|
|
g_return_val_if_fail (GST_IS_ENCODING_PROFILE (a), FALSE);
|
|
|
|
g_return_val_if_fail (GST_IS_ENCODING_PROFILE (b), FALSE);
|
|
|
|
|
2010-08-13 15:27:52 +00:00
|
|
|
return (_compare_encoding_profiles (a, b) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2011-01-05 21:02:35 +00:00
|
|
|
* gst_encoding_profile_get_input_caps:
|
2010-08-13 15:27:52 +00:00
|
|
|
* @profile: a #GstEncodingProfile
|
|
|
|
*
|
|
|
|
* Computes the full output caps that this @profile will be able to consume.
|
|
|
|
*
|
2011-05-17 10:47:32 +00:00
|
|
|
* Returns: (transfer full): The full caps the given @profile can consume. Call
|
|
|
|
* gst_caps_unref() when you are done with the caps.
|
2010-08-13 15:27:52 +00:00
|
|
|
*/
|
|
|
|
GstCaps *
|
2011-01-05 21:02:35 +00:00
|
|
|
gst_encoding_profile_get_input_caps (GstEncodingProfile * profile)
|
2010-08-13 15:27:52 +00:00
|
|
|
{
|
|
|
|
GstCaps *out, *tmp;
|
|
|
|
GList *ltmp;
|
|
|
|
GstStructure *st, *outst;
|
|
|
|
GQuark out_name;
|
|
|
|
guint i, len;
|
2011-05-17 10:47:32 +00:00
|
|
|
GstCaps *fcaps;
|
2010-08-13 15:27:52 +00:00
|
|
|
|
2016-12-15 19:10:55 +00:00
|
|
|
g_return_val_if_fail (GST_IS_ENCODING_PROFILE (profile), NULL);
|
|
|
|
|
2010-08-13 15:27:52 +00:00
|
|
|
if (GST_IS_ENCODING_CONTAINER_PROFILE (profile)) {
|
|
|
|
GstCaps *res = gst_caps_new_empty ();
|
|
|
|
|
|
|
|
for (ltmp = GST_ENCODING_CONTAINER_PROFILE (profile)->encodingprofiles;
|
|
|
|
ltmp; ltmp = ltmp->next) {
|
|
|
|
GstEncodingProfile *sprof = (GstEncodingProfile *) ltmp->data;
|
2012-03-11 18:04:41 +00:00
|
|
|
res = gst_caps_merge (res, gst_encoding_profile_get_input_caps (sprof));
|
2010-08-13 15:27:52 +00:00
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
fcaps = profile->format;
|
|
|
|
|
|
|
|
/* fast-path */
|
|
|
|
if ((profile->restriction == NULL) || gst_caps_is_any (profile->restriction))
|
2011-05-17 10:47:32 +00:00
|
|
|
return gst_caps_ref (fcaps);
|
2010-08-13 15:27:52 +00:00
|
|
|
|
|
|
|
/* Combine the format with the restriction caps */
|
|
|
|
outst = gst_caps_get_structure (fcaps, 0);
|
|
|
|
out_name = gst_structure_get_name_id (outst);
|
|
|
|
tmp = gst_caps_new_empty ();
|
|
|
|
len = gst_caps_get_size (profile->restriction);
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
st = gst_structure_copy (gst_caps_get_structure (profile->restriction, i));
|
|
|
|
st->name = out_name;
|
|
|
|
gst_caps_append_structure (tmp, st);
|
|
|
|
}
|
|
|
|
|
|
|
|
out = gst_caps_intersect (tmp, fcaps);
|
|
|
|
gst_caps_unref (tmp);
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_encoding_profile_get_type_nick:
|
|
|
|
* @profile: a #GstEncodingProfile
|
|
|
|
*
|
|
|
|
* Returns: the human-readable name of the type of @profile.
|
|
|
|
*/
|
|
|
|
const gchar *
|
|
|
|
gst_encoding_profile_get_type_nick (GstEncodingProfile * profile)
|
|
|
|
{
|
|
|
|
if (GST_IS_ENCODING_CONTAINER_PROFILE (profile))
|
|
|
|
return "container";
|
|
|
|
if (GST_IS_ENCODING_VIDEO_PROFILE (profile))
|
|
|
|
return "video";
|
|
|
|
if (GST_IS_ENCODING_AUDIO_PROFILE (profile))
|
|
|
|
return "audio";
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-12-22 17:18:00 +00:00
|
|
|
|
2012-12-23 15:26:59 +00:00
|
|
|
extern const gchar *pb_utils_get_file_extension_from_caps (const GstCaps *
|
|
|
|
caps);
|
|
|
|
gboolean pb_utils_is_tag (const GstCaps * caps);
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_encoding_profile_has_format (GstEncodingProfile * profile,
|
|
|
|
const gchar * media_type)
|
|
|
|
{
|
|
|
|
GstCaps *caps;
|
|
|
|
gboolean ret;
|
|
|
|
|
2016-12-15 19:10:55 +00:00
|
|
|
g_return_val_if_fail (GST_IS_ENCODING_PROFILE (profile), FALSE);
|
|
|
|
|
2012-12-23 15:26:59 +00:00
|
|
|
caps = gst_encoding_profile_get_format (profile);
|
|
|
|
ret = gst_structure_has_name (gst_caps_get_structure (caps, 0), media_type);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_encoding_container_profile_has_video (GstEncodingContainerProfile * profile)
|
|
|
|
{
|
|
|
|
const GList *l;
|
|
|
|
|
2016-12-15 19:10:55 +00:00
|
|
|
g_return_val_if_fail (GST_IS_ENCODING_CONTAINER_PROFILE (profile), FALSE);
|
|
|
|
|
2012-12-23 15:26:59 +00:00
|
|
|
for (l = profile->encodingprofiles; l != NULL; l = l->next) {
|
|
|
|
if (GST_IS_ENCODING_VIDEO_PROFILE (l->data))
|
|
|
|
return TRUE;
|
|
|
|
if (GST_IS_ENCODING_CONTAINER_PROFILE (l->data) &&
|
|
|
|
gst_encoding_container_profile_has_video (l->data))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_encoding_profile_get_file_extension:
|
|
|
|
* @profile: a #GstEncodingProfile
|
|
|
|
*
|
|
|
|
* Returns: a suitable file extension for @profile, or NULL.
|
|
|
|
*/
|
|
|
|
const gchar *
|
|
|
|
gst_encoding_profile_get_file_extension (GstEncodingProfile * profile)
|
|
|
|
{
|
|
|
|
GstEncodingContainerProfile *cprofile;
|
|
|
|
const gchar *ext = NULL;
|
|
|
|
gboolean has_video;
|
|
|
|
GstCaps *caps;
|
|
|
|
guint num_children;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_ENCODING_PROFILE (profile), NULL);
|
|
|
|
|
|
|
|
caps = gst_encoding_profile_get_format (profile);
|
|
|
|
ext = pb_utils_get_file_extension_from_caps (caps);
|
|
|
|
|
|
|
|
if (!GST_IS_ENCODING_CONTAINER_PROFILE (profile))
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
cprofile = GST_ENCODING_CONTAINER_PROFILE (profile);
|
|
|
|
|
|
|
|
num_children = g_list_length (cprofile->encodingprofiles);
|
|
|
|
|
|
|
|
/* if it's a tag container profile (e.g. id3mux/apemux), we need
|
|
|
|
* to look at what's inside it */
|
|
|
|
if (pb_utils_is_tag (caps)) {
|
|
|
|
GST_DEBUG ("tag container profile");
|
|
|
|
if (num_children == 1) {
|
|
|
|
GstEncodingProfile *child_profile = cprofile->encodingprofiles->data;
|
|
|
|
|
|
|
|
ext = gst_encoding_profile_get_file_extension (child_profile);
|
|
|
|
} else {
|
|
|
|
GST_WARNING ("expected exactly one child profile with tag profile");
|
|
|
|
}
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2012-12-23 15:51:51 +00:00
|
|
|
if (num_children == 0)
|
|
|
|
goto done;
|
|
|
|
|
2012-12-23 15:26:59 +00:00
|
|
|
/* special cases */
|
|
|
|
has_video = gst_encoding_container_profile_has_video (cprofile);
|
|
|
|
|
2012-12-23 15:51:51 +00:00
|
|
|
/* Ogg */
|
2020-11-10 22:26:39 +00:00
|
|
|
if (g_strcmp0 (ext, "ogg") == 0) {
|
2012-12-23 15:26:59 +00:00
|
|
|
/* ogg with video => .ogv */
|
|
|
|
if (has_video) {
|
|
|
|
ext = "ogv";
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
/* ogg with just speex audio => .spx */
|
|
|
|
if (num_children == 1) {
|
|
|
|
GstEncodingProfile *child_profile = cprofile->encodingprofiles->data;
|
|
|
|
|
|
|
|
if (GST_IS_ENCODING_AUDIO_PROFILE (child_profile) &&
|
|
|
|
gst_encoding_profile_has_format (child_profile, "audio/x-speex")) {
|
|
|
|
ext = "spx";
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* does anyone actually use .oga for ogg audio files? */
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2012-12-23 15:51:51 +00:00
|
|
|
/* Matroska */
|
2020-11-10 22:26:39 +00:00
|
|
|
if (has_video && g_strcmp0 (ext, "mka") == 0) {
|
2012-12-23 15:26:59 +00:00
|
|
|
ext = "mkv";
|
2012-12-23 15:51:51 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Windows Media / ASF */
|
|
|
|
if (gst_encoding_profile_has_format (profile, "video/x-ms-asf")) {
|
|
|
|
const GList *l;
|
|
|
|
guint num_wmv = 0, num_wma = 0, num_other = 0;
|
|
|
|
|
|
|
|
for (l = cprofile->encodingprofiles; l != NULL; l = l->next) {
|
|
|
|
if (gst_encoding_profile_has_format (l->data, "video/x-wmv"))
|
|
|
|
++num_wmv;
|
|
|
|
else if (gst_encoding_profile_has_format (l->data, "audio/x-wma"))
|
|
|
|
++num_wma;
|
|
|
|
else
|
|
|
|
++num_other;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (num_other > 0)
|
|
|
|
ext = "asf";
|
|
|
|
else if (num_wmv > 0)
|
|
|
|
ext = "wmv";
|
|
|
|
else if (num_wma > 0)
|
|
|
|
ext = "wma";
|
|
|
|
|
|
|
|
goto done;
|
|
|
|
}
|
2012-12-23 15:26:59 +00:00
|
|
|
|
|
|
|
done:
|
|
|
|
|
|
|
|
GST_INFO ("caps %" GST_PTR_FORMAT ", ext: %s", caps, GST_STR_NULL (ext));
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
return ext;
|
|
|
|
}
|
|
|
|
|
2010-12-22 17:18:00 +00:00
|
|
|
/**
|
|
|
|
* gst_encoding_profile_find:
|
|
|
|
* @targetname: (transfer none): The name of the target
|
2018-03-18 18:15:55 +00:00
|
|
|
* @profilename: (transfer none) (allow-none): The name of the profile, if %NULL
|
2015-11-02 10:34:56 +00:00
|
|
|
* provided, it will default to the encoding profile called `default`.
|
2010-12-22 17:18:00 +00:00
|
|
|
* @category: (transfer none) (allow-none): The target category. Can be %NULL
|
|
|
|
*
|
|
|
|
* Find the #GstEncodingProfile with the specified name and category.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): The matching #GstEncodingProfile or %NULL.
|
|
|
|
*/
|
|
|
|
GstEncodingProfile *
|
|
|
|
gst_encoding_profile_find (const gchar * targetname, const gchar * profilename,
|
|
|
|
const gchar * category)
|
|
|
|
{
|
|
|
|
GstEncodingProfile *res = NULL;
|
|
|
|
GstEncodingTarget *target;
|
|
|
|
|
|
|
|
g_return_val_if_fail (targetname != NULL, NULL);
|
|
|
|
|
|
|
|
target = gst_encoding_target_load (targetname, category, NULL);
|
|
|
|
if (target) {
|
2015-11-02 10:34:56 +00:00
|
|
|
res =
|
|
|
|
gst_encoding_target_get_profile (target,
|
|
|
|
profilename ? profilename : "default");
|
2010-12-22 17:18:00 +00:00
|
|
|
gst_encoding_target_unref (target);
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstEncodingProfile *
|
|
|
|
combo_search (const gchar * pname)
|
|
|
|
{
|
2016-12-23 21:08:43 +00:00
|
|
|
GstEncodingProfile *res = NULL;
|
2010-12-22 17:18:00 +00:00
|
|
|
gchar **split;
|
2015-10-27 11:50:26 +00:00
|
|
|
gint split_length;
|
2010-12-22 17:18:00 +00:00
|
|
|
|
|
|
|
/* Splitup */
|
2015-10-27 11:50:26 +00:00
|
|
|
split = g_strsplit (pname, "/", 3);
|
|
|
|
split_length = g_strv_length (split);
|
2016-12-16 12:58:15 +00:00
|
|
|
if (split_length > 3)
|
2016-12-23 17:23:48 +00:00
|
|
|
goto done;
|
2010-12-22 17:18:00 +00:00
|
|
|
|
2016-12-16 12:58:15 +00:00
|
|
|
res = gst_encoding_profile_find (split[0],
|
|
|
|
split_length == 2 ? split[1] : NULL, split_length == 3 ? split[2] : NULL);
|
2010-12-22 17:18:00 +00:00
|
|
|
|
2016-12-23 17:23:48 +00:00
|
|
|
|
|
|
|
done:
|
2010-12-22 17:18:00 +00:00
|
|
|
g_strfreev (split);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2016-12-23 17:23:48 +00:00
|
|
|
static GstCaps *
|
|
|
|
get_profile_format_from_possible_factory_name (const gchar * factory_desc,
|
2020-11-13 19:32:45 +00:00
|
|
|
gchar ** new_factory_name, GstCaps ** restrictions,
|
|
|
|
gboolean * is_rendering_muxer)
|
2015-12-11 14:38:00 +00:00
|
|
|
{
|
2016-12-23 17:23:48 +00:00
|
|
|
GList *tmp;
|
|
|
|
GstCaps *caps = NULL, *tmpcaps = gst_caps_from_string (factory_desc);
|
|
|
|
GstStructure *tmpstruct;
|
2016-12-23 21:08:43 +00:00
|
|
|
GstElementFactory *fact = NULL;
|
2015-12-11 14:38:00 +00:00
|
|
|
|
2020-11-13 19:32:45 +00:00
|
|
|
if (is_rendering_muxer)
|
|
|
|
*is_rendering_muxer = FALSE;
|
2016-12-23 17:23:48 +00:00
|
|
|
*new_factory_name = NULL;
|
|
|
|
if (gst_caps_get_size (tmpcaps) != 1)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
tmpstruct = gst_caps_get_structure (tmpcaps, 0);
|
|
|
|
fact = gst_element_factory_find (gst_structure_get_name (tmpstruct));
|
|
|
|
if (!fact)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
if (!gst_element_factory_list_is_type (fact,
|
|
|
|
GST_ELEMENT_FACTORY_TYPE_ENCODER | GST_ELEMENT_FACTORY_TYPE_MUXER)) {
|
|
|
|
GST_ERROR_OBJECT (fact,
|
|
|
|
"is not an encoder or muxer, it can't be"
|
|
|
|
" used in an encoding profile.");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (tmp = (GList *) gst_element_factory_get_static_pad_templates (fact);
|
|
|
|
tmp; tmp = tmp->next) {
|
|
|
|
GstStaticPadTemplate *templ = ((GstStaticPadTemplate *) tmp->data);
|
|
|
|
|
|
|
|
if (templ->direction == GST_PAD_SRC) {
|
2018-04-23 19:50:26 +00:00
|
|
|
GstCaps *tmpcaps = gst_static_caps_get (&templ->static_caps);
|
|
|
|
|
|
|
|
if (gst_caps_get_size (tmpcaps) > 0)
|
|
|
|
caps =
|
|
|
|
gst_caps_new_empty_simple (gst_structure_get_name
|
|
|
|
(gst_caps_get_structure (tmpcaps, 0)));
|
|
|
|
|
|
|
|
gst_caps_unref (tmpcaps);
|
|
|
|
if (caps)
|
|
|
|
break;
|
2015-12-11 14:38:00 +00:00
|
|
|
}
|
2016-12-23 17:23:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (caps) {
|
|
|
|
*new_factory_name = g_strdup (gst_structure_get_name (tmpstruct));
|
|
|
|
|
|
|
|
if (gst_structure_n_fields (tmpstruct) && restrictions) {
|
|
|
|
const gchar *sname =
|
|
|
|
gst_structure_get_name (gst_caps_get_structure (caps, 0));
|
|
|
|
|
|
|
|
if (g_str_has_prefix (sname, "audio/"))
|
|
|
|
gst_structure_set_name (tmpstruct, "audio/x-raw");
|
|
|
|
else if (g_str_has_prefix (sname, "video/") ||
|
|
|
|
g_str_has_prefix (sname, "image/"))
|
|
|
|
gst_structure_set_name (tmpstruct, "video/x-raw");
|
|
|
|
|
|
|
|
*restrictions = tmpcaps;
|
|
|
|
tmpcaps = NULL;
|
|
|
|
}
|
2020-11-13 19:32:45 +00:00
|
|
|
} else if (gst_element_factory_list_is_type (fact,
|
|
|
|
GST_ELEMENT_FACTORY_TYPE_MUXER)) {
|
|
|
|
*new_factory_name = g_strdup (gst_structure_get_name (tmpstruct));
|
2016-12-23 17:23:48 +00:00
|
|
|
|
2020-11-13 19:32:45 +00:00
|
|
|
caps = gst_caps_ref (gst_caps_new_empty ());
|
|
|
|
if (is_rendering_muxer)
|
|
|
|
*is_rendering_muxer = TRUE;
|
2016-12-23 17:23:48 +00:00
|
|
|
}
|
|
|
|
|
2020-11-13 19:32:45 +00:00
|
|
|
|
2016-12-23 17:23:48 +00:00
|
|
|
done:
|
|
|
|
if (fact)
|
|
|
|
gst_object_unref (fact);
|
|
|
|
|
|
|
|
if (tmpcaps)
|
|
|
|
gst_caps_unref (tmpcaps);
|
|
|
|
|
|
|
|
return caps;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstEncodingProfile *
|
|
|
|
create_encoding_profile_from_caps (GstCaps * caps, gchar * preset_name,
|
2019-08-30 21:16:35 +00:00
|
|
|
GstCaps * restrictioncaps, gint presence, gboolean single_segment,
|
|
|
|
gchar * factory_name, GList * muxers_and_encoders, GstCaps * raw_audio_caps,
|
2020-11-13 19:32:45 +00:00
|
|
|
GstCaps * raw_video_caps, gboolean is_rendering_muxer)
|
2016-12-23 17:23:48 +00:00
|
|
|
{
|
|
|
|
GstEncodingProfile *profile = NULL;
|
2018-04-23 19:50:26 +00:00
|
|
|
GList *factories = NULL;
|
|
|
|
gboolean is_raw_audio = FALSE, is_raw_video = FALSE;
|
|
|
|
|
2020-11-13 19:32:45 +00:00
|
|
|
if (is_rendering_muxer) {
|
|
|
|
profile =
|
|
|
|
GST_ENCODING_PROFILE (gst_encoding_container_profile_new
|
|
|
|
("User profile", "User profile", caps, NULL));
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2018-04-23 19:50:26 +00:00
|
|
|
if (gst_caps_can_intersect (raw_audio_caps, caps)) {
|
|
|
|
is_raw_audio = TRUE;
|
|
|
|
} else if (gst_caps_can_intersect (raw_video_caps, caps)) {
|
|
|
|
is_raw_video = TRUE;
|
|
|
|
} else {
|
|
|
|
factories = gst_element_factory_list_filter (muxers_and_encoders, caps,
|
|
|
|
GST_PAD_SRC, FALSE);
|
|
|
|
|
|
|
|
if (!factories) {
|
|
|
|
GST_INFO ("Could not find factory for %" GST_PTR_FORMAT, caps);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2016-12-23 17:23:48 +00:00
|
|
|
|
2018-04-23 19:50:26 +00:00
|
|
|
if (is_raw_audio || (factories
|
|
|
|
&& gst_element_factory_list_is_type (factories->data,
|
|
|
|
GST_ELEMENT_FACTORY_TYPE_AUDIO_ENCODER)))
|
|
|
|
profile =
|
|
|
|
GST_ENCODING_PROFILE (gst_encoding_audio_profile_new (caps, preset_name,
|
|
|
|
restrictioncaps, presence));
|
|
|
|
else if (is_raw_video || (factories
|
|
|
|
&& gst_element_factory_list_is_type (factories->data,
|
|
|
|
GST_ELEMENT_FACTORY_TYPE_VIDEO_ENCODER)))
|
|
|
|
profile =
|
|
|
|
GST_ENCODING_PROFILE (gst_encoding_video_profile_new (caps, preset_name,
|
|
|
|
restrictioncaps, presence));
|
|
|
|
else if (gst_element_factory_list_is_type (factories->data,
|
|
|
|
GST_ELEMENT_FACTORY_TYPE_MUXER))
|
|
|
|
profile =
|
|
|
|
GST_ENCODING_PROFILE (gst_encoding_container_profile_new
|
|
|
|
("User profile", "User profile", caps, NULL));
|
2016-12-23 17:23:48 +00:00
|
|
|
|
2021-01-08 11:39:32 +00:00
|
|
|
if (factories)
|
|
|
|
gst_plugin_feature_list_free (factories);
|
|
|
|
|
2020-11-13 19:32:45 +00:00
|
|
|
done:
|
2016-12-23 17:23:48 +00:00
|
|
|
if (factory_name && profile)
|
|
|
|
gst_encoding_profile_set_preset_name (profile, factory_name);
|
2019-08-30 21:16:35 +00:00
|
|
|
gst_encoding_profile_set_single_segment (profile, single_segment);
|
2016-12-23 17:23:48 +00:00
|
|
|
|
|
|
|
g_free (factory_name);
|
|
|
|
|
|
|
|
return profile;
|
|
|
|
}
|
|
|
|
|
2020-11-20 21:35:49 +00:00
|
|
|
static gboolean
|
|
|
|
gst_structure_validate_name (const gchar * name)
|
|
|
|
{
|
|
|
|
const gchar *s;
|
|
|
|
|
|
|
|
g_return_val_if_fail (name != NULL, FALSE);
|
|
|
|
|
|
|
|
if (G_UNLIKELY (!g_ascii_isalpha (*name)))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* FIXME: test name string more */
|
|
|
|
s = &name[1];
|
|
|
|
while (*s && (g_ascii_isalnum (*s) || strchr ("/-_.:+", *s) != NULL))
|
|
|
|
s++;
|
|
|
|
|
|
|
|
if (*s == ',')
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (G_UNLIKELY (*s != '\0'))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2016-12-23 17:23:48 +00:00
|
|
|
static GstEncodingProfile *
|
2018-04-23 19:50:26 +00:00
|
|
|
create_encoding_stream_profile (gchar * serialized_profile,
|
|
|
|
GList * muxers_and_encoders, GstCaps * raw_audio_caps,
|
|
|
|
GstCaps * raw_video_caps)
|
2016-12-23 17:23:48 +00:00
|
|
|
{
|
|
|
|
GstCaps *caps;
|
|
|
|
guint presence = 0;
|
2019-08-30 21:16:35 +00:00
|
|
|
gboolean single_segment = FALSE;
|
|
|
|
gchar *strcaps, *strpresence, **strprops_v, **restriction_format,
|
2020-03-19 20:02:57 +00:00
|
|
|
**preset_v, *preset_name = NULL, *factory_name = NULL,
|
|
|
|
*variable_framerate = NULL;
|
2020-11-20 21:35:49 +00:00
|
|
|
GstStructure *element_properties = NULL;
|
2016-12-23 17:23:48 +00:00
|
|
|
GstCaps *restrictioncaps = NULL;
|
|
|
|
GstEncodingProfile *profile = NULL;
|
|
|
|
|
|
|
|
restriction_format = g_strsplit (serialized_profile, "->", 0);
|
|
|
|
if (restriction_format[1]) {
|
|
|
|
restrictioncaps = gst_caps_from_string (restriction_format[0]);
|
|
|
|
strcaps = g_strdup (restriction_format[1]);
|
2015-12-11 14:38:00 +00:00
|
|
|
} else {
|
2016-12-23 17:23:48 +00:00
|
|
|
restrictioncaps = NULL;
|
|
|
|
strcaps = g_strdup (restriction_format[0]);
|
2015-12-11 14:38:00 +00:00
|
|
|
}
|
2016-12-23 17:23:48 +00:00
|
|
|
g_strfreev (restriction_format);
|
2015-12-11 14:38:00 +00:00
|
|
|
|
2016-12-23 17:23:48 +00:00
|
|
|
preset_v = g_strsplit (strcaps, "+", 0);
|
|
|
|
if (preset_v[1]) {
|
|
|
|
strpresence = preset_v[1];
|
|
|
|
g_free (strcaps);
|
|
|
|
strcaps = g_strdup (preset_v[0]);
|
|
|
|
} else {
|
|
|
|
strpresence = preset_v[0];
|
|
|
|
}
|
|
|
|
|
2019-08-30 21:16:35 +00:00
|
|
|
strprops_v = g_strsplit (strpresence, "|", 0);
|
|
|
|
if (strprops_v[1]) { /* We have a properties */
|
2016-12-23 17:23:48 +00:00
|
|
|
gchar *endptr;
|
2019-08-30 21:16:35 +00:00
|
|
|
guint propi;
|
2016-12-23 17:23:48 +00:00
|
|
|
|
2019-08-30 21:16:35 +00:00
|
|
|
if (preset_v[1]) { /* We have preset and properties */
|
|
|
|
preset_name = g_strdup (strprops_v[0]);
|
|
|
|
} else { /* We have a properties but no preset */
|
2016-12-23 17:23:48 +00:00
|
|
|
g_free (strcaps);
|
2019-08-30 21:16:35 +00:00
|
|
|
strcaps = g_strdup (strprops_v[0]);
|
2015-12-11 14:38:00 +00:00
|
|
|
}
|
|
|
|
|
2019-08-30 21:16:35 +00:00
|
|
|
for (propi = 1; strprops_v[propi]; propi++) {
|
2020-11-20 21:35:49 +00:00
|
|
|
gchar **propv;
|
2019-08-30 21:16:35 +00:00
|
|
|
gchar *presence_str = NULL;
|
2020-11-20 21:35:49 +00:00
|
|
|
gchar *prop = strprops_v[propi];
|
|
|
|
GstStructure *tmpstruct = NULL;
|
2016-12-23 17:23:48 +00:00
|
|
|
|
2020-11-20 21:35:49 +00:00
|
|
|
if (gst_structure_validate_name (prop))
|
|
|
|
tmpstruct = gst_structure_new_from_string (prop);
|
|
|
|
if (tmpstruct) {
|
|
|
|
if (element_properties)
|
|
|
|
gst_structure_free (element_properties);
|
|
|
|
|
|
|
|
element_properties = tmpstruct;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
propv = g_strsplit (prop, "=", -1);
|
2019-08-30 21:16:35 +00:00
|
|
|
if (propv[1] && propv[2]) {
|
|
|
|
g_warning ("Wrong format for property: %s, only 1 `=` is expected",
|
2020-11-20 21:35:49 +00:00
|
|
|
prop);
|
2019-08-30 21:16:35 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!propv[1]) {
|
|
|
|
presence_str = propv[0];
|
|
|
|
} else if (!g_strcmp0 (propv[0], "presence")) {
|
|
|
|
presence_str = propv[1];
|
2020-03-19 20:02:57 +00:00
|
|
|
} else if (!g_strcmp0 (propv[0], "variable-framerate")) {
|
|
|
|
variable_framerate = g_strdup (propv[1]);
|
2019-08-30 21:16:35 +00:00
|
|
|
} else if (!g_strcmp0 (propv[0], "single-segment")) {
|
|
|
|
GValue v = G_VALUE_INIT;
|
|
|
|
|
|
|
|
g_value_init (&v, G_TYPE_BOOLEAN);
|
|
|
|
if (!gst_value_deserialize (&v, propv[1])) {
|
|
|
|
g_warning ("Invalid value for property 'single-segment': %s",
|
|
|
|
propv[1]);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
single_segment = g_value_get_boolean (&v);
|
|
|
|
g_value_reset (&v);
|
2020-11-20 21:35:49 +00:00
|
|
|
} else {
|
|
|
|
g_warning ("Unsupported property: %s", propv[0]);
|
|
|
|
return NULL;
|
2019-08-30 21:16:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (presence_str) {
|
|
|
|
presence = g_ascii_strtoll (presence_str, &endptr, 10);
|
|
|
|
|
|
|
|
if (endptr == strprops_v[1]) {
|
|
|
|
g_warning ("Wrong presence %s", presence_str);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2016-12-23 17:23:48 +00:00
|
|
|
}
|
|
|
|
} else { /* We have no presence */
|
|
|
|
if (preset_v[1]) { /* Not presence but preset */
|
|
|
|
preset_name = g_strdup (preset_v[1]);
|
2015-12-11 14:38:00 +00:00
|
|
|
g_free (strcaps);
|
|
|
|
strcaps = g_strdup (preset_v[0]);
|
2016-12-23 17:23:48 +00:00
|
|
|
} /* Else we have no presence nor preset */
|
|
|
|
}
|
2019-08-30 21:16:35 +00:00
|
|
|
g_strfreev (strprops_v);
|
2016-12-23 17:23:48 +00:00
|
|
|
g_strfreev (preset_v);
|
|
|
|
|
|
|
|
GST_DEBUG ("Creating preset with restrictions: %" GST_PTR_FORMAT
|
|
|
|
", caps: %s, preset %s, presence %d", restrictioncaps, strcaps,
|
|
|
|
preset_name ? preset_name : "none", presence);
|
|
|
|
|
|
|
|
caps = gst_caps_from_string (strcaps);
|
|
|
|
if (caps) {
|
|
|
|
profile = create_encoding_profile_from_caps (caps, preset_name,
|
2019-08-30 21:16:35 +00:00
|
|
|
restrictioncaps, presence, single_segment, NULL, muxers_and_encoders,
|
2020-11-13 19:32:45 +00:00
|
|
|
raw_audio_caps, raw_video_caps, FALSE);
|
2016-12-23 17:23:48 +00:00
|
|
|
gst_caps_unref (caps);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!profile) {
|
2020-11-13 19:32:45 +00:00
|
|
|
gboolean is_rendering_muxer;
|
|
|
|
|
2016-12-23 17:23:48 +00:00
|
|
|
caps = get_profile_format_from_possible_factory_name (strcaps,
|
2020-11-13 19:32:45 +00:00
|
|
|
&factory_name, restrictioncaps ? NULL : &restrictioncaps,
|
|
|
|
&is_rendering_muxer);
|
2016-12-23 17:23:48 +00:00
|
|
|
if (caps) {
|
|
|
|
profile = create_encoding_profile_from_caps (caps, preset_name,
|
2019-08-30 21:16:35 +00:00
|
|
|
restrictioncaps, presence, single_segment, factory_name,
|
2020-11-13 19:32:45 +00:00
|
|
|
muxers_and_encoders, raw_audio_caps, raw_video_caps,
|
|
|
|
is_rendering_muxer);
|
2016-12-23 17:23:48 +00:00
|
|
|
gst_caps_unref (caps);
|
2015-12-11 14:38:00 +00:00
|
|
|
}
|
2016-12-23 17:23:48 +00:00
|
|
|
}
|
|
|
|
g_free (preset_name);
|
|
|
|
g_free (strcaps);
|
2015-12-11 14:38:00 +00:00
|
|
|
|
2016-12-23 17:23:48 +00:00
|
|
|
if (restrictioncaps)
|
|
|
|
gst_caps_unref (restrictioncaps);
|
2015-12-11 14:38:00 +00:00
|
|
|
|
2020-03-19 20:02:57 +00:00
|
|
|
if (variable_framerate) {
|
|
|
|
if (GST_IS_ENCODING_VIDEO_PROFILE (profile)) {
|
|
|
|
GValue v = {
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
g_value_init (&v, G_TYPE_BOOLEAN);
|
|
|
|
if (gst_value_deserialize (&v, variable_framerate)) {
|
|
|
|
gst_encoding_video_profile_set_variableframerate
|
|
|
|
(GST_ENCODING_VIDEO_PROFILE (profile), g_value_get_boolean (&v));
|
|
|
|
} else {
|
|
|
|
GST_WARNING ("Invalid value for variable_framerate: %s",
|
|
|
|
variable_framerate);
|
|
|
|
|
|
|
|
}
|
|
|
|
g_value_reset (&v);
|
|
|
|
} else {
|
|
|
|
GST_WARNING
|
|
|
|
("Variable framerate specified on a non video encoding profile");
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (variable_framerate);
|
|
|
|
}
|
|
|
|
|
2016-12-23 17:23:48 +00:00
|
|
|
if (profile == NULL) {
|
|
|
|
GST_ERROR ("No way to create a profile for description: %s",
|
|
|
|
serialized_profile);
|
2015-12-11 14:38:00 +00:00
|
|
|
|
2016-12-23 17:23:48 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2015-12-11 14:38:00 +00:00
|
|
|
|
2020-11-20 21:35:49 +00:00
|
|
|
if (element_properties)
|
|
|
|
gst_encoding_profile_set_element_properties (profile, element_properties);
|
|
|
|
|
2016-12-23 17:23:48 +00:00
|
|
|
return profile;
|
|
|
|
}
|
2015-12-11 14:38:00 +00:00
|
|
|
|
2016-12-23 17:23:48 +00:00
|
|
|
static GstEncodingProfile *
|
|
|
|
parse_encoding_profile (const gchar * value)
|
|
|
|
{
|
2018-04-20 14:04:44 +00:00
|
|
|
GstEncodingProfile *res = NULL;
|
|
|
|
gchar *caps_str = NULL;
|
|
|
|
gchar **strcaps_v =
|
|
|
|
g_regex_split_simple ("(?<!\\\\)(?:\\\\\\\\)*:", value, 0, 0);
|
2016-12-23 17:23:48 +00:00
|
|
|
guint i;
|
2018-04-23 19:50:26 +00:00
|
|
|
GList *muxers_and_encoders =
|
|
|
|
gst_element_factory_list_get_elements (GST_ELEMENT_FACTORY_TYPE_ENCODER |
|
|
|
|
GST_ELEMENT_FACTORY_TYPE_MUXER,
|
|
|
|
GST_RANK_MARGINAL);
|
|
|
|
GstCaps *raw_video_caps = gst_caps_new_empty_simple ("video/x-raw");
|
|
|
|
GstCaps *raw_audio_caps = gst_caps_new_empty_simple ("audio/x-raw");
|
2015-12-11 14:38:00 +00:00
|
|
|
|
2018-04-20 14:04:44 +00:00
|
|
|
/* The regex returns NULL if no ":" found, handle that case. */
|
|
|
|
if (strcaps_v == NULL)
|
|
|
|
strcaps_v = g_strsplit (value, ":", 0);
|
|
|
|
|
2018-04-23 19:50:26 +00:00
|
|
|
for (i = 0; strcaps_v[i] && *strcaps_v[i]; i++) {
|
2018-04-20 14:04:44 +00:00
|
|
|
GstEncodingProfile *profile;
|
|
|
|
caps_str = g_strcompress (strcaps_v[i]);
|
2018-04-23 19:50:26 +00:00
|
|
|
profile =
|
|
|
|
create_encoding_stream_profile (caps_str, muxers_and_encoders,
|
|
|
|
raw_audio_caps, raw_video_caps);
|
2015-12-11 14:38:00 +00:00
|
|
|
|
2018-04-20 14:04:44 +00:00
|
|
|
if (!profile) {
|
|
|
|
GST_ERROR ("Could not create profile for caps: %s", caps_str);
|
|
|
|
goto error;
|
|
|
|
}
|
2015-12-11 14:38:00 +00:00
|
|
|
|
|
|
|
if (res) {
|
2018-04-23 19:50:26 +00:00
|
|
|
if (!GST_IS_ENCODING_CONTAINER_PROFILE (res)) {
|
|
|
|
GST_ERROR ("The first described encoding profile was not a container"
|
|
|
|
" but you are trying to add more profiles to it. This is not possible");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2015-12-29 15:56:21 +00:00
|
|
|
if (!gst_encoding_container_profile_add_profile
|
|
|
|
(GST_ENCODING_CONTAINER_PROFILE (res), profile)) {
|
2018-04-20 14:04:44 +00:00
|
|
|
GST_ERROR ("Can not add profile for caps: %s", caps_str);
|
|
|
|
goto error;
|
2015-12-11 14:38:00 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
res = profile;
|
|
|
|
}
|
2018-04-20 14:04:44 +00:00
|
|
|
|
|
|
|
g_clear_pointer (&caps_str, g_free);
|
2015-12-11 14:38:00 +00:00
|
|
|
}
|
2018-04-23 19:50:26 +00:00
|
|
|
|
|
|
|
done:
|
|
|
|
g_free (caps_str);
|
2015-12-11 14:38:00 +00:00
|
|
|
g_strfreev (strcaps_v);
|
2018-04-23 19:50:26 +00:00
|
|
|
gst_caps_unref (raw_audio_caps);
|
|
|
|
gst_caps_unref (raw_video_caps);
|
|
|
|
gst_plugin_feature_list_free (muxers_and_encoders);
|
2015-12-11 14:38:00 +00:00
|
|
|
|
|
|
|
return res;
|
2018-04-20 14:04:44 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
g_clear_object (&res);
|
|
|
|
|
2018-04-23 19:50:26 +00:00
|
|
|
goto done;
|
2015-12-11 14:38:00 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 16:24:37 +00:00
|
|
|
static GstEncodingProfile *
|
|
|
|
profile_from_string (const gchar * string)
|
|
|
|
{
|
|
|
|
GstEncodingProfile *profile;
|
|
|
|
gchar *filename_end;
|
|
|
|
|
|
|
|
profile = combo_search (string);
|
|
|
|
|
|
|
|
if (profile)
|
|
|
|
return profile;
|
|
|
|
|
|
|
|
filename_end = g_strrstr (string, ".gep");
|
|
|
|
if (filename_end) {
|
|
|
|
GstEncodingTarget *target;
|
|
|
|
gchar *profilename = NULL, *filename;
|
|
|
|
|
|
|
|
if (filename_end[4] == ':')
|
|
|
|
profilename = g_strdup (&filename_end[5]);
|
|
|
|
|
|
|
|
if (filename_end[4] == '\0' || profilename) {
|
|
|
|
filename = g_strndup (string, filename_end - string + strlen (".gep"));
|
|
|
|
|
|
|
|
target = gst_encoding_target_load_from_file (filename, NULL);
|
|
|
|
if (target) {
|
|
|
|
profile = gst_encoding_target_get_profile (target,
|
|
|
|
profilename ? profilename : "default");
|
|
|
|
gst_encoding_target_unref (target);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (profilename);
|
|
|
|
g_free (filename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!profile)
|
|
|
|
profile = parse_encoding_profile (string);
|
|
|
|
|
|
|
|
return profile;
|
|
|
|
}
|
|
|
|
|
2010-12-22 17:18:00 +00:00
|
|
|
/* GValue transform function */
|
|
|
|
static void
|
|
|
|
string_to_profile_transform (const GValue * src_value, GValue * dest_value)
|
|
|
|
{
|
|
|
|
const gchar *profilename;
|
|
|
|
GstEncodingProfile *profile;
|
|
|
|
|
|
|
|
profilename = g_value_get_string (src_value);
|
|
|
|
|
2016-12-21 16:24:37 +00:00
|
|
|
profile = profile_from_string (profilename);
|
2010-12-22 17:18:00 +00:00
|
|
|
|
|
|
|
if (profile)
|
2011-02-23 13:12:22 +00:00
|
|
|
g_value_take_object (dest_value, (GObject *) profile);
|
2010-12-22 17:18:00 +00:00
|
|
|
}
|
|
|
|
|
2020-03-20 13:58:19 +00:00
|
|
|
static void
|
|
|
|
serialize_profile (GString * res, GstEncodingProfile * profile)
|
|
|
|
{
|
|
|
|
gchar *tmp;
|
|
|
|
|
|
|
|
if (res->len)
|
|
|
|
g_string_append_c (res, ':');
|
|
|
|
|
|
|
|
if (profile->restriction) {
|
|
|
|
tmp = gst_caps_to_string (profile->restriction);
|
|
|
|
g_string_append_printf (res, "%s->", tmp);
|
|
|
|
g_free (tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = gst_caps_to_string (profile->format);
|
|
|
|
g_string_append (res, tmp);
|
|
|
|
|
|
|
|
if (profile->presence)
|
|
|
|
g_string_append_printf (res, "|presence=%d", profile->presence);
|
|
|
|
|
|
|
|
if (profile->single_segment)
|
|
|
|
g_string_append_printf (res, "%ssingle-segment=true",
|
|
|
|
profile->presence ? "" : "|");
|
|
|
|
|
|
|
|
if (GST_IS_ENCODING_CONTAINER_PROFILE (profile)) {
|
|
|
|
GList *tmp;
|
|
|
|
|
|
|
|
for (tmp = GST_ENCODING_CONTAINER_PROFILE (profile)->encodingprofiles; tmp;
|
|
|
|
tmp = tmp->next)
|
|
|
|
serialize_profile (res, tmp->data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gchar *
|
|
|
|
gst_encoding_profile_serialize_valfunc (GValue * value)
|
|
|
|
{
|
|
|
|
GString *res = g_string_new (NULL);
|
|
|
|
GstEncodingProfile *profile = g_value_get_object (value);
|
|
|
|
|
|
|
|
serialize_profile (res, profile);
|
|
|
|
|
|
|
|
return g_string_free (res, FALSE);
|
|
|
|
}
|
|
|
|
|
2010-12-22 17:18:00 +00:00
|
|
|
static gboolean
|
|
|
|
gst_encoding_profile_deserialize_valfunc (GValue * value, const gchar * s)
|
|
|
|
{
|
|
|
|
GstEncodingProfile *profile;
|
|
|
|
|
2016-12-21 16:24:37 +00:00
|
|
|
profile = profile_from_string (s);
|
2015-12-11 14:38:00 +00:00
|
|
|
|
2010-12-22 17:18:00 +00:00
|
|
|
if (profile) {
|
2011-02-23 13:12:22 +00:00
|
|
|
g_value_take_object (value, (GObject *) profile);
|
2010-12-22 17:18:00 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-02-18 11:48:37 +00:00
|
|
|
|
2020-07-24 12:33:23 +00:00
|
|
|
static GstEncodingProfile *
|
|
|
|
create_stream_profile_recurse (GstEncodingProfile * toplevel,
|
2016-04-28 08:15:53 +00:00
|
|
|
GstDiscovererStreamInfo * sinfo)
|
|
|
|
{
|
2020-07-24 12:33:23 +00:00
|
|
|
GstEncodingProfile *profile = NULL;
|
2016-04-28 08:15:53 +00:00
|
|
|
GstStructure *s;
|
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
caps = gst_discoverer_stream_info_get_caps (sinfo);
|
|
|
|
|
2016-07-08 13:43:05 +00:00
|
|
|
/* Should unify this with copy_and_clean_caps() */
|
2021-08-14 23:27:39 +00:00
|
|
|
caps = gst_caps_make_writable (caps);
|
2016-04-28 08:15:53 +00:00
|
|
|
s = gst_caps_get_structure (caps, 0);
|
2021-08-14 23:27:39 +00:00
|
|
|
|
|
|
|
gst_structure_remove_fields (s, "codec_data", "streamheader", "parsed",
|
2021-10-15 01:55:35 +00:00
|
|
|
"colorimetry", "framed", "stream-format", "alignment", "tier", "level",
|
|
|
|
"profile", NULL);
|
2016-04-28 08:15:53 +00:00
|
|
|
|
2017-04-12 08:58:49 +00:00
|
|
|
GST_LOG ("Stream: %" GST_PTR_FORMAT, caps);
|
2016-04-28 08:15:53 +00:00
|
|
|
if (GST_IS_DISCOVERER_AUDIO_INFO (sinfo)) {
|
2020-07-24 12:33:23 +00:00
|
|
|
profile =
|
2016-04-28 08:15:53 +00:00
|
|
|
(GstEncodingProfile *) gst_encoding_audio_profile_new (caps, NULL,
|
|
|
|
NULL, 0);
|
|
|
|
} else if (GST_IS_DISCOVERER_VIDEO_INFO (sinfo)) {
|
2020-07-24 12:33:23 +00:00
|
|
|
profile =
|
2016-04-28 08:15:53 +00:00
|
|
|
(GstEncodingProfile *) gst_encoding_video_profile_new (caps, NULL,
|
|
|
|
NULL, 0);
|
2016-04-28 08:21:47 +00:00
|
|
|
} else if (GST_IS_DISCOVERER_CONTAINER_INFO (sinfo)) {
|
|
|
|
GList *streams, *stream;
|
|
|
|
|
|
|
|
streams =
|
|
|
|
gst_discoverer_container_info_get_streams (GST_DISCOVERER_CONTAINER_INFO
|
|
|
|
(sinfo));
|
2020-07-24 12:33:23 +00:00
|
|
|
|
|
|
|
if (!toplevel || !GST_IS_ENCODING_CONTAINER_PROFILE (toplevel)) {
|
|
|
|
GstEncodingProfile *prev_toplevel = toplevel;
|
|
|
|
|
|
|
|
toplevel = (GstEncodingProfile *)
|
|
|
|
gst_encoding_container_profile_new ("auto-generated",
|
|
|
|
"Automatically generated from GstDiscovererInfo", caps, NULL);
|
|
|
|
if (prev_toplevel)
|
|
|
|
gst_encoding_container_profile_add_profile
|
|
|
|
(GST_ENCODING_CONTAINER_PROFILE (toplevel), prev_toplevel);
|
2016-04-28 08:21:47 +00:00
|
|
|
}
|
|
|
|
|
2020-07-24 12:33:23 +00:00
|
|
|
for (stream = streams; stream; stream = stream->next)
|
|
|
|
create_stream_profile_recurse (toplevel,
|
|
|
|
(GstDiscovererStreamInfo *) stream->data);
|
|
|
|
gst_discoverer_stream_info_list_free (streams);
|
2016-04-28 08:15:53 +00:00
|
|
|
} else {
|
2020-07-24 12:33:23 +00:00
|
|
|
GST_FIXME ("Ignoring stream of type '%s'",
|
2016-04-28 08:18:23 +00:00
|
|
|
g_type_name (G_OBJECT_TYPE (sinfo)));
|
2016-04-28 08:15:53 +00:00
|
|
|
/* subtitles or other ? ignore for now */
|
|
|
|
}
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
|
2020-07-24 12:33:23 +00:00
|
|
|
if (profile) {
|
|
|
|
const gchar *stream_id = gst_discoverer_stream_info_get_stream_id (sinfo);
|
|
|
|
|
|
|
|
if (stream_id) {
|
|
|
|
const gchar *subid = strchr (stream_id, '/');
|
|
|
|
|
|
|
|
gst_encoding_profile_set_name (profile, subid ? subid : stream_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GST_IS_ENCODING_CONTAINER_PROFILE (toplevel))
|
|
|
|
gst_encoding_container_profile_add_profile ((GstEncodingContainerProfile
|
|
|
|
*)
|
|
|
|
toplevel, profile);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!toplevel && profile)
|
|
|
|
toplevel = profile;
|
|
|
|
|
|
|
|
sinfo = gst_discoverer_stream_info_get_next (sinfo);
|
|
|
|
if (sinfo)
|
|
|
|
return create_stream_profile_recurse (toplevel, sinfo);
|
|
|
|
|
|
|
|
return toplevel;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
_compare_profile_names (const GstEncodingProfile * a,
|
|
|
|
const GstEncodingProfile * b)
|
|
|
|
{
|
|
|
|
return g_strcmp0 (a->name, b->name);
|
2016-04-28 08:15:53 +00:00
|
|
|
}
|
|
|
|
|
2011-02-18 11:48:37 +00:00
|
|
|
/**
|
|
|
|
* gst_encoding_profile_from_discoverer:
|
|
|
|
* @info: (transfer none): The #GstDiscovererInfo to read from
|
|
|
|
*
|
|
|
|
* Creates a #GstEncodingProfile matching the formats from the given
|
2014-07-18 10:16:05 +00:00
|
|
|
* #GstDiscovererInfo. Streams other than audio or video (eg,
|
2011-02-18 11:48:37 +00:00
|
|
|
* subtitles), are currently ignored.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): The new #GstEncodingProfile or %NULL.
|
|
|
|
*/
|
|
|
|
GstEncodingProfile *
|
|
|
|
gst_encoding_profile_from_discoverer (GstDiscovererInfo * info)
|
|
|
|
{
|
2020-07-24 12:33:23 +00:00
|
|
|
GstEncodingProfile *profile;
|
2011-02-18 11:48:37 +00:00
|
|
|
GstDiscovererStreamInfo *sinfo;
|
|
|
|
|
|
|
|
if (!info || gst_discoverer_info_get_result (info) != GST_DISCOVERER_OK)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
sinfo = gst_discoverer_info_get_stream_info (info);
|
|
|
|
if (!sinfo)
|
|
|
|
return NULL;
|
|
|
|
|
2020-07-24 12:33:23 +00:00
|
|
|
profile = create_stream_profile_recurse (NULL, sinfo);
|
|
|
|
if (GST_IS_ENCODING_CONTAINER_PROFILE (profile)) {
|
|
|
|
if (!gst_encoding_container_profile_get_profiles
|
|
|
|
(GST_ENCODING_CONTAINER_PROFILE (profile))) {
|
|
|
|
GST_ERROR ("Failed to add any streams");
|
|
|
|
g_object_unref (profile);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
/* Sort by stream ID */
|
|
|
|
GST_ENCODING_CONTAINER_PROFILE (profile)->encodingprofiles =
|
|
|
|
g_list_sort (GST_ENCODING_CONTAINER_PROFILE (profile)->encodingprofiles,
|
|
|
|
(GCompareFunc) _compare_profile_names);
|
2011-02-18 11:48:37 +00:00
|
|
|
|
2016-04-28 08:18:23 +00:00
|
|
|
}
|
|
|
|
|
2011-02-18 11:48:37 +00:00
|
|
|
return (GstEncodingProfile *) profile;
|
|
|
|
}
|
2017-01-04 17:27:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_encoding_profile_copy:
|
|
|
|
* @self: The #GstEncodingProfile to copy
|
|
|
|
*
|
|
|
|
* Makes a deep copy of @self
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): The copy of @self
|
|
|
|
*
|
2019-04-23 12:05:43 +00:00
|
|
|
* Since: 1.12
|
2017-01-04 17:27:40 +00:00
|
|
|
*/
|
|
|
|
GstEncodingProfile *
|
|
|
|
gst_encoding_profile_copy (GstEncodingProfile * self)
|
|
|
|
{
|
|
|
|
GstEncodingProfileClass *klass =
|
|
|
|
(GstEncodingProfileClass *) G_OBJECT_GET_CLASS (self);
|
|
|
|
GstEncodingProfile *copy =
|
|
|
|
common_creation (G_OBJECT_TYPE (self), self->format, self->preset,
|
|
|
|
self->name, self->description, self->restriction, self->presence);
|
|
|
|
|
|
|
|
copy->enabled = self->enabled;
|
|
|
|
copy->allow_dynamic_output = self->allow_dynamic_output;
|
|
|
|
gst_encoding_profile_set_preset_name (copy, self->preset_name);
|
|
|
|
gst_encoding_profile_set_description (copy, self->description);
|
|
|
|
|
|
|
|
if (klass->copy)
|
|
|
|
klass->copy (self, copy);
|
|
|
|
|
|
|
|
return copy;
|
|
|
|
}
|