Disclosure of Invention
Technical problem to be solved by the invention
However, there are still some problems in the method of adjusting the buffer space size to solve the zero window problem. In a playing terminal used as an embedded device with limited resources, a http/https long connection mode is generally used for data transmission when network audio or video and the like are played. Because a network has a certain instability (i.e., network jitter), in a poor network environment, a situation that the originally adjusted cache space cannot meet the requirement of the player for processing data at the later stage, and cannot request more data to fill through the network in time may occur, which may cause a pause phenomenon in playing of network audio or video, and may not ensure smooth playing under the condition of network jitter.
The present invention has been made to solve the above-mentioned problems, and an object of the present invention is to provide a data transmission method and apparatus for a broadcast terminal, and a storage medium, which can prevent the occurrence of a zero window problem and ensure smooth broadcast under network jitter.
Technical scheme for solving technical problem
The invention provides a data transmission method of a playing terminal, wherein the playing terminal acquires data from a server through a network, and the method comprises the following steps: a data temporary storage area establishing step of establishing a data temporary storage area; a data buffer area establishing step of establishing a data buffer area with a storage space larger than the data temporary storage area; a data download thread creating step of creating a data download thread; a download request step of sending a download request including a data download start point and a data download length to the server, receiving and storing data requested to be downloaded from the server by using a data temporary storage area; a data unloading step of sending the stored data in the data temporary storage area to the data buffer area and emptying the stored data in the data temporary storage area; a data sending step of sending the data in the data buffer area to a player of the playing terminal for playing; and updating the data downloading starting point of the downloading request, and jumping to the downloading request step after the updating step so as to carry out the next downloading request.
Preferably, in the data transmission method of the above-mentioned playback terminal, the data buffer is a ring storage area.
Preferably, in the data transmission method of the playing terminal, the storage space of the data temporary storage area is set so that the amount of data requested to be downloaded each time in the data download thread matches the processing speed of the player.
Preferably, in the data transmission method of the broadcast terminal, the data download length is updated at the same time as the data download start point is updated in the updating step.
Preferably, in the data transmission method of the broadcast terminal, when the storage data in the data temporary storage area is transmitted to the data buffer, it is determined whether or not the remaining space of the data buffer is equal to or larger than the size of the storage data, and when the remaining space of the data buffer is smaller than the size of the storage data, the next determination is performed after waiting for a predetermined time.
Preferably, in the data transmission method of the playback terminal, when it is determined that a download error occurs or the end of the file is reached, the data download thread of this time is exited.
Preferably, in the data transmission method of the broadcasting terminal, when there is an error in downloading data from the server or an error in the data download thread itself, it is determined that there is a download error.
Preferably, in the data transmission method of the broadcasting terminal, the broadcasting terminal is an audio broadcasting device or a video broadcasting device.
The present invention also provides a data transmission device of a broadcast terminal, wherein the broadcast terminal acquires data from a server via a network, and the data transmission device comprises: the data temporary storage area establishing module is used for establishing a data temporary storage area; the data buffer area establishing module is used for establishing a data buffer area with a storage space larger than the data temporary storage area; the data downloading thread creating module is used for creating a data downloading thread; the request downloading module is used for sending a downloading request containing a data downloading starting point and a data downloading length to the server, receiving and storing the data requested to be downloaded from the server by using the data temporary storage area; the data unloading module is used for sending the stored data in the data temporary storage area to the data buffer area and emptying the stored data in the data temporary storage area; the data sending module is used for sending the data in the data buffer area to a player of the playing terminal for playing; and the updating module is used for updating the data downloading starting point of the downloading request, and after the data downloading starting point of the downloading request is updated by the updating module, the next downloading request is carried out by the downloading request module.
The present invention also provides a playback terminal that acquires data from a server via a network, the playback terminal comprising: a processor; and the memory is stored with instructions, and when the instructions are operated by the processor, the data transmission method of the playing terminal is executed.
The present invention also provides a storage medium, in which instructions are stored, and when the storage medium runs on a computer, the storage medium causes the computer to execute the data transmission method of the above-mentioned playing terminal.
Technical effects
According to the data transmission method and device of the playing terminal, the playing terminal and the storage medium, the data temporary storage area and the data buffer area with the storage space larger than that of the data temporary storage area are arranged, the data temporary storage area is used for requesting to download and store data from the server in a multi-time slicing mode, and the data buffer area with the larger storage space is used for providing enough data to meet the requirement of a player of the playing terminal on the data, so that the problem of zero window can be prevented, and meanwhile smooth playing under the condition of network jitter can be guaranteed.
Detailed Description
The present invention now will be described more fully hereinafter with reference to the accompanying drawings, in which preferred embodiments of the invention are shown. This invention may, however, be embodied in different forms and should not be construed as limited to the embodiments set forth herein. Unless otherwise defined, terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention belongs. Terms are to be understood as having a meaning that is consistent with their meaning in the context of the relevant art and will not be interpreted in an idealized or overly formal sense unless expressly so defined herein.
The invention is applied to the playing terminal, and the playing terminal can be an intelligent sound box, an intelligent watch, an intelligent mobile phone, a tablet computer, a notebook computer, a desktop computer and the like, but is not limited to the above, and the playing terminal can be an audio playing device or a video playing device capable of playing audio or video. The playback terminal acquires data from the server via the network. The server may be an independent physical server, a server cluster or a distributed system formed by a plurality of physical servers, or a cloud server providing basic cloud computing services such as cloud service, a cloud database, cloud computing, a cloud function, cloud storage, network service, cloud communication, middleware service, domain name service, security service, CDN, and a big data and artificial intelligence platform.
< data transmission method of Player terminal >
Hereinafter, a data transmission method of a broadcast terminal according to an embodiment of the present invention will be specifically described with reference to fig. 1. A flow chart of the data transmission method is shown in fig. 1.
As shown in fig. 1, the data transmission method of the cast terminal includes the following steps.
Step S1, a data temporary storage area is established.
The data temporary storage area is used for requesting downloading data from the server in a multi-time slicing mode and storing the data. Specifically, the data temporary storage area may obtain data from the server by means of http/https, for example. The data temporary storage area adopts a smaller storage space, and the value of the data temporary storage area is set to be N. In the present embodiment, the data temporary storage area is set to a data storage space of about 30 to 80K. However, the present invention is not limited to this, and N may be set flexibly as needed as long as the amount of data to be downloaded per request in the data download thread described later matches the processing speed of the player of the playback terminal, and the http/https congestion does not occur. The data in the data temporary storage area is transferred to a data buffer area described later.
At step S2, a data buffer having a storage space larger than the data temporary storage area is created.
The data buffer area receives the data transmitted by the data temporary storage area and is used as a data source for a player of the playing terminal to play. The data buffer area adopts a larger storage space. When the value is M, M > N is satisfied. In the present embodiment, the data buffer is set to be a ring-shaped storage area of about 200 to 400K, but the present invention is not limited thereto, and M may be set to satisfy the requirement for data processing at the back stage of the player, and may be flexibly set as needed.
In step S3, a data download thread is created.
In this step, for example, libcurl (cross-platform open source network protocol library) may be used to establish a connection with the server.
Step S4, sending a download request including a data download start point and a data download length to the server, receiving and storing the data requested to be downloaded from the server using the data temporary storage area.
In this step, the starting point of data downloading is the starting position of each request for downloading, and is initially set as the file header of the file to be downloaded. The data download length can be flexibly set as needed as long as it does not exceed the size N of the data temporary storage area established in step S1. In the present embodiment, the data is obtained in pieces by directly using the size N of the data temporary storage area as the data download length.
Step S5, the storage data in the data temporary storage area is sent to the data buffer area, and the storage data in the data temporary storage area is emptied.
In this step, the stored data in the data temporary storage area can be stored in a data buffer area, which is, for example, a ring storage area, in units of bytes by a callback function.
Step S6, the data in the data buffer is sent to the player of the playing terminal for playing.
The data buffer has a large storage space, so that there is enough data to support the data requirement of the player of the playing terminal in a poor network environment. The player of the playing terminal performs post-processing such as decapsulation and decoding on the transmitted data to play audio or video.
In step S7, the data download start point of the download request is updated.
Specifically, the updated data download start point can be obtained based on the previous data download start point and the data download length.
After step S7, the process jumps to step S4 to perform the next download request, thereby realizing the loop processing of data transmission. Each requested connection (e.g., an http/https connection) is a complete process. In the data acquisition process, because the request space of the data is small, the long-time blocking waiting of http/https can not be caused. When the data is needed next time, the http/https connection request is made again.
Fig. 2 is a schematic diagram illustrating a data flow in the data transmission method of the play terminal shown in fig. 1. As shown in fig. 2, data acquired from the server in a multi-time slicing manner is stored in a data temporary storage area with a small storage space each time, the stored data in the data temporary storage area is forwarded to a data buffer with a large storage space, and the data in the data buffer is sent to a player of the playing terminal for playing.
In the data transmission method of the playing terminal, the data temporary storage area is utilized to request to download data from the server in a multi-time slicing mode, each data request action is an independent process, and the data acquisition operation of the current slice can be directly finished without waiting for the part of the requested data to be stored in the data buffer area. Therefore, the data is effectively prevented from being sent by the server, and the receiving end is blocked due to insufficient storage space, so that the zero window problem is effectively avoided.
In addition, the direct data source of the player of the playing terminal is a data buffer area with a larger storage space, and the area has enough data to support the requirement of the player of the playing terminal on the data in a poorer network environment, so that the playing jam caused by network jitter is effectively avoided, and smooth playing under the condition of network jitter is ensured.
According to the data transmission method of the playing terminal in the embodiment, the data temporary storage area and the data buffer area with the storage space larger than that of the data temporary storage area are set, the data temporary storage area is used for requesting to download and store data from the server in a multi-time slicing mode, and the data buffer area with the larger storage space is used for providing enough data to meet the requirement of a player of the playing terminal on the data, so that the smooth playing under the condition of network jitter can be ensured while the zero window problem is prevented.
< modification example >
Fig. 1 shows an example of a data transfer method of a broadcast terminal according to an embodiment of the present invention, but in a modification of the present invention, an end judgment condition may be set for a loop process of data transfer. For example, the data download thread is exited when it is determined that a download error has occurred or the end of the file has been reached. Specifically, when there is an error in downloading data from the server or when there is an error in the data download thread itself, it may be determined that there is a download error.
Further, when the data stored in the data temporary storage area is transmitted to the data buffer, it may be determined whether or not the remaining space of the data buffer is equal to or larger than the size of the stored data, and when the remaining space of the data buffer is smaller than the size of the stored data, the next determination may be performed after waiting for a predetermined time.
Fig. 3 is a flowchart illustrating a data transmission method according to a modification. As shown in fig. 3, steps S1, S2, S3, S6, and S7 are the same as steps S1, S2, S3, S6, and S7 in fig. 1, steps S41 to S42 correspond to step S4 in fig. 1, and steps S51 to S53 correspond to step S5 in fig. 1.
After step S42, it is determined whether or not the remaining space U of the data buffer is equal to or larger than the size of the stored data in step S51. If yes in step S51, the flow proceeds to step S52, where the data is stored in the data buffer. If no in step S51, the routine proceeds to step S53, where the routine waits for a predetermined time and then proceeds to step S51 to make the next determination. The predetermined time can be flexibly set as needed, and is set to about 100ms in the present embodiment.
After step S52, it is determined whether or not a download error occurred (step S81) and whether or not the end of the file was reached (step S82). And when the downloading is judged to be wrong or the end of the file is reached, exiting the data downloading thread and ending the processing. Otherwise, the process proceeds to step S7, the data download starting point of the download request is updated, and the process jumps to step S41 to proceed to the next download request.
In addition, the data transmission method of the present invention may also be modified in other ways, for example, the data download length may be updated at the same time of updating the data download starting point in step S7.
< data transmission device of Player terminal >
Hereinafter, the data transfer device 1 of the broadcast terminal according to the embodiment of the present invention will be specifically described with reference to fig. 4. Fig. 4 shows a block diagram of the data transmission device 1.
The data transmission device 1 includes a data temporary storagearea establishing module 10, a data bufferarea establishing module 20, a data downloadingthread establishing module 30, arequest downloading module 40, adata unloading module 50, adata sending module 60 and an updatingmodule 70.
The data temporary storagearea establishing module 10 is used for establishing a data temporary storage area.
The data bufferarea establishing module 20 is used for establishing a data buffer area with a storage space larger than the data temporary storage area.
The data downloadthread creating module 30 is used for creating a data download thread.
Thedownload request module 40 is configured to send a download request including a data download start point and a data download length to the server, and receive and store data requested to be downloaded from the server by using the data temporary storage area.
Thedata unloading module 50 is configured to send the storage data in the data temporary storage area to the data buffer, and empty the storage data in the data temporary storage area.
Thedata sending module 60 is used for sending the data in the data buffer to a player of the playing terminal for playing.
The updatingmodule 70 is used for updating the data download starting point of the download request.
After the data download start point of the download request is updated by the updatingmodule 70, the next download request is made by thedownload request module 40.
It should be noted that the embodiment of the data transmission device in the present invention corresponds to the embodiment of the data transmission method, and specific principles in the embodiment of the data transmission device can be referred to in the contents of the embodiment of the data transmission method, and will not be described again here.
Another embodiment of the present invention further provides a broadcasting terminal, which obtains data from a server via a network, and comprises a processor and a memory. The playing terminal may be a smart speaker, a smart watch, a smart phone, a tablet computer, a notebook computer, a desktop computer, or the like, but is not limited thereto, and may be an audio playing device or a video playing device capable of playing audio or video.
The processor may be implemented in at least one hardware form of Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), and Programmable Logic Array (PLA).
The Memory may be a Read-Only Memory (ROM), a Random Access Memory (RAM), or the like. The memory stores instructions, and the instructions are executed by the processor to execute the data transmission method of the play terminal according to the embodiment of the invention.
Another embodiment of the present invention also provides a computer-readable storage medium, which stores instructions that, when executed on a computer, cause the computer to execute the data transmission method of the cast terminal according to the embodiment of the present invention.
Another embodiment of the present invention further provides a computer program product containing instructions, which when run on a computer, causes the computer to execute the data transmission method of the cast terminal according to the embodiment of the present invention.
It should be noted that, for the sake of simplicity, the embodiments of the data transmission method of the foregoing broadcast terminal are all described as a series of action combinations, but those skilled in the art should understand that the present invention is not limited by the described action sequence. Some steps may be performed in other sequences or simultaneously according to the present invention. Further, those skilled in the art should also appreciate that the embodiments described in the specification are preferred embodiments and that the acts and modules referred to are not necessarily required by the invention.
Those skilled in the art will understand that all or part of the steps in the above-described data transmission method of the broadcasting terminal may be implemented by hardware associated with program instructions, and the program may be stored in a computer-readable storage medium, and the storage medium may include: flash disks, Read-Only memories (ROMs), Random Access Memories (RAMs), EPROMs, EEPROMs, magnetic or optical disks, etc.
The present invention has been described in detail, but the above embodiments are merely examples of all embodiments, and the present invention is not limited thereto. The present invention may freely combine the respective embodiments, may modify any of the components of the respective embodiments, or may omit any of the components of the respective embodiments within the scope of the present invention.