Original address:
blog.csdn.net/android_lee/article/details/6789272
Own a little add:
Playbin2 has two properties: Audio-sink and Video-sink. The application only needs to instantiate the appropriate element and pass these two attributes to playbin2.
1. Directory structure
gstreamer-0.10.21 Directory
GST core file for functions such as GST component factory
Components provided by the plugins gstreamer-0.10.21
Lib cannot be applied to the calling component, but he is the parent class of some components
Pkgconfig Install tools are the things that make install needs to copy
Po translation files in various languages
Tests testing the components of the gstreamer-0.10.21
gst-plugins-base-0.10.21 Directory
Components provided by GST base
Gst-libs the parent class of the component provided by the base, applying an unavailable component
Ext requires additional Source Library components
SYS system-related components (X11,V4L) These 2 windows have no
2. Fine Number Components
See which components of GST see which files call the Gst_element_register
Grep-nr ' Gst_element_register '--include=*.c.
GStreamer components are unified registration, the other components are basically separate registration
static struct _elements_entry _elements[] = {
{"Capsfilter", Gst_rank_none, Gst_capsfilter_get_type},
{"Fakesrc", Gst_rank_none, Gst_fake_src_get_type},
{"Fakesink", Gst_rank_none, Gst_fake_sink_get_type},
#ifdef Have_sys_socket_h
{"Fdsrc", Gst_rank_none, Gst_fd_src_get_type},
{"Fdsink", Gst_rank_none, Gst_fd_sink_get_type},
#endif
{"Filesrc", Gst_rank_primary, Gst_file_src_get_type},
{"Identity", Gst_rank_none, Gst_identity_get_type},
{"Queue", Gst_rank_none, Gst_queue_get_type},
{"Filesink", Gst_rank_primary, Gst_file_sink_get_type},
{"Tee", Gst_rank_none, Gst_tee_get_type},
{"Typefind", Gst_rank_none, Gst_type_find_element_get_type},
{"Multiqueue", Gst_rank_none, Gst_multi_queue_get_type},
{NULL, 0},
};
3.playbin (only say Playbin play video)
Playbin components are integrated components that build a factory pipeline and use many components.
3.1 Component flowchart
FILESRC---(Typefind)-->decodebin-->|--> Abin (audioconvert-->audioresample-->volume--> Osssink)
··························································| --Vbin (Identity-->ffmpegcolorspace-->videoscale-->fbdevsink)
3.2 Code Analysis
After the application establishes the Playbin component, it calls Get_element_set_state to set Playbin to Null,ready,paused,playing, when ready-->paused (GST_STATE_ change_ready_to_paused), Playbin set up the pipe.
Gst_play_base_bin_change_state
|----Setup_source
|----|----gen_source_element Establish the source element, i.e. FILESRC
|----|----|----if (PLAY_BASE_BIN->SUBURI) setup_subtitle Configure the caption symbol if the Suburi attribute of the Playbin is set
|----|----|----GST_ELEMENT_MAKE_FROM_URI
|----|----|----|----GET_ELEMENT_FACTORIES_FROM_URI_PROTOCOL determine the plant type based on the string header URI protocol search_by_entry, such as file:// The establishment of FILESRC
|----|----|----GST_ELEMENT_FACTORY_CREATE building components based on a determined plant type (FILESRC)
|----|----ANALYSE_SOURCE analysis Source is raw data/dynamic pad/has output pad to do the corresponding processing
|----|----|----Things are going to group_commit.
|----|----|----|----GST_PLAY_BASE_BIN_GET_CLASS (play_base_bin)
Setup_output_pads is Gstplaybin.c's setup_sinks.
|----|----|----|----|----audio needs to be visualized call Gen_vis_element
|----|----|----|----|----have audio do not need visual call Gen_audio_element
|----|----|----|----|----HAVE video call Gen_video_element
|----|----make_decoder
|----|----|----gst_element_factory_make ("Decodebin", NULL) Establish decodebin element
|----|----gst_element_link (play_base_bin->source, decoder) Link filesrc and Decodebin.
3.3 Playbin Directory
Directory is gst-plugins-base-0.10.21/gst/playback/
Originally looked at a lot of documents, but 2 sets of Playbin, one set of non-stable version playbin2, so actually really want to see the file is not much.
GSTPLAYBACK.C Register Playbin and Playbin2
Playbin c files Used (mainly Playbin, Playbasebin, Decodebin)
Gstplaybin.c
Gstplaybasebin.c
Gstdecodebin.c
Gststreaminfo.c
Gststreamselector.c
Gstplaymarshal.c
Playbin2 c file Used (with Playbin,playbasebin, decodebin equivalent is Playbin2,playsink, decodebin2)
Gstplaybin2.c
Gstplaysink.c
Gstdecodebin2.c
And some of the remaining files, GSTURIDECODEBIN.C and gstdecodebin2.c are also non-stable versions
3.4 The parent class used by the Playbin element
FILESRC's Parent_class is BASESRC, as can be seen from below,
Gst_boilerplate_full (GSTFILESRC, GST_FILE_SRC, GSTBASESRC, GST_TYPE_BASE_SRC,
_do_init);
When the user calls set_state for an internal change_state, the change_state of the parent class of the component is called. BASESRC is like a filesrc base class.
Osssink's Parent_class is Audiosink, as can be seen from below,
Osssink_type = g_type_register_static (Gst_type_audio_sink, "Gstosssink", &osssink_info, 0);
Osssink is just doing the underlying work, the logic layer of the audio is still in the Audiosink and its parent audiobasesink, they call the Osssink function pointer for the specific read and write sound card operation
3.5 element's parent class
Because the change_state will be distributed to every component in the pipeline, the change_state of the component will call it Parent_class change_state, so it is inevitable to see Playbin parent_class
struct _gstplaybin {
Gstplaybasebin parent;
struct _gstplaybasebin {
Gstpipeline pipeline;
Playbin-->playbasebin-->pipeline is in the pipeline.
Set_state change_state function that can be sent to all components in a pipeline
The Parent_class Change_state is called in the Change_state function of each component,
playbin--(parent)-->playbasebin
playbasebin--(parent)-->pipeline
pipeline--(parent)-->bin
The top level is bin, look at Bin's change_state function,
while (!done) {
Gpointer data;
Switch (Gst_iterator_next (it, &data)) {
Case GST_ITERATOR_OK:
{
Gstelement *child;
Child = gst_element_cast (data);
/* Set state and Base_time now */
ret = gst_bin_element_set_state (bin, child, Base_time, current, next);
Remove the elements from the bin to send the set_state command so that all components will change state.
Gstclock 3 ways to get a clock
1 Systemclock system Clock
2 Audio Devices know the clock based on the sample rate
3 The clock information contained in the network package
I've only seen Systemclock, gstclock->gstsystemtclock->g_get_current_time->gettimeofday-> (System call)
Audio and video time synchronization to system time
It's not the audio and video who syncs who, but everyone is in sync with the system time.
Ns... B... B... EOS ns=new Segment
C.running_time = Absolute_time-base_time (System)
B.running_time = (b.timestamp-ns.start)/ns.abs_rate + ns.accum (component)
Synchronization is to make B,c running_time equal, b wait
Base_time from the New_segment event as a benchmark, such as Seek is new SEGMENT
_class_init to Klass to hang function pointers
Gst_base_audio_sink_class_init (Gstbaseaudiosinkclass * Klass)
Gobject_class = (Gobjectclass *) Klass;
Gstelement_class = (Gstelementclass *) Klass;
Gstbasesink_class = (Gstbasesinkclass *) Klass;
Convert a Klass to 3 data structures, can be the reason is that the first level is the data structure of a member, the Kclass is the largest data structure, to small turn of course can
struct _gstbaseaudiosink {
Gstbasesink element;
struct _gstbasesink {
gstelement element;
struct _gstelement
{
Gstobject object;
State Change
Null-->ready
1 Probe device
2 Open Device
Ready-->paused
1 Activate pad, return async, and then the stream thread thread only to the state change things to finish, until the sink pad received first buffer, blocked, then only real state change, with get_state can query to
2 Pipe Running_time Zeroing
3 If the live source returns No_preroll, no data is generated (live source is sources that generate data even when paused, such as net and camera)
Paused-->playing (most components ignore this state)
1 pipe selection clock is distributed to each sub-component, that is, the synchronous clock only occurs when the playing
2 pipe distributes clock running_time computed base_time to each sub-component (Change_state)
3 sink gasket no longer blocks buffer/event, start render data
4 Live source starts generating data
Playing-->paused (most components ignore this state)
1 if sink at this time no buffer in the hand must wait to receive buffer to complete the status change. Look at the above ready->paused is also sink before entering the paused must have buffer, in order to playing do not let the user wait for a few hours ahead
2 EOS event is invalid, but will repost when playing
3 sink all the waiting on the preroll unblocked.
4 Live source stops generating data
Paused-->ready
1 sink unblocking Preroll, component unblocking device
2 chain and Get_range return to wrong_state (buffer related function)
3 Pad Invalidates (deactivate), stream thread stops
4 sink Forget all the negotiation formats (negotiation caps)
Ready-->null
1 Close Device
2 Delete all dynamically established pads