mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-03-28 11:55:39 +00:00
Added basic tutorial 6
This commit is contained in:
parent
a8e8e02ef2
commit
589218bd13
4 changed files with 300 additions and 0 deletions
203
gst-sdk/tutorials/basic-tutorial-6.c
Normal file
203
gst-sdk/tutorials/basic-tutorial-6.c
Normal file
|
@ -0,0 +1,203 @@
|
|||
#include <gst/gst.h>
|
||||
|
||||
/* Functions below print the Capabilities in a human-friendly format */
|
||||
static gboolean print_field (GQuark field, const GValue * value, gpointer pfx) {
|
||||
gchar *str = gst_value_serialize (value);
|
||||
|
||||
g_print ("%s %15s: %s\n", (gchar *) pfx, g_quark_to_string (field), str);
|
||||
g_free (str);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void print_caps (const GstCaps * caps, const gchar * pfx) {
|
||||
guint i;
|
||||
|
||||
g_return_if_fail (caps != NULL);
|
||||
|
||||
if (gst_caps_is_any (caps)) {
|
||||
g_print ("%sANY\n", pfx);
|
||||
return;
|
||||
}
|
||||
if (gst_caps_is_empty (caps)) {
|
||||
g_print ("%sEMPTY\n", pfx);
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < gst_caps_get_size (caps); i++) {
|
||||
GstStructure *structure = gst_caps_get_structure (caps, i);
|
||||
|
||||
g_print ("%s%s\n", pfx, gst_structure_get_name (structure));
|
||||
gst_structure_foreach (structure, print_field, (gpointer) pfx);
|
||||
}
|
||||
}
|
||||
|
||||
/* Prints information about a Pad Template, including its Capabilities */
|
||||
static void print_pad_templates_information (GstElementFactory * factory) {
|
||||
const GList *pads;
|
||||
GstStaticPadTemplate *padtemplate;
|
||||
|
||||
g_print ("Pad Templates for %s:\n", gst_element_factory_get_longname (factory));
|
||||
if (!factory->numpadtemplates) {
|
||||
g_print (" none\n");
|
||||
return;
|
||||
}
|
||||
|
||||
pads = factory->staticpadtemplates;
|
||||
while (pads) {
|
||||
padtemplate = (GstStaticPadTemplate *) (pads->data);
|
||||
pads = g_list_next (pads);
|
||||
|
||||
if (padtemplate->direction == GST_PAD_SRC)
|
||||
g_print (" SRC template: '%s'\n", padtemplate->name_template);
|
||||
else if (padtemplate->direction == GST_PAD_SINK)
|
||||
g_print (" SINK template: '%s'\n", padtemplate->name_template);
|
||||
else
|
||||
g_print (" UNKNOWN!!! template: '%s'\n", padtemplate->name_template);
|
||||
|
||||
if (padtemplate->presence == GST_PAD_ALWAYS)
|
||||
g_print (" Availability: Always\n");
|
||||
else if (padtemplate->presence == GST_PAD_SOMETIMES)
|
||||
g_print (" Availability: Sometimes\n");
|
||||
else if (padtemplate->presence == GST_PAD_REQUEST) {
|
||||
g_print (" Availability: On request\n");
|
||||
} else
|
||||
g_print (" Availability: UNKNOWN!!!\n");
|
||||
|
||||
if (padtemplate->static_caps.string) {
|
||||
g_print (" Capabilities:\n");
|
||||
print_caps (gst_static_caps_get (&padtemplate->static_caps), " ");
|
||||
}
|
||||
|
||||
g_print ("\n");
|
||||
}
|
||||
}
|
||||
|
||||
/* Shows the CURRENT capabilities of the requested pad in the given element */
|
||||
static void print_pad_capabilities (GstElement *element, gchar *pad_name) {
|
||||
GstPad *pad = NULL;
|
||||
GstCaps *caps = NULL;
|
||||
|
||||
/* Retrieve pad */
|
||||
pad = gst_element_get_static_pad (element, pad_name);
|
||||
if (!pad) {
|
||||
g_printerr ("Could not retrieve pad '%s'\n", pad_name);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Retrieve negotiated caps (or acceptable caps if negotiation is not finished yet) */
|
||||
caps = gst_pad_get_negotiated_caps (pad);
|
||||
if (!caps)
|
||||
caps = gst_pad_get_caps_reffed (pad);
|
||||
|
||||
/* Print and free */
|
||||
g_print ("Caps for the %s pad:\n", pad_name);
|
||||
print_caps (caps, " ");
|
||||
gst_caps_unref (caps);
|
||||
gst_object_unref (pad);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
GstElement *pipeline, *source, *sink;
|
||||
GstElementFactory *source_factory, *sink_factory;
|
||||
GstBus *bus;
|
||||
GstMessage *msg;
|
||||
GstStateChangeReturn ret;
|
||||
gboolean terminate = FALSE;
|
||||
|
||||
/* Initialize GStreamer */
|
||||
gst_init (&argc, &argv);
|
||||
|
||||
/* Create the element factories */
|
||||
source_factory = gst_element_factory_find ("audiotestsrc");
|
||||
sink_factory = gst_element_factory_find ("autoaudiosink");
|
||||
if (!source_factory || !sink_factory) {
|
||||
g_printerr ("Not all element factories could be created.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Print information about the pad templates of these factories */
|
||||
print_pad_templates_information (source_factory);
|
||||
print_pad_templates_information (sink_factory);
|
||||
|
||||
/* Ask the factories to instantiate actual elements */
|
||||
source = gst_element_factory_create (source_factory, "source");
|
||||
sink = gst_element_factory_create (sink_factory, "sink");
|
||||
|
||||
/* Create the empty pipeline */
|
||||
pipeline = gst_pipeline_new ("test-pipeline");
|
||||
|
||||
if (!pipeline || !source || !sink) {
|
||||
g_printerr ("Not all elements could be created.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Build the pipeline */
|
||||
gst_bin_add_many (GST_BIN (pipeline), source, sink, NULL);
|
||||
if (gst_element_link (source, sink) != TRUE) {
|
||||
g_printerr ("Elements could not be linked.\n");
|
||||
gst_object_unref (pipeline);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Print initial negotiated caps (in NULL state) */
|
||||
g_print ("In NULL state:\n");
|
||||
print_pad_capabilities (sink, "sink");
|
||||
|
||||
/* Start playing */
|
||||
ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
||||
if (ret == GST_STATE_CHANGE_FAILURE) {
|
||||
g_printerr ("Unable to set the pipeline to the playing state (check the bus for error messages).\n");
|
||||
}
|
||||
|
||||
/* Wait until error, EOS or State Change */
|
||||
bus = gst_element_get_bus (pipeline);
|
||||
do {
|
||||
msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR | GST_MESSAGE_EOS |
|
||||
GST_MESSAGE_STATE_CHANGED);
|
||||
|
||||
/* Parse message */
|
||||
if (msg != NULL) {
|
||||
GError *err;
|
||||
gchar *debug_info;
|
||||
|
||||
switch (GST_MESSAGE_TYPE (msg)) {
|
||||
case GST_MESSAGE_ERROR:
|
||||
gst_message_parse_error (msg, &err, &debug_info);
|
||||
g_printerr ("Error received from element %s: %s\n", GST_OBJECT_NAME (msg->src), err->message);
|
||||
g_printerr ("Debugging information: %s\n", debug_info ? debug_info : "none");
|
||||
g_clear_error (&err);
|
||||
g_free (debug_info);
|
||||
terminate = TRUE;
|
||||
break;
|
||||
case GST_MESSAGE_EOS:
|
||||
g_print ("End-Of-Stream reached.\n");
|
||||
terminate = TRUE;
|
||||
break;
|
||||
case GST_MESSAGE_STATE_CHANGED:
|
||||
/* We are only interested in state-changed messages from the pipeline */
|
||||
if (GST_MESSAGE_SRC (msg) == GST_OBJECT (pipeline)) {
|
||||
GstState old_state, new_state, pending_state;
|
||||
gst_message_parse_state_changed (msg, &old_state, &new_state, &pending_state);
|
||||
g_print ("\nPipeline state changed from %s to %s:\n",
|
||||
gst_element_state_get_name (old_state), gst_element_state_get_name (new_state));
|
||||
/* Print the current capabilities of the sink element */
|
||||
print_pad_capabilities (sink, "sink");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
/* We should not reach here because we only asked for ERRORs, EOS and STATE_CHANGED */
|
||||
g_printerr ("Unexpected message received.\n");
|
||||
break;
|
||||
}
|
||||
gst_message_unref (msg);
|
||||
}
|
||||
} while (!terminate);
|
||||
|
||||
/* Free resources */
|
||||
gst_object_unref (bus);
|
||||
gst_element_set_state (pipeline, GST_STATE_NULL);
|
||||
gst_object_unref (pipeline);
|
||||
gst_object_unref (source_factory);
|
||||
gst_object_unref (sink_factory);
|
||||
return 0;
|
||||
}
|
85
vs/2010/tutorials/basic-tutorial-6/basic-tutorial-6.vcxproj
Normal file
85
vs/2010/tutorials/basic-tutorial-6/basic-tutorial-6.vcxproj
Normal file
|
@ -0,0 +1,85 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{A2A55F96-F759-4AF6-84EB-96ABD9D82410}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>basictutorial6</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\..\libs\gstreamer-0.10.props" />
|
||||
<Import Project="..\..\libs\msvc\x86.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\..\libs\gstreamer-0.10.props" />
|
||||
<Import Project="..\..\libs\msvc\x86.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\..\..\gst-sdk\tutorials\basic-tutorial-6.c" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\..\..\gst-sdk\tutorials\basic-tutorial-6.c" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -15,6 +15,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "playback-tutorial-1", "play
|
|||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "playback-tutorial-2", "playback-tutorial-2\playback-tutorial-2.vcxproj", "{4319F5D7-039A-44B5-B1A7-507DC627B24D}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "basic-tutorial-6", "basic-tutorial-6\basic-tutorial-6.vcxproj", "{A2A55F96-F759-4AF6-84EB-96ABD9D82410}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
|
@ -49,6 +51,10 @@ Global
|
|||
{4319F5D7-039A-44B5-B1A7-507DC627B24D}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{4319F5D7-039A-44B5-B1A7-507DC627B24D}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{4319F5D7-039A-44B5-B1A7-507DC627B24D}.Release|Win32.Build.0 = Release|Win32
|
||||
{A2A55F96-F759-4AF6-84EB-96ABD9D82410}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{A2A55F96-F759-4AF6-84EB-96ABD9D82410}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{A2A55F96-F759-4AF6-84EB-96ABD9D82410}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{A2A55F96-F759-4AF6-84EB-96ABD9D82410}.Release|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
Loading…
Reference in a new issue