CN109246123B - Media stream acquisition method and device - Google Patents

Media stream acquisition method and device Download PDF

Info

Publication number
CN109246123B
CN109246123B CN201811157395.0A CN201811157395A CN109246123B CN 109246123 B CN109246123 B CN 109246123B CN 201811157395 A CN201811157395 A CN 201811157395A CN 109246123 B CN109246123 B CN 109246123B
Authority
CN
China
Prior art keywords
attribute
server
connection
target
value
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201811157395.0A
Other languages
Chinese (zh)
Other versions
CN109246123A (en
Inventor
吕现广
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Guangzhou Kugou Computer Technology Co Ltd
Original Assignee
Guangzhou Kugou Computer Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Guangzhou Kugou Computer Technology Co Ltd filed Critical Guangzhou Kugou Computer Technology Co Ltd
Priority to CN201811157395.0A priority Critical patent/CN109246123B/en
Publication of CN109246123A publication Critical patent/CN109246123A/en
Application granted granted Critical
Publication of CN109246123B publication Critical patent/CN109246123B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L65/00Network arrangements, protocols or services for supporting real-time applications in data packet communication
    • H04L65/1066Session management
    • H04L65/1069Session establishment or de-establishment
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L65/00Network arrangements, protocols or services for supporting real-time applications in data packet communication
    • H04L65/60Network streaming of media packets
    • H04L65/65Network streaming protocols, e.g. real-time transport protocol [RTP] or real-time control protocol [RTCP]
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L65/00Network arrangements, protocols or services for supporting real-time applications in data packet communication
    • H04L65/80Responding to QoS

Abstract

The invention discloses a media stream acquisition method and a media stream acquisition device, and belongs to the technical field of networks. The method comprises the following steps: when a live application is started, a target connection is established in advance, the target connection is used for acquiring a media stream from a server, and the live application is used for providing a plurality of live channels; detecting a state of the target connection; when the state of the target connection is an unavailable state, reestablishing the target connection; and when a media stream acquisition instruction of any live channel is received, acquiring the media stream of the live channel from the server based on the target connection. The invention can quickly acquire the corresponding media stream from the server directly based on the target connection established in advance when the media stream acquisition instruction is received, thereby reducing the time required by the terminal to acquire the media stream.

Description

Media stream acquisition method and device
Technical Field
The present invention relates to the field of network technologies, and in particular, to a method and an apparatus for acquiring a media stream.
Background
With the development of network technology, more and more users use terminals to watch live videos on the network, and the live videos are generally provided to the terminals in a media stream form based on a Real Time Messaging Protocol (RTMP) Protocol.
Currently, a user may click a certain live channel (live room) on a terminal, and when detecting the operation, the terminal establishes a connection with a streaming media server first, including handshaking, establishing a network connection and establishing a streaming connection with the streaming media server in sequence, and then sends a play instruction to the streaming media server to obtain a media stream from the streaming media server.
The above-mentioned technology establishes a connection with the server after detecting the user operation, and the establishment of the connection often takes a long time, resulting in a long time required for acquiring the media stream.
Disclosure of Invention
The embodiment of the invention provides a method and a device for acquiring a media stream, which can solve the problem of long time required for acquiring the media stream in the related technology. The technical scheme is as follows:
in a first aspect, a media stream acquiring method is provided, including:
when a live application is started, a target connection is established in advance, the target connection is used for acquiring a media stream from a server, and the live application is used for providing a plurality of live channels;
detecting a state of the target connection;
when the state of the target connection is an unavailable state, reestablishing the target connection;
and when a media stream acquisition instruction of any live channel is received, acquiring the media stream of the live channel from the server based on the target connection.
In one possible implementation, the pre-establishing the target connection includes:
allocating a pre-established connection object for a pre-established connection object pointer variable, initializing values of a first attribute, a second attribute and a third attribute of the pre-established connection object as a first target value, and a value of a fourth attribute as initial time, wherein the first attribute is used for describing whether TCP (Transmission Control Protocol) connection is established or not, the second attribute is used for describing whether a preposed instruction is completed or not, the third attribute is used for describing whether target connection is available or not, and the fourth attribute is used for describing the time of finally receiving a user Control message;
after the TCP connection is successfully established with the server, modifying the value of the first attribute into a second target value;
and after the interaction of a plurality of prepositive instructions with the server is successfully carried out, modifying the values of the second attribute and the third attribute into the second target value, and updating the value of the fourth attribute to the current time, wherein the prepositive instructions comprise a handshake instruction, a connection instruction and a stream creation instruction.
In one possible implementation, the detecting the state of the target connection includes:
attempting to read a user control message sent by the server;
when a user control message sent by the server is read, updating the value of the fourth attribute to the current time, and determining that the state of the target connection is an available state;
and when the user control message sent by the server is not read, determining the state of the target connection according to the time interval between the current time and the value of the fourth attribute.
In a possible implementation manner, the determining the state of the target connection according to a time interval between a current time and a value of the fourth attribute includes:
when the time interval between the current time and the value of the fourth attribute is greater than a preset time interval, determining that the state of the target connection is an unavailable state, wherein the preset time interval is greater than the time interval of the server for sending the user control message;
and when the time interval between the current time and the value of the fourth attribute is smaller than the preset time interval, after sleeping for a first preset time, determining the state of the target connection by executing the step of trying to read the user control message sent by the server, wherein the time interval corresponding to the first preset time is smaller than the time interval of sending the user control message by the server.
In one possible implementation, after the detecting the state of the target connection, the method further includes:
and when the target connection state is an available state, continuing to execute the step of trying to read the user control message sent by the server after sleeping for a first preset time.
In one possible implementation, the reestablishing the target connection when the status of the target connection is the unavailable status includes:
and when the target connection state is an unavailable state, after sleeping for a second preset time, closing the TCP connection, deleting the pre-established connection object, setting the pointer variable of the pre-established connection object to be null, and re-executing the step of pre-establishing the target connection.
In one possible implementation manner, when a media stream acquisition instruction for any live channel is received, acquiring a media stream of the live channel from the server based on the target connection includes:
when a media stream acquisition instruction of any live channel is received, acquiring a stream address and a stream name of the live channel;
and when the pointer variable of the pre-established connection object is not null and the value of the third attribute is the second target value, sending a play instruction to the server based on the target connection, and receiving the media stream sent by the server, wherein the play instruction carries the stream name and the stream identifier, and the stream identifier is obtained from a response result of the stream creation instruction.
In one possible implementation manner, after the obtaining of the stream address and the stream name of the live channel, the method further includes:
when the pointer variable of the pre-established connection object is empty, acquiring a media stream from the server based on the stream address; or the like, or, alternatively,
and when the pointer variable of the pre-established connection object is not null and the value of the third attribute is the first target value, acquiring the media stream from the server based on the stream address.
In a second aspect, a media stream acquiring apparatus is provided, which includes:
the system comprises an establishing module, a receiving module and a processing module, wherein the establishing module is used for establishing target connection in advance when a live application is started, the target connection is used for acquiring media streams from a server, and the live application is used for providing a plurality of live channels;
the detection module is used for detecting the state of the target connection;
the establishing module is further configured to reestablish the target connection when the state of the target connection is an unavailable state;
and the acquisition module is used for acquiring the media stream of the live channel from the server based on the target connection when receiving a media stream acquisition instruction of any live channel.
In one possible implementation, the establishing module is configured to:
allocating a pre-established connection object for a pre-established connection object pointer variable, initializing values of a first attribute, a second attribute and a third attribute of the pre-established connection object as a first target value, and initializing a value of a fourth attribute as initial time, wherein the first attribute is used for describing whether a Transmission Control Protocol (TCP) connection is established or not, the second attribute is used for describing whether a pre-instruction is completed or not, the third attribute is used for describing whether a target connection is available or not, and the fourth attribute is used for describing the time of finally receiving a user control message;
after the TCP connection is successfully established with the server, modifying the value of the first attribute into a second target value;
and after the interaction of a plurality of prepositive instructions with the server is successfully carried out, modifying the values of the second attribute and the third attribute into the second target value, and updating the value of the fourth attribute to the current time, wherein the prepositive instructions comprise a handshake instruction, a connection instruction and a stream creation instruction.
In one possible implementation, the detection module is configured to:
attempting to read a user control message sent by the server;
when a user control message sent by the server is read, updating the value of the fourth attribute to the current time, and determining that the state of the target connection is an available state;
and when the user control message sent by the server is not read, determining the state of the target connection according to the time interval between the current time and the value of the fourth attribute.
In one possible implementation, the detection module is configured to:
when the time interval between the current time and the value of the fourth attribute is greater than a preset time interval, determining that the state of the target connection is an unavailable state, wherein the preset time interval is greater than the time interval of the server for sending the user control message;
and when the time interval between the current time and the value of the fourth attribute is smaller than the preset time interval, after sleeping for a first preset time, determining the state of the target connection by executing the step of trying to read the user control message sent by the server, wherein the time interval corresponding to the first preset time is smaller than the time interval of sending the user control message by the server.
In a possible implementation manner, the detection module is further configured to, when the target connection state is an available state, continue to perform the step of attempting to read the user control packet sent by the server after sleeping for a first preset time.
In a possible implementation manner, the establishing module is configured to, when the target connection state is an unavailable state, after sleeping for a second preset duration, close the TCP connection, delete the pre-established connection object, set a pointer variable of the pre-established connection object to be null, and re-execute the step of pre-establishing the target connection.
In one possible implementation, the obtaining module is configured to:
when a media stream acquisition instruction of any live channel is received, acquiring a stream address and a stream name of the live channel;
and when the pointer variable of the pre-established connection object is not null and the value of the third attribute is the second target value, sending a play instruction to the server based on the target connection, and receiving the media stream sent by the server, wherein the play instruction carries the stream name and the stream identifier, and the stream identifier is obtained from a response result of the stream creation instruction.
In a possible implementation manner, the obtaining module is further configured to obtain a media stream from the server based on the stream address when the pointer variable of the pre-established connection object is empty; or the like, or, alternatively,
the obtaining module is further configured to obtain a media stream from the server based on the stream address when the pointer variable of the pre-established connection object is not null and the value of the third attribute is the first target value.
In a third aspect, a computer device is provided, comprising a processor and a memory; the memory is used for storing a computer program; the processor is configured to execute the computer program stored in the memory to implement the method steps of any one of the implementation manners of the first aspect.
In a fourth aspect, a computer-readable storage medium is provided, in which a computer program is stored which, when being executed by a processor, carries out the method steps of any of the implementations of the first aspect.
The technical scheme provided by the embodiment of the invention has the beneficial effects that at least:
by pre-establishing the target connection before receiving the media stream acquisition instruction and re-establishing the target connection once the target connection is detected to be unavailable, when the media stream acquisition instruction is received, the corresponding media stream can be quickly acquired from the server directly based on the pre-established target connection, and the time required by the terminal for acquiring the media stream is reduced.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings needed to be used in the description of the embodiments will be briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
Fig. 1 is a schematic diagram of an implementation environment of a media stream acquisition method according to an embodiment of the present invention;
fig. 2 is a flowchart of a media stream acquiring method according to an embodiment of the present invention;
fig. 3 is a flowchart of a media stream acquiring method according to an embodiment of the present invention;
fig. 4 is a schematic structural diagram of a media stream acquiring apparatus according to an embodiment of the present invention;
fig. 5 is a schematic structural diagram of a terminal 500 according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, embodiments of the present invention will be described in detail with reference to the accompanying drawings.
Fig. 1 is a schematic diagram of an implementation environment of a media stream acquisition method according to an embodiment of the present invention. Referring to fig. 1, the implementation environment may include a first terminal 101, a server 102, and a plurality of second terminals 103.
The first terminal 101 is a terminal for the anchor user to perform live broadcast, and the second terminal 103 is a terminal for obtaining a media stream for the audience user to watch live video. The server 102 is configured to provide a live service for the first terminal 101 and the second terminal 103, and specifically, the server 101 may provide a service to the first terminal 101 and the second terminal 103 through an application installed therein. The server 102 may be a streaming media server, and the multi-server 102 may be a server cluster composed of a plurality of servers.
The anchor user can perform live video broadcast in a live channel (live room) through the first terminal 101, and the viewer user of the second terminal 103 can log in the server 102 to enter the live channel of the anchor user. In the process of video live broadcast by the anchor user, the first terminal 101 may send the live video of the anchor user to the server 102 in real time in a media stream form, and the server 102 sends the live video to the second terminal 103 in the live broadcast channel, so that the second terminal 103 may obtain the media stream.
Fig. 2 is a flowchart of a media stream acquiring method according to an embodiment of the present invention. Referring to fig. 2, the method includes:
201. when a live application is started, a target connection is established in advance, the target connection is used for acquiring a media stream from a server, and the live application is used for providing a plurality of live channels.
202. The status of the target connection is detected.
203. And when the state of the target connection is the unavailable state, reestablishing the target connection.
204. And when a media stream acquisition instruction of any live channel is received, acquiring the media stream of the live channel from the server based on the target connection.
According to the method provided by the embodiment of the invention, the target connection is preset before the media stream acquisition instruction is received, and once the target connection is detected to be unavailable, the target connection is reestablished, so that when the media stream acquisition instruction is received, the corresponding media stream can be quickly acquired from the server directly based on the preset target connection, and the time required by the terminal to acquire the media stream is reduced.
In one possible implementation, the pre-establishing the target connection includes:
allocating a pre-established connection object for a pre-established connection object pointer variable, initializing values of a first attribute, a second attribute and a third attribute of the pre-established connection object as a first target value, and initializing a value of a fourth attribute as initial time, wherein the first attribute is used for describing whether a Transmission Control Protocol (TCP) connection is established or not, the second attribute is used for describing whether a preposed instruction is completed or not, the third attribute is used for describing whether a target connection is available or not, and the fourth attribute is used for describing the time of finally receiving a user control message;
after the TCP connection is successfully established with the server, the value of the first attribute is modified into a second target value;
and after the interaction of a plurality of preposed instructions with the server is successfully carried out, modifying the values of the second attribute and the third attribute into the second target value, and updating the value of the fourth attribute to the current time, wherein the plurality of preposed instructions comprise a handshake instruction, a connection instruction and a stream creation instruction.
In one possible implementation, the detecting the state of the target connection includes:
trying to read a user control message sent by the server;
when a user control message sent by the server is read, updating the value of the fourth attribute to the current time, and determining that the target connection state is an available state;
and when the user control message sent by the server is not read, determining the state of the target connection according to the time interval between the current time and the value of the fourth attribute.
In a possible implementation manner, the determining the state of the target connection according to a time interval between a current time and a value of the fourth attribute includes:
when the time interval between the current time and the value of the fourth attribute is greater than a preset time interval, determining that the state of the target connection is an unavailable state, wherein the preset time interval is greater than the time interval of sending a user control message by the server;
and when the time interval between the current time and the value of the fourth attribute is smaller than the preset time interval, after sleeping for a first preset time, determining the state of the target connection by executing the step of trying to read the user control message sent by the server, wherein the time interval corresponding to the first preset time is smaller than the time interval of sending the user control message by the server.
In one possible implementation, after detecting the state of the target connection, the method further includes:
and when the target connection state is an available state, continuing to execute the step of trying to read the user control message sent by the server after sleeping for a first preset time.
In one possible implementation, when the state of the target connection is an unavailable state, reestablishing the target connection includes:
and when the target connection state is an unavailable state, after sleeping for a second preset time, closing the TCP connection, deleting the pre-established connection object, setting the pointer variable of the pre-established connection object to be null, and re-executing the step of pre-establishing the target connection.
In one possible implementation manner, when receiving a media stream acquisition instruction for any live channel, acquiring a media stream of the live channel from the server based on the target connection includes:
when a media stream acquisition instruction of any live channel is received, acquiring a stream address and a stream name of the live channel;
and when the pointer variable of the pre-established connection object is not null and the value of the third attribute is the second target value, sending a play instruction to the server based on the target connection, receiving the media stream sent by the server, wherein the play instruction carries the stream name and the stream identifier, and the stream identifier is obtained from a response result of the stream creation instruction.
In one possible implementation, after obtaining the stream address and the stream name of the live channel, the method further includes:
when the pointer variable of the pre-established connection object is empty, acquiring a media stream from the server based on the stream address; or the like, or, alternatively,
and when the pointer variable of the pre-established connection object is not null and the value of the third attribute is the first target value, acquiring the media stream from the server based on the stream address.
All the above-mentioned optional technical solutions can be combined arbitrarily to form the optional embodiments of the present invention, and are not described herein again.
Fig. 3 is a flowchart of a media stream acquiring method according to an embodiment of the present invention. The method may be performed by a terminal, which may be the second terminal 103 in the implementation environment shown in fig. 1, see fig. 3, the method comprising:
301. when a live application is started, a terminal establishes a target connection in advance, the target connection is used for acquiring a media stream from a server, and the live application is used for providing a plurality of live channels.
The target connection may be an RTMP streaming connection, the live channel is also called a live room, and the server may be a streaming server.
In the embodiment of the invention, a user can start the live application on the terminal, for example, an icon of the live application is clicked, and a start instruction of the live application is triggered. When receiving the start instruction, the terminal can start the live broadcast application and establish a target connection. In a possible implementation manner, in the process of starting the live application, the terminal may initialize a video player, play the subsequently acquired media stream through the video player, and initialize a pre-established connection management module, and execute the process of establishing the target connection in advance through the pre-established connection management module.
Of course, the embodiment of the present invention is described by taking the example that the terminal establishes the target connection when the live broadcast application is started as an example, in fact, the terminal may also establish the target connection at other occasions before the user clicks any live broadcast channel to trigger the media stream acquisition instruction, and the embodiment of the present invention does not limit this.
In a possible implementation manner, before the terminal establishes the target connection in advance, step 3011 may be performed:
step 3011, the terminal initializes the pointer variable of the pre-established connection object to null, and obtains the domain name.
The pre-established join object pointer variable may be denoted as "PSLinkObjectPtr", which when empty "NULL" indicates that the pointer variable does not point to any object.
In a possible implementation manner, the terminal may send a domain name acquisition request to the streaming media scheduling management server, and the streaming media scheduling management server returns a domain name of the streaming media server system to the terminal, where the domain name corresponds to an IP address of a server that the terminal may access when acquiring the media stream.
In a possible implementation manner, the terminal may initialize a pointer variable of a pre-established connection object, acquire a domain name, and start a pre-established connection management thread when initializing the pre-established connection management module, where the thread is responsible for pre-establishing a target connection. In one possible implementation, the establishment procedure of the target connection may include steps 3012 to 3017:
step 3012, when the pointer variable of the pre-established connection object is empty, the terminal allocates the pre-established connection object to the pointer variable of the pre-established connection object, initializes values of the first attribute, the second attribute, and the third attribute of the pre-established connection object as a first target value, and initializes a value of the fourth attribute as an initial time, and then executes step 3013.
Wherein the first attribute is used for describing whether a TCP connection is established, and the first attribute can be represented by a variable 'IsTCPAvailable'; the second attribute is used for describing whether the pre-instruction is completed or not, and the second attribute can be represented by a variable 'IsPreCommand finished'; the third attribute is used to describe whether the target connection is available, the third attribute may be represented by a variable "IsALive", the fourth attribute is used to describe the time when the user control packet is finally received, and the fourth attribute may be represented by a variable "LastRPingTime".
The first attribute, the second attribute, and the third attribute may each have two values, such as a first target value and a second target value, and the first target value and the second target value may each be a logical value, for example, the first target value may be False and the second target value may be True. The value of the fourth attribute is time, and the initial time may be 0.
When the value of the first attribute is a first target value, the TCP connection is not established, and when the value of the first attribute is a second target value, the TCP connection is established; when the value of the second attribute is the first target value, indicating that the preposed instruction is not finished, and when the value of the second attribute is the second target value, indicating that the preposed instruction is finished; and when the value of the third attribute is the first target value, the target connection is not available, and when the value of the third attribute is the second target value, the target connection is available.
And after the terminal distributes the pre-established connection object to the pointer variable of the pre-established connection object, the pointer variable of the pre-established connection object is not null.
3013, when the value of the first attribute is the first target value, the terminal establishes a TCP connection with the server, if the TCP connection fails, after sleeping for a second preset duration, deletes the pre-established connection object, sets the pointer variable of the pre-established connection object to null, and re-executes step 3012; if the result is successful, the value of the first attribute is modified to the second target value, and step 3014 is executed.
In step 3011, the terminal acquires a domain name, and in step 3013, the terminal may acquire an IP (Internet Protocol) address corresponding to the domain name and establish a TCP connection with a server corresponding to the IP address. For example, the terminal may resolve the Domain Name into the corresponding IP address through a DNS (Domain Name System) server, for example, the terminal may send a Domain Name resolution request to the DNS server, where the Domain Name resolution request carries the Domain Name acquired in step 3011, and the DNS server returns the IP address corresponding to the Domain Name.
Step 3014, when the value of the second attribute is the first target value, the terminal and the server perform interaction of multiple pre-instructions, if any instruction fails, after sleeping for a second preset duration, close the TCP connection, delete the pre-established connection object, and set the pointer variable of the pre-established connection object to null; and if the time is successful, modifying the values of the second attribute and the third attribute into a second target value, and updating the value of the fourth attribute into the current time.
The prefix instruction is an instruction before the Play (Play) instruction, and the plurality of prefix instructions include a handshake instruction, a Connect instruction, and a create stream (CreateStream) instruction.
The interaction of the plurality of preposed instructions between the terminal and the server comprises the following steps: the terminal initiates an RTMP handshake process to the server, sends a Connect command to the server after the handshake is completed, waits for a response result, then initiates a CreateStream command to the server, and waits for the response result. The handshake process is used for judging whether the terminal and the server exist or not; after the Connect command is successful, establishing network connection between the terminal and the server, but the terminal cannot support media stream transmission; after the CreateStream instruction is successful, the media stream can be transmitted between the terminal and the server.
In a possible implementation manner, after the interaction of the plurality of prearranged commands with the server is successful, the terminal may obtain a stream identifier from a response result of the create stream command, where the stream identifier is also a stream ID (identification).
In the process of the terminal performing the pre-instruction interaction with the server, the terminal receives the response result of the server, and even if the response result is not the user control message, the terminal can still determine that the connection between the terminal and the server is available through the response result, so that the terminal can update the value of the fourth attribute once.
For the server, after receiving the TCP connection, the RTMP handshake, the Connect instruction, and the createstatream instruction initiated by the terminal, the server may perform corresponding processing. For example, the receiving of the instructions and the processing steps may be performed by a host process of the server.
After the terminal establishes the target connection in advance, since the user has not clicked any live channel, the terminal needs to maintain the heartbeat of the target connection established in advance, and the specific process refers to the following steps 302 to 303.
302. The terminal detects the state of the target connection, wherein the state comprises an available state and an unavailable state.
The available state represents that the terminal can acquire the media stream from the server based on the target connection established in advance, and the unavailable state represents that the terminal cannot acquire the media stream from the server based on the target connection established in advance.
In this embodiment of the present invention, a terminal may perform information interaction with a server to detect a state of a target connection, and in a possible implementation manner, the information interaction may be interaction of a user control packet, and accordingly, the step 302 may include the following steps 3021 to 3023:
step 3021, the terminal tries to read the user control packet sent by the server, and when the user control packet sent by the server is read, the value of the fourth attribute is updated to the current time, the target connection state is determined to be an available state, and step 3022 is executed; when the user control message sent by the server is not read, step 3023 is executed.
In the embodiment of the invention, the terminal can perform user control message interaction with the server, and the state of the target connection is determined according to the interaction condition. For example, the terminal may attempt to read a Ping user control message from the server, and if the Ping user control message is read, respond to the server with a Pong user control message. The terminal receives the control message from the server, which indicates that the pre-established target connection is in an available state, so that the terminal can update the value of the fourth attribute.
Accordingly, the server may send a Ping user control message to the server based on the pre-established target connection at a certain time interval, and wait for a Pong user control message responded by the terminal. For example, the step of sending the control message to the terminal may be performed by a host process of the server.
It should be noted that, in the embodiment of the present invention, the user control packet interaction is performed between the terminal and the server to determine the state of the target connection, and actually, other interaction manners, such as interaction of heartbeat information, may also be used between the terminal and the server to determine the state of the target connection.
Step 3022, when the target connection state is the available state, after the terminal sleeps for the first preset time period, continuing to perform the step of attempting to read the user control packet sent by the server.
The time interval corresponding to the first preset time length is smaller than the time interval of the server sending the user control message, for example, the time interval of the server sending the user control message is 5 seconds, and the first preset time length is 1 second.
In the embodiment of the invention, when the terminal detects that the target connection is in the available state, the terminal can sleep for a period of time and then try to read the user control message from the server, wherein the sleep time is less than the time interval for sending the user control message by the server.
Step 3023, the terminal obtains the current time, determines whether a time interval between the current time and a value of the fourth attribute is greater than a preset time interval, determines that the target connection state is an unavailable state if the time interval is greater than the preset time interval, and determines the target connection state by performing a step of attempting to read a user control packet sent by the server after sleeping for a first preset time period if the time interval is not greater than the preset time interval.
The preset time interval is greater than the time interval for the server to send the user control packet, for example, the time interval for the server to send the user control packet is 5 seconds, and the preset time interval may be 8 seconds.
And if the time interval between the current time and the value of the fourth attribute is greater than the preset time interval, indicating that the target connection established in advance has risk and is unavailable. And if the time interval is smaller than the preset time interval, sleeping for a period of time and continuing to detect the state.
It should be noted that, the step 3023 is a possible implementation manner of determining the state of the target connection according to a time interval between the current time and the value of the fourth attribute. According to the difference value between the current time and the time of receiving the user control message at last, whether the interaction of the user control message is normally carried out between the terminal and the server can be accurately known, and therefore the target connection state is determined.
303. And when the state of the target connection is the unavailable state, the terminal reestablishes the target connection.
In one possible implementation manner, the process of the terminal reestablishing the target connection includes: when the target connection state is the unavailable state, after sleeping for a second preset time, closing the TCP connection of the pre-established connection object pointed by the pre-established connection object pointer variable, deleting the pre-established connection object pointed by the pre-established connection object pointer variable, setting the pre-established connection object pointer variable to be null, and re-executing the step of pre-establishing the target connection, that is, re-executing the steps 3012 to 3014. Wherein the second predetermined duration may be set to be shorter than the first predetermined duration, such as 10 milliseconds.
Through steps 302 to 303, a reliable target connection can be maintained between the terminal and the server, so that when a user clicks a live channel, the terminal can directly use the target connection to acquire a media stream from the server.
304. And when a media stream acquisition instruction of any live channel is received, the terminal acquires the media stream of the live channel from the server based on the target connection.
In the embodiment of the invention, after the terminal starts the live broadcast application, a plurality of live broadcast channels provided by the live broadcast application can be displayed, a user can click any one of the live broadcast channels to trigger a media stream acquisition instruction for the live broadcast channel, and after the terminal receives the media stream acquisition instruction, the terminal can request the server to acquire the media stream of the live broadcast channel for playing.
In one possible implementation, obtaining the media stream of the live channel from the server based on the target connection includes the following steps 3041 to 3046:
step 3041, when receiving a media stream acquiring instruction for any live channel, the terminal acquires a stream address and a stream name of the live channel.
In the embodiment of the invention, all live channels provided by the live application are corresponding to the stream addresses and the stream names, and when a user clicks any live channel, the terminal can acquire the stream address (streamURL) and the stream name (streamName) of the live channel clicked by the user according to the corresponding relation between the live channel and the stream addresses and the stream names.
In a possible implementation manner, the streaming media scheduling management server may store a correspondence between an identifier of a live channel and a stream address and a stream name, when the terminal detects that a user clicks any one of the live channels, the terminal may send a request to the streaming media scheduling management server, where the request carries the identifier of the live channel clicked by the user, and the streaming media scheduling management server may query the correspondence according to the identifier of the live channel sent by the terminal, and send the corresponding stream address and stream name to the terminal, so that the terminal obtains the stream address and stream name of the live channel.
Step 3042, the terminal determines whether the value of the pointer variable of the pre-established connection object is null, if yes, step 3044 is executed, if not, step 3043 is executed.
The terminal may first determine whether a value of the pointer variable of the pre-established connection object is null, if so, the terminal may perform step 3043, and if not, the terminal may perform the step of reading the third attribute.
Step 3043, the terminal determines whether a value of a third attribute of the pre-established connection object pointed by the pointer variable of the pre-established connection object is a first target value, if so, executes step 3044, and if not, executes step 3045.
When the value of the third attribute is the first target value, the target connection is available, and when the value of the third attribute is not the first target value, the target connection is unavailable.
Step 3044, the terminal obtains the media stream from the server based on the stream address.
In this embodiment of the present invention, when the pre-established connection object pointer variable is empty, the terminal performs the step 3044, or when the pre-established connection object pointer variable is not empty and the value of the third attribute is the first target value, the terminal performs the step 3044.
In step 3044, the terminal executes a normal media stream acquiring procedure based on the stream address, where the acquiring process of the media stream may include: after establishing TCP connection and carrying out preposed instruction interaction with the server, the terminal sends a Play instruction (Play instruction) to the server based on the stream address and receives a media stream returned by the server.
Step 3045, the terminal sends a play instruction to the server based on the target connection, where the play instruction carries the stream identifier and the stream name.
Wherein the stream identification is obtained from the response result of the create stream instruction in step 3015.
In this embodiment of the present invention, when the pointer variable of the pre-established connection object is not null and the value of the third attribute is the second target value, the terminal performs the step 3045. After the terminal establishes the target connection in advance, a channel for transmitting the media stream is arranged between the terminal and the server, so that the terminal can send a Play instruction to the server to request the server to start sending the media stream to the terminal when the terminal needs to acquire the media stream. The stream name carried in the Play instruction is used to identify which media stream needs to be acquired, each media stream corresponds to one stream name, and the server can transmit the media stream corresponding to the stream name to the terminal according to the stream name carried in the Play instruction. The stream identifier carried in the Play identifier command is used to distinguish which stream name the transmitted video frame belongs to, and the stream identifier may also be used to distinguish the memory buffers (including the sending and receiving buffers) of different media streams, associated objects, some attributes and other related information by the server, so as to ensure the correct transmission of the media streams.
In a possible implementation manner, when the value of the third attribute is the second target value, the terminal may assign the pre-established link object pointer variable to the link object pointer variable, set the pre-established link object pointer variable to be null, then send a Play instruction to the server based on the target connection with the stream identifier and the stream name as parameters, and wait for the media stream.
Step 3046, the terminal receives the media stream sent by the server.
After the terminal sends the Play instruction to the server, the server can analyze the stream identifier and the stream name carried by the Play instruction, and then the server can judge whether the media stream corresponding to the stream name exists or not, if so, the media stream is forwarded to the terminal, and if not, the media stream is requested to the superior server and then forwarded to the terminal.
The receiving of the Play instruction, the parsing of the stream identifier and the stream name may be performed by a main process of the server, and further, the main process may transfer a target connection established in advance to a sub-process of the server, and transfer the target connection to a target sub-process as much as possible, where the target sub-process refers to a sub-process that has already pulled a media stream corresponding to the stream name from an upper server, and of course, if the target sub-process does not exist, that is, if none of the sub-processes has pulled a media stream corresponding to the stream name from an upper server, the main process may select a sub-process with the smallest load and transfer the target connection established in advance to the sub-process with the smallest load. Then, the sub-process transferred to the target connection may determine whether a media stream corresponding to the stream name exists, if so, forward the media stream to the terminal based on the target connection, and if not, request the media stream to the upper-level server, and then forward the media stream to the terminal based on the target connection, so that the terminal may receive the media stream.
After the terminal acquires the media stream, the terminal may further decode and render the media stream, and display the first frame of the video. The action of establishing the connection is advanced, the target connection is established in advance before the user watches the video, after the instruction of watching a certain live channel by the user is received, the established target connection is directly used, the Play instruction is immediately sent to the server, and the media stream sent by the server can be quickly received, so that the first screen duration of the video is reduced, and the waiting time of the user for watching the first frame of the video is reduced. The first screen duration is a duration corresponding to a period from receiving a media stream acquisition instruction triggered by a user to displaying a first frame of a video.
Alternatively, the terminal may destroy the target connection when the live application is closed. For example, a user may perform an operation of closing a live application on a terminal, trigger a closing instruction for the live application, and when receiving the closing instruction, the terminal may close the live application and destroy a target connection. In a possible implementation manner, in the process of closing the live broadcast application, the terminal may destroy the video player, destroy the pre-established connection management module, stop the pre-established connection management thread, close the network connection of the pre-established connection object indicated by the pre-established connection object pointer variable, and delete the pre-established connection object.
According to the method provided by the embodiment of the invention, the target connection is preset before the media stream acquisition instruction is received, and once the target connection is detected to be unavailable, the target connection is reestablished, so that when the media stream acquisition instruction is received, the corresponding media stream can be quickly acquired from the server directly based on the preset target connection, and the time required by the terminal to acquire the media stream is reduced.
Fig. 4 is a schematic structural diagram of a media stream acquiring apparatus according to an embodiment of the present invention. Referring to fig. 4, the apparatus includes:
an establishing module 401, configured to, when a live application is started, establish a target connection in advance, where the target connection is used to obtain a media stream from a server, and the live application is used to provide a plurality of live channels;
a detection module 402, configured to detect a status of the target connection;
the establishing module 401 is further configured to reestablish the target connection when the status of the target connection is an unavailable status;
an obtaining module 403, configured to, when a media stream obtaining instruction for any live channel is received, obtain a media stream of the live channel from the server based on the target connection.
In one possible implementation, the establishing module 401 is configured to:
allocating a pre-established connection object for a pre-established connection object pointer variable, initializing values of a first attribute, a second attribute and a third attribute of the pre-established connection object as a first target value, and initializing a value of a fourth attribute as initial time, wherein the first attribute is used for describing whether a Transmission Control Protocol (TCP) connection is established or not, the second attribute is used for describing whether a preposed instruction is completed or not, the third attribute is used for describing whether a target connection is available or not, and the fourth attribute is used for describing the time of finally receiving a user control message;
after the TCP connection is successfully established with the server, the value of the first attribute is modified into a second target value;
and after the interaction of a plurality of preposed instructions with the server is successfully carried out, modifying the values of the second attribute and the third attribute into the second target value, and updating the value of the fourth attribute to the current time, wherein the plurality of preposed instructions comprise a handshake instruction, a connection instruction and a stream creation instruction.
In one possible implementation, the detection module 402 is configured to:
trying to read a user control message sent by the server;
when a user control message sent by the server is read, updating the value of the fourth attribute to the current time, and determining that the target connection state is an available state;
and when the user control message sent by the server is not read, determining the state of the target connection according to the time interval between the current time and the value of the fourth attribute.
In one possible implementation, the detection module 402 is configured to:
when the time interval between the current time and the value of the fourth attribute is greater than a preset time interval, determining that the state of the target connection is an unavailable state, wherein the preset time interval is greater than the time interval of sending a user control message by the server;
and when the time interval between the current time and the value of the fourth attribute is smaller than the preset time interval, after sleeping for a first preset time, determining the state of the target connection by executing the step of trying to read the user control message sent by the server, wherein the time interval corresponding to the first preset time is smaller than the time interval of sending the user control message by the server.
In a possible implementation manner, the detecting module 402 is further configured to, when the target connection state is an available state, continue to perform the step of attempting to read the user control packet sent by the server after sleeping for a first preset time.
In a possible implementation manner, the establishing module 401 is configured to close the TCP connection, delete the pre-established connection object, set the pointer variable of the pre-established connection object to be null, and re-execute the step of pre-establishing the target connection after sleeping for a second preset duration when the state of the target connection is the unavailable state.
In one possible implementation, the obtaining module 403 is configured to:
when a media stream acquisition instruction of any live channel is received, acquiring a stream address and a stream name of the live channel;
and when the pointer variable of the pre-established connection object is not null and the value of the third attribute is the second target value, sending a play instruction to the server based on the target connection, receiving the media stream sent by the server, wherein the play instruction carries the stream name and the stream identifier, and the stream identifier is obtained from a response result of the stream creation instruction.
In a possible implementation manner, the obtaining module 403 is further configured to obtain a media stream from the server based on the stream address when the pointer variable of the pre-established connection object is empty; or the like, or, alternatively,
the obtaining module 403 is further configured to obtain a media stream from the server based on the stream address when the pointer variable of the pre-established connection object is not null and the value of the third attribute is the first target value.
In the embodiment of the invention, the target connection is preset before the media stream acquisition instruction is received, and once the target connection is detected to be unavailable, the target connection is reestablished, so that when the media stream acquisition instruction is received, the corresponding media stream can be quickly acquired from the server directly based on the preset target connection, and the time required by the terminal for acquiring the media stream is reduced.
It should be noted that: the media stream acquiring apparatus provided in the foregoing embodiment is only illustrated by dividing the functional modules when acquiring a media stream, and in practical applications, the functions may be distributed by different functional modules according to needs, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the media stream acquiring apparatus and the media stream acquiring method provided in the above embodiments belong to the same concept, and specific implementation processes thereof are detailed in the method embodiments and will not be described herein again.
Fig. 5 is a schematic structural diagram of a terminal 500 according to an embodiment of the present invention. The terminal 500 may be: a smart phone, a tablet computer, an MP3 player (Moving Picture Experts Group Audio Layer III, motion video Experts compression standard Audio Layer 3), an MP4 player (Moving Picture Experts Group Audio Layer IV, motion video Experts compression standard Audio Layer 4), a notebook computer, or a desktop computer. Terminal 500 may also be referred to by other names such as user equipment, portable terminal, laptop terminal, desktop terminal, and the like.
In general, the terminal 500 includes: a processor 501 and a memory 502.
The processor 501 may include one or more processing cores, such as a 4-core processor, an 8-core processor, and so on. The processor 501 may be implemented in at least one hardware form of a DSP (Digital Signal Processing), an FPGA (Field-Programmable Gate Array), and a PLA (Programmable Logic Array). The processor 501 may also include a main processor and a coprocessor, where the main processor is a processor for Processing data in an awake state, and is also called a Central Processing Unit (CPU); a coprocessor is a low power processor for processing data in a standby state. In some embodiments, the processor 501 may be integrated with a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content required to be displayed on the display screen. In some embodiments, processor 501 may also include an AI (Artificial Intelligence) processor for processing computational operations related to machine learning.
Memory 502 may include one or more computer-readable storage media, which may be non-transitory. Memory 502 may also include high-speed random access memory, as well as non-volatile memory, such as one or more magnetic disk storage devices, flash memory storage devices. In some embodiments, a non-transitory computer readable storage medium in memory 502 is used to store at least one instruction for execution by processor 501 to implement the media stream acquisition method provided by the method embodiments herein.
In some embodiments, the terminal 500 may further optionally include: a peripheral interface 503 and at least one peripheral. The processor 501, memory 502 and peripheral interface 503 may be connected by a bus or signal lines. Each peripheral may be connected to the peripheral interface 503 by a bus, signal line, or circuit board. Specifically, the peripheral device includes: at least one of radio frequency circuitry 504, display screen 505, camera 506, audio circuitry 507, positioning components 508, and power supply 509.
The peripheral interface 503 may be used to connect at least one peripheral related to I/O (Input/Output) to the processor 501 and the memory 502. In some embodiments, the processor 501, memory 502, and peripheral interface 503 are integrated on the same chip or circuit board; in some other embodiments, any one or two of the processor 501, the memory 502, and the peripheral interface 503 may be implemented on a separate chip or circuit board, which is not limited in this embodiment.
The Radio Frequency circuit 504 is used for receiving and transmitting RF (Radio Frequency) signals, also called electromagnetic signals. The radio frequency circuitry 504 communicates with communication networks and other communication devices via electromagnetic signals. The rf circuit 504 converts an electrical signal into an electromagnetic signal to transmit, or converts a received electromagnetic signal into an electrical signal. Optionally, the radio frequency circuit 504 includes: an antenna system, an RF transceiver, one or more amplifiers, a tuner, an oscillator, a digital signal processor, a codec chipset, a subscriber identity module card, and so forth. The radio frequency circuitry 504 may communicate with other terminals via at least one wireless communication protocol. The wireless communication protocols include, but are not limited to: metropolitan area networks, various generation mobile communication networks (2G, 3G, 4G, and 5G), Wireless local area networks, and/or WiFi (Wireless Fidelity) networks. In some embodiments, the rf circuit 504 may further include NFC (Near Field Communication) related circuits, which are not limited in this application.
The display screen 505 is used to display a UI (user interface). The UI may include graphics, text, icons, video, and any combination thereof. When the display screen 505 is a touch display screen, the display screen 505 also has the ability to capture touch signals on or over the surface of the display screen 505. The touch signal may be input to the processor 501 as a control signal for processing. At this point, the display screen 505 may also be used to provide virtual buttons and/or a virtual keyboard, also referred to as soft buttons and/or a soft keyboard. In some embodiments, the display screen 505 may be one, providing the front panel of the terminal 500; in other embodiments, the display screens 505 may be at least two, respectively disposed on different surfaces of the terminal 500 or in a folded design; in still other embodiments, the display 505 may be a flexible display disposed on a curved surface or on a folded surface of the terminal 500. Even more, the display screen 505 can be arranged in a non-rectangular irregular figure, i.e. a shaped screen. The Display screen 505 may be made of LCD (Liquid Crystal Display), OLED (Organic Light-Emitting Diode), and other materials.
The camera assembly 506 is used to capture images or video. Optionally, camera assembly 506 includes a front camera and a rear camera. Generally, a front camera is disposed at a front panel of the terminal, and a rear camera is disposed at a rear surface of the terminal. In some embodiments, the number of the rear cameras is at least two, and each rear camera is any one of a main camera, a depth-of-field camera, a wide-angle camera and a telephoto camera, so that the main camera and the depth-of-field camera are fused to realize a background blurring function, and the main camera and the wide-angle camera are fused to realize panoramic shooting and VR (Virtual Reality) shooting functions or other fusion shooting functions. In some embodiments, camera assembly 506 may also include a flash. The flash lamp can be a monochrome temperature flash lamp or a bicolor temperature flash lamp. The double-color-temperature flash lamp is a combination of a warm-light flash lamp and a cold-light flash lamp, and can be used for light compensation at different color temperatures.
Audio circuitry 507 may include a microphone and a speaker. The microphone is used for collecting sound waves of a user and the environment, converting the sound waves into electric signals, and inputting the electric signals to the processor 501 for processing, or inputting the electric signals to the radio frequency circuit 504 to realize voice communication. For the purpose of stereo sound collection or noise reduction, a plurality of microphones may be provided at different portions of the terminal 500. The microphone may also be an array microphone or an omni-directional pick-up microphone. The speaker is used to convert electrical signals from the processor 501 or the radio frequency circuit 504 into sound waves. The loudspeaker can be a traditional film loudspeaker or a piezoelectric ceramic loudspeaker. When the speaker is a piezoelectric ceramic speaker, the speaker can be used for purposes such as converting an electric signal into a sound wave audible to a human being, or converting an electric signal into a sound wave inaudible to a human being to measure a distance. In some embodiments, audio circuitry 507 may also include a headphone jack.
The positioning component 508 is used for positioning the current geographic Location of the terminal 500 for navigation or LBS (Location Based Service). The Positioning component 508 may be a Positioning component based on the united states GPS (Global Positioning System), the chinese beidou System, the russian graves System, or the european union's galileo System.
Power supply 509 is used to power the various components in terminal 500. The power source 509 may be alternating current, direct current, disposable or rechargeable. When power supply 509 includes a rechargeable battery, the rechargeable battery may support wired or wireless charging. The rechargeable battery may also be used to support fast charge technology.
In some embodiments, terminal 500 also includes one or more sensors 510. The one or more sensors 510 include, but are not limited to: acceleration sensor 511, gyro sensor 512, pressure sensor 513, fingerprint sensor 514, optical sensor 515, and proximity sensor 516.
The acceleration sensor 511 may detect the magnitude of acceleration on three coordinate axes of the coordinate system established with the terminal 500. For example, the acceleration sensor 511 may be used to detect components of the gravitational acceleration in three coordinate axes. The processor 501 may control the touch screen 505 to display the user interface in a landscape view or a portrait view according to the gravitational acceleration signal collected by the acceleration sensor 511. The acceleration sensor 511 may also be used for acquisition of motion data of a game or a user.
The gyro sensor 512 may detect a body direction and a rotation angle of the terminal 500, and the gyro sensor 512 may cooperate with the acceleration sensor 511 to acquire a 3D motion of the user on the terminal 500. The processor 501 may implement the following functions according to the data collected by the gyro sensor 512: motion sensing (such as changing the UI according to a user's tilting operation), image stabilization at the time of photographing, game control, and inertial navigation.
The pressure sensor 513 may be disposed on a side bezel of the terminal 500 and/or an underlying layer of the touch display screen 505. When the pressure sensor 513 is disposed on the side frame of the terminal 500, a user's holding signal of the terminal 500 may be detected, and the processor 501 performs left-right hand recognition or shortcut operation according to the holding signal collected by the pressure sensor 513. When the pressure sensor 513 is disposed at the lower layer of the touch display screen 505, the processor 501 controls the operability control on the UI interface according to the pressure operation of the user on the touch display screen 505. The operability control comprises at least one of a button control, a scroll bar control, an icon control and a menu control.
The fingerprint sensor 514 is used for collecting a fingerprint of the user, and the processor 501 identifies the identity of the user according to the fingerprint collected by the fingerprint sensor 514, or the fingerprint sensor 514 identifies the identity of the user according to the collected fingerprint. Upon recognizing that the user's identity is a trusted identity, the processor 501 authorizes the user to perform relevant sensitive operations including unlocking the screen, viewing encrypted information, downloading software, paying, and changing settings, etc. The fingerprint sensor 514 may be provided on the front, back, or side of the terminal 500. When a physical button or a vendor Logo is provided on the terminal 500, the fingerprint sensor 514 may be integrated with the physical button or the vendor Logo.
The optical sensor 515 is used to collect the ambient light intensity. In one embodiment, the processor 501 may control the display brightness of the touch display screen 505 based on the ambient light intensity collected by the optical sensor 515. Specifically, when the ambient light intensity is high, the display brightness of the touch display screen 505 is increased; when the ambient light intensity is low, the display brightness of the touch display screen 505 is turned down. In another embodiment, processor 501 may also dynamically adjust the shooting parameters of camera head assembly 506 based on the ambient light intensity collected by optical sensor 515.
A proximity sensor 516, also referred to as a distance sensor, is typically disposed on the front panel of the terminal 500. The proximity sensor 516 is used to collect the distance between the user and the front surface of the terminal 500. In one embodiment, when the proximity sensor 516 detects that the distance between the user and the front surface of the terminal 500 gradually decreases, the processor 501 controls the touch display screen 505 to switch from the bright screen state to the dark screen state; when the proximity sensor 516 detects that the distance between the user and the front surface of the terminal 500 becomes gradually larger, the processor 501 controls the touch display screen 505 to switch from the screen-rest state to the screen-on state.
Those skilled in the art will appreciate that the configuration shown in fig. 5 is not intended to be limiting of terminal 500 and may include more or fewer components than those shown, or some components may be combined, or a different arrangement of components may be used.
In an exemplary embodiment, a computer-readable storage medium, such as a memory, storing a computer program is also provided, which when executed by a processor implements the media stream acquisition method in the above embodiments. For example, the computer-readable storage medium may be a Read-Only Memory (ROM), a Random Access Memory (RAM), a Compact Disc Read-Only Memory (CD-ROM), a magnetic tape, a floppy disk, an optical data storage device, and the like.
It will be understood by those skilled in the art that all or part of the steps for implementing the above embodiments may be implemented by hardware, or may be implemented by a program instructing relevant hardware, where the program may be stored in a computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a magnetic disk or an optical disk, etc.
The above description is only for the purpose of illustrating the preferred embodiments of the present invention and is not to be construed as limiting the invention, and any modifications, equivalents, improvements and the like that fall within the spirit and principle of the present invention are intended to be included therein.

Claims (14)

1. A media stream acquisition method, the method comprising:
when a live application is started, a target connection is established in advance, the target connection is used for acquiring a media stream from a server, and the live application is used for providing a plurality of live channels;
detecting a state of the target connection;
when the state of the target connection is an unavailable state, reestablishing the target connection;
when a media stream acquisition instruction of any live channel is received, acquiring a media stream of the live channel from the server based on the target connection;
prior to the step of pre-establishing a target connection, the method further comprises: initializing a pointer variable of a pre-built connection object to be null;
the pre-establishing of the target connection comprises:
when a pointer variable of a pre-established connection object is empty, allocating the pre-established connection object for the pointer variable of the pre-established connection object, initializing values of a first attribute, a second attribute and a third attribute of the pre-established connection object as a first target value, initializing a value of a fourth attribute as initial time, wherein the first attribute is used for describing whether a Transmission Control Protocol (TCP) connection is established or not, the second attribute is used for describing whether a preposed instruction is completed or not, the third attribute is used for describing whether a target connection is available or not, and the fourth attribute is used for describing the time of receiving a user control message at last;
after the TCP connection is successfully established with the server, modifying the value of the first attribute into a second target value;
after a plurality of prepositive instructions are successfully interacted with the server, values of the second attribute and the third attribute are modified into the second target value, and the value of the fourth attribute is updated to the current time, wherein the prepositive instructions comprise a handshake instruction, a connection instruction and a stream creation instruction;
wherein the detecting the state of the target connection comprises:
attempting to read a user control message sent by the server;
when a user control message sent by the server is read, updating the value of the fourth attribute to the current time, and determining that the state of the target connection is an available state;
and when the user control message sent by the server is not read, determining the state of the target connection according to the time interval between the current time and the value of the fourth attribute.
2. The method of claim 1, wherein the determining the state of the target connection according to a time interval between a current time and a value of the fourth attribute comprises:
when the time interval between the current time and the value of the fourth attribute is greater than a preset time interval, determining that the state of the target connection is an unavailable state, wherein the preset time interval is greater than the time interval of the server for sending the user control message;
and when the time interval between the current time and the value of the fourth attribute is smaller than the preset time interval, after sleeping for a first preset time, determining the state of the target connection by executing the step of trying to read the user control message sent by the server, wherein the time interval corresponding to the first preset time is smaller than the time interval of sending the user control message by the server.
3. The method of claim 2, wherein after detecting the status of the target connection, the method further comprises:
and when the target connection state is an available state, continuing to execute the step of trying to read the user control message sent by the server after sleeping for a first preset time.
4. The method of claim 1, wherein the re-establishing the target connection when the status of the target connection is unavailable comprises:
and when the target connection state is an unavailable state, after sleeping for a second preset time, closing the TCP connection, deleting the pre-established connection object, setting the pointer variable of the pre-established connection object to be null, and re-executing the step of pre-establishing the target connection.
5. The method of claim 1, wherein when receiving a media stream acquisition instruction for any live channel, acquiring a media stream of the live channel from the server based on the target connection comprises:
when a media stream acquisition instruction of any live channel is received, acquiring a stream address and a stream name of the live channel;
and when the pointer variable of the pre-established connection object is not null and the value of the third attribute is the second target value, sending a play instruction to the server based on the target connection, and receiving the media stream sent by the server, wherein the play instruction carries the stream name and the stream identifier, and the stream identifier is obtained from a response result of the stream creation instruction.
6. The method of claim 5, wherein after obtaining the stream address and the stream name of the live channel, the method further comprises:
when the pointer variable of the pre-established connection object is empty, acquiring a media stream from the server based on the stream address; or the like, or, alternatively,
and when the pointer variable of the pre-established connection object is not null and the value of the third attribute is the first target value, acquiring the media stream from the server based on the stream address.
7. An apparatus for acquiring a media stream, the apparatus comprising:
the system comprises an establishing module, a receiving module and a processing module, wherein the establishing module is used for establishing target connection in advance when a live application is started, the target connection is used for acquiring media streams from a server, and the live application is used for providing a plurality of live channels;
the detection module is used for detecting the state of the target connection;
the establishing module is further configured to reestablish the target connection when the state of the target connection is an unavailable state;
the acquisition module is used for acquiring the media stream of any live channel from the server based on the target connection when receiving a media stream acquisition instruction of the live channel;
the apparatus is further configured to: initializing a pointer variable of a pre-built connection object to be null;
the establishing module is used for:
when a pointer variable of a pre-established connection object is empty, allocating the pre-established connection object for the pointer variable of the pre-established connection object, initializing values of a first attribute, a second attribute and a third attribute of the pre-established connection object as a first target value, initializing a value of a fourth attribute as initial time, wherein the first attribute is used for describing whether a Transmission Control Protocol (TCP) connection is established or not, the second attribute is used for describing whether a preposed instruction is completed or not, the third attribute is used for describing whether a target connection is available or not, and the fourth attribute is used for describing the time of receiving a user control message at last;
after the TCP connection is successfully established with the server, modifying the value of the first attribute into a second target value;
after a plurality of prepositive instructions are successfully interacted with the server, values of the second attribute and the third attribute are modified into the second target value, and the value of the fourth attribute is updated to the current time, wherein the prepositive instructions comprise a handshake instruction, a connection instruction and a stream creation instruction;
the detection module is used for:
attempting to read a user control message sent by the server;
when a user control message sent by the server is read, updating the value of the fourth attribute to the current time, and determining that the state of the target connection is an available state;
and when the user control message sent by the server is not read, determining the state of the target connection according to the time interval between the current time and the value of the fourth attribute.
8. The apparatus of claim 7, wherein the detection module is configured to:
when the time interval between the current time and the value of the fourth attribute is greater than a preset time interval, determining that the state of the target connection is an unavailable state, wherein the preset time interval is greater than the time interval of the server for sending the user control message;
and when the time interval between the current time and the value of the fourth attribute is smaller than the preset time interval, after sleeping for a first preset time, determining the state of the target connection by executing the step of trying to read the user control message sent by the server, wherein the time interval corresponding to the first preset time is smaller than the time interval of sending the user control message by the server.
9. The apparatus according to claim 8, wherein the detection module is further configured to continue to perform the step of attempting to read the user control packet sent by the server after sleeping for a first preset duration when the status of the target connection is an available status.
10. The apparatus according to claim 7, wherein the establishing module is configured to, when the target connection status is an unavailable status, sleep for a second preset duration, close the TCP connection, delete the pre-established connection object, set the pointer variable of the pre-established connection object to be null, and re-execute the step of pre-establishing the target connection.
11. The apparatus of claim 7, wherein the obtaining module is configured to:
when a media stream acquisition instruction of any live channel is received, acquiring a stream address and a stream name of the live channel;
and when the pointer variable of the pre-established connection object is not null and the value of the third attribute is the second target value, sending a play instruction to the server based on the target connection, and receiving the media stream sent by the server, wherein the play instruction carries the stream name and the stream identifier, and the stream identifier is obtained from a response result of the stream creation instruction.
12. The apparatus according to claim 11, wherein the obtaining module is further configured to obtain a media stream from the server based on the stream address when the pre-established connection object pointer variable is null; or the like, or, alternatively,
the obtaining module is further configured to obtain a media stream from the server based on the stream address when the pointer variable of the pre-established connection object is not null and the value of the third attribute is the first target value.
13. A terminal comprising a processor and a memory; the memory is used for storing a computer program; the processor, configured to execute the computer program stored in the memory, implements the method steps of any of claims 1-6.
14. A computer-readable storage medium, characterized in that a computer program is stored in the computer-readable storage medium, which computer program, when being executed by a processor, carries out the method steps of any one of claims 1-6.
CN201811157395.0A 2018-09-30 2018-09-30 Media stream acquisition method and device Active CN109246123B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811157395.0A CN109246123B (en) 2018-09-30 2018-09-30 Media stream acquisition method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201811157395.0A CN109246123B (en) 2018-09-30 2018-09-30 Media stream acquisition method and device

Publications (2)

Publication Number Publication Date
CN109246123A CN109246123A (en) 2019-01-18
CN109246123B true CN109246123B (en) 2021-10-22

Family

ID=65054958

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811157395.0A Active CN109246123B (en) 2018-09-30 2018-09-30 Media stream acquisition method and device

Country Status (1)

Country Link
CN (1) CN109246123B (en)

Families Citing this family (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111294355B (en) * 2020-02-10 2021-12-17 浙江大华技术股份有限公司 Sub-connection creating method, client device and server device
CN114006935B (en) * 2020-07-14 2023-11-21 成都鼎桥通信技术有限公司 Private network terminal network access method, device and equipment
CN112367367A (en) * 2020-10-27 2021-02-12 西安万像电子科技有限公司 Image management method, device and system
CN112770124B (en) * 2020-12-22 2023-10-31 Oppo广东移动通信有限公司 Method and device for entering live broadcast room, storage medium and electronic equipment
CN113038158B (en) * 2021-03-09 2022-11-22 北京高途云集教育科技有限公司 Object display method and device based on live broadcast, electronic equipment and medium
CN113824915B (en) * 2021-08-10 2024-04-05 深圳Tcl新技术有限公司 Video picture acquisition method, apparatus and computer readable storage medium
CN114002488B (en) * 2021-09-29 2024-01-16 苏州浪潮智能科技有限公司 Automatic monitoring and adjusting method, device and system
CN114339296A (en) * 2022-03-02 2022-04-12 阿里巴巴(中国)有限公司 Method and device for transmitting media stream and media system
CN114844870B (en) * 2022-03-25 2024-03-26 阿里巴巴(中国)有限公司 Media stream acquisition method and device, electronic equipment and storage medium

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101741743A (en) * 2009-12-11 2010-06-16 东南大学 Network address sort-based bidirectional stream combining method
CN102270207A (en) * 2010-06-02 2011-12-07 中国科学院计算技术研究所 Online multimedia information mining oriented data caching method and system
CN103152134A (en) * 2013-02-26 2013-06-12 汉柏科技有限公司 Real time protocol (RTP)-based method and system for rearranging voice packets at receiving end

Family Cites Families (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102523531A (en) * 2011-12-08 2012-06-27 深圳市同洲视讯传媒有限公司 Access entity which processes session in video on demand system and method thereof
CN103685241A (en) * 2013-11-26 2014-03-26 中国科学院计算技术研究所 Adaptive heartbeat method and adaptive heartbeat system for maintaining long connection of TCP (transmission control protocol)
CN104184944B (en) * 2014-08-15 2016-03-16 小米科技有限责任公司 Obtain method and the device of multimedia data stream
US20160323352A1 (en) * 2015-04-28 2016-11-03 Fortinet, Inc. Web proxy
CN104935958B (en) * 2015-06-24 2018-03-30 青岛科技大学 A kind of real-time video transmission device
US10387676B2 (en) * 2015-09-14 2019-08-20 Viasat, Inc. Machine-driven crowd-disambiguation of data resources
CN107396431A (en) * 2017-06-19 2017-11-24 努比亚技术有限公司 Connect keeping method, connection keeps equipment and computer-readable recording medium
CN107820100B (en) * 2017-10-30 2020-08-28 北京四达时代软件技术股份有限公司 Internet audio and video playing method and device

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101741743A (en) * 2009-12-11 2010-06-16 东南大学 Network address sort-based bidirectional stream combining method
CN102270207A (en) * 2010-06-02 2011-12-07 中国科学院计算技术研究所 Online multimedia information mining oriented data caching method and system
CN103152134A (en) * 2013-02-26 2013-06-12 汉柏科技有限公司 Real time protocol (RTP)-based method and system for rearranging voice packets at receiving end

Also Published As

Publication number Publication date
CN109246123A (en) 2019-01-18

Similar Documents

Publication Publication Date Title
CN109246123B (en) Media stream acquisition method and device
CN110971930B (en) Live virtual image broadcasting method, device, terminal and storage medium
CN110674022B (en) Behavior data acquisition method and device and storage medium
CN111147878B (en) Stream pushing method and device in live broadcast and computer storage medium
CN110278464B (en) Method and device for displaying list
WO2019128592A1 (en) Method and apparatus for live broadcasting
CN108093307B (en) Method and system for acquiring playing file
CN110149332B (en) Live broadcast method, device, equipment and storage medium
CN108881286B (en) Multimedia playing control method, terminal, sound box equipment and system
CN108762881B (en) Interface drawing method and device, terminal and storage medium
CN110740340B (en) Video live broadcast method and device and storage medium
CN111327694B (en) File uploading method and device, storage medium and electronic equipment
CN109194972B (en) Live stream acquisition method and device, computer equipment and storage medium
CN110418152B (en) Method and device for carrying out live broadcast prompt
CN107896337B (en) Information popularization method and device and storage medium
CN111510482B (en) Method and device for determining failed network request and computer storage medium
CN110234036B (en) Method, device and system for playing multimedia file
CN109783176B (en) Page switching method and device
CN113613028A (en) Live broadcast data processing method, device, terminal, server and storage medium
CN112181915A (en) Method, device, terminal and storage medium for executing service
CN114785766A (en) Control method of intelligent equipment, terminal and server
CN111064657B (en) Method, device and system for grouping concerned accounts
CN111464829B (en) Method, device and equipment for switching media data and storage medium
CN109819308B (en) Virtual resource acquisition method, device, terminal, server and storage medium
CN110851435B (en) Data storage method and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant