Method and system for realizing multi-screen synchronous playing of player based on gstreamer
By introducing an intermediate adaptive layer and clock synchronization mechanism in the gstreamer streaming media player, the distance limitation, complex operation and unstable synchronization problems in streaming media synchronous playback are solved, and the stable, accurate and video list synchronization functions of multi-screen synchronous playback are realized.
Patent Information
- Application Number
- CN202411726587.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-28
- Publication Date
- 2025-03-14
AI Technical Summary
The prior art has problems such as distance limitation, complex operation, unstable synchronization and inability to synchronize video lists in streaming media synchronous playback.
By introducing an intermediate adaptive layer in the gstreamer streaming media player, the master and slave roles are allocated, the master generates network clocks and reference clocks, and shares them with the slave. The slave uses the same clock mechanism to achieve playback position synchronization.
It realizes the stability and accuracy of multi-screen synchronous playback, simplifies operations, eliminates distance limitations, and supports synchronous playback of video lists.
Smart Images

Figure CN119629395A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of streaming media playback, and more specifically, to a method and system for realizing multi-screen synchronous playback based on a gstreamer player. Background Art
[0002] In recent years, with the rapid development of the electronics industry, streaming media playback technology has continued to develop and improve. The consumer demand for streaming media playback devices such as smart TVs has increased year by year, and the management of product displays in stores has become more complicated. More and more event sites and promotional sites use multi-screen synchronous playback to achieve shocking effects, and multi-screen synchronous playback has been widely used.
[0003] At present, there are three common ways to perform synchronous playback. One is to use a signal distributor to distribute to the device through an HDMI cable. This method is limited by the transmission distance. The second is to ensure that the playback devices start playing at the same time to achieve synchronization. This method has the defects of cumbersome operation and inaccurate synchronization. The third is to divide the device into a master end and a slave end. The master end sends the current playback position to the slave end, and the slave end starts playing from the playback position of the master end. This method has the defect of unstable synchronization. For example, if buffering, pausing, and other playback control operations occur at either end during playback, the playback will lose synchronization. Methods 2 and 3 can only ensure that the master and slave ends play the same video position, and cannot determine whether the two ends play the same video, so the video list cannot be played synchronously. Summary of the invention
[0004] The present invention overcomes the defects of the prior art in that synchronous playback of streaming media is limited by distance, the operation is complicated, the synchronization is unstable, and the playlist cannot be synchronized. A method and system for realizing multi-screen synchronous playback of a player based on gstreamer is provided, in the hope of solving the problems existing in the prior art.
[0005] In order to solve the above technical problems, one aspect of the present invention provides a method for realizing multi-screen synchronous playback based on a gstreamer player.
[0006] A method for realizing multi-screen synchronous playback based on a gstreamer player comprises the following steps:
[0007] The intermediate adaptive layer between gstreamer's streaming media players assigns the master and slave roles to the terminals;
[0008] The intermediate adaptive layer allocates a local IP address master_ip and a port number to the master end, and generates a net_clock (network clock) and a base_time (reference clock);
[0009] The slave sets the master IP address master_ip and the master port number, and connects to the master to obtain net_clock and base_time, current_position (current playback position) and current_URL (current playback address);
[0010] Set the generated net_clock and base_time to the gstreamer framework layer through the gstreamer interface, and check whether the current master and slave are in a synchronized state (synced);
[0011] If the synchronization is achieved, playback starts;
[0012] If the synchronization state is not reached, a synchronization callback is set and playback starts after receiving the synchronization callback.
[0013] The reaching of synchronization state means that the slave end uses the same network clock and reference clock as the master end and the current playback position (current_position) and the current playback URL (current_URL).
[0014] By dividing the playback device into a master and a slave, the master generates a network clock and a reference clock, obtains the current playback position and the current playback URL and shares them with the slave. The slave uses the same network clock and reference clock as the master to achieve playback position synchronization based on the gstreamer clock mechanism.
[0015] A further technical solution is that the intermediate adaptive layer generates net_clock and base_time in the following specific steps:
[0016] Get the current default system clock (system clock) through the gstreamer interface, create a new clock provider (provider_clock) and get the corresponding base_time;
[0017] The clock synchronization port of the master end is obtained through the clock provider, and a new net_clock is generated by obtaining the master_ip and clock synchronization port of the master end.
[0018] A further technical solution is to perform the following steps after the master end allocates the local IP address master_ip:
[0019] The middle adaptive layer creates a socket service thread and monitors whether a new slave connection is captured;
[0020] If a new slave connection is captured, the current playback position and current playback URL are obtained and sent to the newly captured slave together with the generated net_clock and base_time.
[0021] Through the above steps, you can continuously add slaves to the synchronization.
[0022] A further technical solution is that the slave end connects to the master end to obtain net_clock and base_time specifically includes the following steps:
[0023] Connect to the master end through the obtained master_ip and master end port number;
[0024] If the connection fails, create a timer thread and connect once at a certain time interval until the connection is successful and net_clock, base_time, current_position and current_URL are successfully obtained;
[0025] After the connection is successful, end the thread to release resources.
[0026] A further technical solution is that when the playback needs to be paused, the state needs to be switched to pause;
[0027] When you need to restart playback, first set net_clock and base_time;
[0028] Check whether the master and slave are currently in synchronization state. If not, set the synchronization callback;
[0029] When the detection reaches the synchronization state, the playback starts.
[0030] In order to avoid the situation where one terminal loses synchronization after being paused, one terminal can be paused or all terminals can be paused.
[0031] However, when it is necessary to restart playback, it must be detected that the master and slave ends have reached a synchronized state. Only after reaching a synchronized state can playback begin, and the video being played is also synchronized at this time.
[0032] A further technical solution is that the master end detects that the synchronization state has been reached and before starting to play, performs the following steps:
[0033] The slave detects whether the current playback URL is consistent with the master URL.
[0034] If they match, start playing;
[0035] If they are inconsistent, a MEDIA_INFO event is thrown to notify the upper-layer application to replay the URL of the main end;
[0036] The slave obtains the URL of the master, sets the master IP address master_ip and continues to perform subsequent steps.
[0037] When the current playback URL of the slave is inconsistent with the URL of the master, the slave throws a MEDIA_INFO event to notify the upper-layer product application to play the URL of the master to achieve video list synchronization.
[0038] A further technical solution is to restore net_clock and base_time to default values when the playback ends, and terminate the socket service thread to release resources.
[0039] Another aspect of the present invention provides a system for realizing multi-screen synchronous playback based on a gstreamer player.
[0040] A system for realizing multi-screen synchronous playback based on a gstreamer player, comprising an intermediate adaptive layer between gstreamer streaming media players, a gstreamer framework layer, a master end, and a slave end;
[0041] The intermediate adaptive layer between the gstreamer streaming media players is used to allocate the master and slave roles to the terminals;
[0042] Assign the local IP address master_ip and port number to the master end, and generate net_clock and base_time;
[0043] The gstreamer framework layer is used to accept the generated net_clock and base_time, and detect whether the current master end and slave end have reached a synchronous state;
[0044] The master end is used to receive the generated local IP address master_ip, port number, and generate net_clock and base_time;
[0045] The slave end is used to connect to the master end to obtain net_clock and base_time.
[0046] Compared with the prior art, the present invention has at least the following beneficial effects: the method divides the playback device into a master end and a slave end, the slave end sets a timer, regularly connects to the master end, and obtains the network clock (net_clock), reference clock (base_time), current playback position and current playback URL (video address) generated by the master end. When the current playback URL and the master end URL are inconsistent, the slave end throws a MEDIA_INFO event (meidaplayer player event monitoring) to notify the upper-layer product application to play the URL of the master end, and the slave end sets the same network clock and reference clock as the master end based on the clock mechanism of gstreamer (by controlling time transfer, pipeline global system clock, reference clock, running clock, decoding output clock, etc. to achieve audio and video synchronous output) to achieve the function of synchronously playing the video list regardless of whether the master end or the slave end starts playing first. Compared with the prior art, the method makes the synchronous playback more stable and accurate, simple to operate, not limited by distance, and can play the video list synchronously. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] Figure 1 It is a schematic diagram of the process of an embodiment of the present invention;
[0048] Figure 2 A schematic diagram of the process from pausing to playing in an embodiment of the present invention;
[0049] Figure 3 Schematic diagram of the working status of the master end and the slave end. DETAILED DESCRIPTION
[0050] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.
[0051] Embodiment 1
[0052] A method for achieving multi-screen synchronous playback based on a gstreamer player, see Figure 1-Figure 3 , including the following steps:
[0053] S1: The intermediate adaptive layer between the gstreamer streaming media players assigns the master and slave roles to the terminals;
[0054] In this embodiment, two Android TVs based on gstreamer players are prepared, and the roles of master and slave are assigned to the two TVs.
[0055] S2: The intermediate adaptive layer allocates a local IP address master_ip and a port number to the master end, generates net_clock and base_time; the master end establishes a socket service: creates a socket service thread through 192.168.31.1 and 7771, and waits for the slave end to connect.
[0056] The master IP is 192.168.31.1 and the port is 7771.
[0057] The specific steps of generating net_clock and base_time by the intermediate adaptive layer are as follows:
[0058] S21: Get the current default system clock (system clock) through the gstreamer interface, create a new clock provider (provider_clock) and get the corresponding base_time;
[0059] S22: Obtain the clock synchronization port of the master end through the clock provider, and generate a new net_clock by obtaining the master_ip and clock synchronization port of the master end.
[0060] S3: The middle adaptive layer creates a socket service thread and monitors whether a new slave connection is captured;
[0061] S31: If a new slave connection is captured, the current playback position and the current playback URL are obtained and sent to the newly captured slave together with the generated net_clock and base_time.
[0062] S4: The slave sets the master IP address master_ip (192.168.31.1) and the master port number (7771), and connects to the master to obtain net_clock, base_time, current_position, and current_URL.
[0063] current_position=120s, master_URL="Demo Source - Transformers".
[0064] The slave end connects to the master end to obtain net_clock and base_time, which specifically includes the following steps:
[0065] S41: Connect to the master end through the obtained master_ip and master end port number;
[0066] In this embodiment, the slave end is connected to the socket service of the master end;
[0067] S42: If the connection fails, create a timer thread and connect once at a certain time interval until the connection is successful and net_clock, base_time, current_position and current_URL are successfully obtained;
[0068] In this embodiment, the time interval is 5 seconds;
[0069] S43: After the connection is successful, the thread is terminated to release resources.
[0070] S5: Set the generated net_clock and base_time to the gstreamer framework layer through the gstreamer interface, and detect whether the current master end and slave end are in a synchronized state;
[0071] S6: If the synchronization state is reached, start playing;
[0072] Synchronous status detection requires detection of net_clock, base_time, current_position and current_URL;
[0073] S7: If the synchronization state is not reached, a synchronization callback is set, and playback starts after receiving the synchronization callback.
[0074] In this embodiment, it is detected that the "Demo Source - Avatar" played by the slave end is different from the "Demo Source - Transformers" played by the master end, and the product application is notified to restart the broadcast and change to "Demo Source - Transformers".
[0075] The slave end restarts broadcasting and connects to the master end socket service: obtains net_clock, base_time, current_position = 120s, current_URL = "Demo Source - Transformers";
[0076] The slave detects that the currently playing "Demo Source - Transformers" is consistent with the URL of the master;
[0077] The slave uses the network clock obtained from the master: the obtained net_clock and base_time are set to the gstreamer framework layer through the gstreamer interface, the synchronized callback is set, and start is called when the synchronized callback is received.
[0078] Seek from the end to the 120s position and start playing. Seeking is to quickly achieve synchronous playback.
[0079] S8: When playback needs to be paused, perform the following steps:
[0080] S81: switch the state to pause;
[0081] S82: When it is necessary to restart the playback, first set the net_clock and base_time to detect whether the master end and the slave end are currently in a synchronized state;
[0082] S83: Start playing if it is synchronized;
[0083] S84: If net_clock, base_time, and current_position have not reached the synchronization state, a synchronization callback is set until the synchronization state is reached;
[0084] If the current playback URL is inconsistent with the master URL, a MEDIA_INFO event is thrown to notify the upper-layer application to replay the master URL.
[0085] The slave obtains the URL of the master, sets the master IP address master_ip and continues to perform subsequent steps.
[0086] S9: When the playback ends, net_clock and base_time are restored to the default values, and the socket service thread is terminated to release resources.
[0087] Embodiment 2
[0088] A system for realizing multi-screen synchronous playback based on a gstreamer player, comprising an intermediate adaptive layer between gstreamer streaming media players, a gstreamer framework layer, a master end, and a slave end;
[0089] The intermediate adaptive layer between the gstreamer streaming media players is used to allocate the master and slave roles to the terminals;
[0090] Assign the local IP address master_ip and port number to the master end, and generate net_clock and base_time;
[0091] The gstreamer framework layer is used to accept the generated net_clock and base_time, and detect whether the current master end and slave end have reached a synchronous state;
[0092] The master end is used to receive the generated local IP address master_ip, port number, and generate net_clock and base_time;
[0093] The slave end is used to connect to the master end to obtain net_clock and base_time.
[0094] Although the present invention is described herein with reference to the illustrative embodiments of the present invention, it should be understood that those skilled in the art can design many other modifications and implementations, which will fall within the scope and spirit of the principles disclosed in the present application. More specifically, within the scope disclosed in the present application, multiple variations and improvements can be made to the components and / or layout of the subject combination layout. In addition to the variations and improvements made to the components and / or layout, other uses will also be apparent to those skilled in the art.
Claims
1. A method for realizing multi-screen synchronous playback based on a gstreamer player, characterized in that: The following steps are involved: The intermediate adaptive layer between gstreamer's streaming media players assigns the master and slave roles to the terminals; The intermediate adaptive layer allocates a local IP address master_ip and a port number to the master end, and generates net_clock and base_time; The slave end sets the master end IP address master_ip and the master end port number, and the slave end connects to the master end to obtain net_clock, base_time, current_position and current_URL; Set the generated net_clock and base_time to the gstreamer framework layer through the gstreamer interface, and check whether the current master and slave are in synchronization; If the synchronization is achieved, playback starts; If the synchronization state is not reached, a synchronization callback is set and playback starts after receiving the synchronization callback.
2. A method for realizing multi-screen synchronous playback based on a gstreamer player as claimed in claim 1, characterized in that: The specific steps of generating net_clock and base_time by the intermediate adaptive layer are as follows: Get the current default system clock through the gstreamer interface, create a new clock provider and get the corresponding base_time; The clock synchronization port of the master end is obtained through the clock provider, and a new net_clock is generated by obtaining the master_ip and clock synchronization port of the master end.
3. A method for realizing multi-screen synchronous playback based on a gstreamer player as claimed in claim 1, characterized in that: After the master side assigns the local IP address master_ip, perform the following steps: The middle adaptive layer creates a socket service thread and monitors whether a new slave connection is captured; If a new slave connection is captured, the current playback position and current playback URL are obtained and sent to the newly captured slave together with the generated net_clock and base_time.
4. A method for realizing multi-screen synchronous playback based on a gstreamer player as claimed in claim 1, characterized in that: The slave end connects to the master end to obtain net_clock and base_time, which specifically includes the following steps: Connect to the master end through the obtained master_ip and master end port number; If the connection fails, create a timer thread and connect once at a certain time interval until the connection is successful and net_clock, base_time, current_position and current_URL are successfully obtained; After the connection is successful, end the thread to release resources.
5. A method for realizing multi-screen synchronous playback based on a gstreamer player as claimed in claim 1, characterized in that: When playback needs to be paused, the state needs to be switched to pause; When you need to restart playback, first set net_clock and base_time; Check whether the master and slave are currently in synchronization state. If not, set the synchronization callback; When the detection reaches the synchronization state, the playback starts.
6. A method for realizing multi-screen synchronous playback based on a gstreamer player as claimed in claim 5, characterized in that: The master detects that the synchronization is reached and before starting to play, it performs the following steps: The slave detects whether the current playback URL is consistent with the master URL. If they match, start playing; If they are inconsistent, a MEDIA_INFO event is thrown to notify the upper-layer application to replay the URL of the main end; The slave obtains the URL of the master, sets the master IP address master_ip and continues to perform subsequent steps.
7. A method for realizing multi-screen synchronous playback based on a gstreamer player as claimed in claim 1, characterized in that: When the playback ends, net_clock and base_time are restored to the default values, and the socket service thread is terminated to release resources.
8. A system for realizing multi-screen synchronous playback based on a gstreamer player, characterized in that: Including the intermediate adaptation layer between gstreamer's streaming media players, gstreamer framework layer, master end, and slave end; The intermediate adaptive layer between the gstreamer streaming media players is used to allocate the master and slave roles to the terminals; Assign the local IP address master_ip and port number to the master end, and generate net_clock and base_time; The gstreamer framework layer is used to accept the generated net_clock and base_time, and detect whether the current master end and slave end have reached a synchronous state; The master end is used to receive the generated local IP address master_ip, port number, and generate net_clock and base_time; The slave end is used to connect to the master end to obtain net_clock and base_time.