A method, system, device and storage medium for playing HLS streaming media

By arranging the M3U8 index file in HLS streaming media, the main thread parses the M3U8 index file and creates a new child thread concurrently opens the URL address of the TS shard, which solves the problem of slow start-up speed and excessive resource usage, and realizes a fast start-up and efficient network Bandwidth utilization.

CN115883936BActive Publication Date: 2025-01-07HUNAN GOKE MICROELECTRONICS CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211550605.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-12-05
Publication Date
2025-01-07
Estimated Expiration
2042-12-05

AI Technical Summary

Technical Problem

The existing HLS streaming media playback technology is slow to play when parsing M3U8 index files and downloading TS shards, resulting in wasted network bandwidth and stuttering playback, and taking up too much system resources.

Method used

When parsing the M3U8 index file through the main thread, create a corresponding number of child threads to concurrently open the URL address of the TS shard, and after the first TS shard is opened, the playback data is downloaded in sequence through the download thread to limit the concurrency of the child threads To avoid excessive resource use.

Benefits of technology

It improves the starting speed of streaming media, avoids network bandwidth waste and playback lag, optimizes the use of system resources, and is suitable for various scenarios such as live broadcast, on-demand and back viewing of HLS streaming media.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115883936B_ABST
    Figure CN115883936B_ABST
Patent Text Reader

Abstract

The present application discloses a method, system, device and storage medium for playing HLS streaming media, and relates to the technical field of streaming media playing. The URL addresses of all TS segments of the HLS streaming media to be played are obtained by parsing the M3U8 index file through the main thread. In the process of parsing the M3U8 index file through the main thread, a sub-thread not exceeding the preset number of newly created sub-threads is created to concurrently open the URL address obtained by parsing, and the URL address corresponding to the first TS segment is opened. The download thread downloads the playback data corresponding to each TS segment from each opened URL address in sequence. The present application can improve the start-up speed and effectively avoid the waste of network bandwidth, playback jams and excessive occupation of system resources.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of streaming media playback, and in particular to a method, system, device and storage medium for playing HLS streaming media. Background Art

[0002] With the rapid development of mobile Internet streaming media playback technology, streaming media playback technology based on the HLS protocol is increasingly widely used in mobile Internet. HLS (HTTP Live Streaming, an adaptive bitrate streaming media transmission protocol based on HTTP) is a streaming media transmission protocol based on HTTP (HyperText Transfer Protocol, Hypertext Transfer Protocol), which can realize live, on-demand and playback services of streaming media. The basic principle of the HLS protocol is: the server cuts the audio and video streams into TS segments and creates an M3U8 index file; the client first downloads and parses the M3U8 index file to obtain the index address of each TS segment of the audio and video stream to be played, and then downloads and plays the corresponding TS segments in sequence according to the index addresses of each TS segment obtained by parsing, forming streaming media playback.

[0003] However, in the existing HLS streaming media playback technology, when the client parses the M3U8 index file and opens and downloads the TS fragments, it usually first parses all the index addresses of the TS fragments of the M3U8 index file, and then uses a single thread to open and download each TS fragment in sequence according to the TS fragment sequence number. When the M3U8 index file is large, the process of parsing the M3U8 index file takes a long time, and waiting for the parsing to be completed and then downloading is a waste of time, resulting in a long time and slow start-up speed during streaming media playback. In addition, only the main thread opens and downloads each TS fragment in sequence, which will cause a waste of network bandwidth and easily cause playback jams.

[0004] Therefore, when playing streaming media, how to increase the start speed and effectively avoid wasting network bandwidth, playing stuck and excessive occupation of system resources is a technical problem that needs to be solved urgently by those skilled in the art. Summary of the invention

[0005] To solve the above technical problems, the present application provides a method for playing HLS streaming media, which can improve the start-up speed and effectively avoid network bandwidth waste, playback freezes and excessive occupation of system resources. The present application also provides a system, device and storage medium for playing HLS streaming media, which have the same technical effects.

[0006] The first objective of the present application is to provide a method for playing HLS streaming media.

[0007] The above-mentioned application objective 1 of the present application is achieved through the following technical solutions:

[0008] A method for playing HLS streaming media, comprising:

[0009] Get the M3U8 index file of the HLS streaming media to be played;

[0010] Parse the M3U8 index file through the main thread to obtain the URL addresses of all TS segments of the HLS streaming media to be played;

[0011] In the process of parsing the M3U8 index file by the main thread, a corresponding number of sub-threads are newly created according to the number of URL addresses of the TS fragments obtained by the parsing, and the URL addresses corresponding to the respective TS fragments obtained by the parsing are opened by the sub-threads, wherein:

[0012] The number of newly created child threads is less than or equal to a preset number n of newly created child threads, where n is a positive integer, and the preset number n of newly created child threads is less than the number of TS fragments of the HLS streaming media to be played;

[0013] When the URL address corresponding to the first TS segment is opened, the download thread sequentially downloads the playback data corresponding to each TS segment from each opened URL address.

[0014] Preferably, the method further comprises:

[0015] When the M3U8 index file is parsed, the main thread sequentially searches for URL addresses corresponding to the TS segments to see whether they have been opened; and

[0016] The main thread performs a URL address opening operation on the URL address corresponding to the TS segment that has not yet been opened according to the search result.

[0017] Preferably, the creating a corresponding number of sub-threads according to the number of URL addresses of the parsed TS fragments, and opening the URL addresses corresponding to the parsed TS fragments through the sub-threads includes:

[0018] Each time the main thread parses out a URL address of the TS segment, a new sub-thread is created for opening the URL address of the TS segment, and the operation of opening the URL address of the TS segment is performed through the newly created sub-thread.

[0019] Preferably, the method further comprises:

[0020] In the process of sequentially searching the URL addresses corresponding to the TS segments by the main thread to see whether they have been opened, when one of the following preset stop search conditions occurs, the search is stopped:

[0021] Stop retrieval condition 1: The URL address of the nth TS segment has been retrieved, and the URL address of the TS segment has been opened;

[0022] Stop retrieval condition 2: The URL address of the i-th TS segment is retrieved, and the URL address of the i-th TS segment has not been opened yet, where i is a positive integer greater than 1, and i≤n.

[0023] Preferably, performing the URL address opening operation on the URL address corresponding to the TS segment that has not yet been opened according to the search result by the main thread includes:

[0024] When the URL address of the nth TS segment is retrieved and the URL address of the TS segment has been opened, the main thread starts to perform the URL address opening operation from the URL address corresponding to the n+1th TS segment; or,

[0025] When the URL address of the i-th TS segment is retrieved, and the URL address of the i-th TS segment has not been opened, the main thread starts to perform the URL address opening operation from the URL address corresponding to the i-th TS segment.

[0026] Preferably, after obtaining the M3U8 index file of the HLS streaming media to be played, the method further comprises:

[0027] The size of the M3U8 index file is compared with a preset file size threshold. When the size of the M3U8 index file is greater than the preset file size threshold, the step of creating a corresponding number of child threads according to the number of URL addresses of the parsed TS fragments during the process of the main thread parsing the M3U8 index file, and opening the URL addresses corresponding to the parsed TS fragments through the child threads is executed.

[0028] Preferably, the preset number n of newly created sub-threads is determined according to device performance and network bandwidth, wherein:

[0029] The device performance includes the number of concurrent connection requests supported by the server, and the CPU performance and memory size of the client;

[0030] The network bandwidth refers to the bandwidth of the communication network between the server and the client.

[0031] The second objective of the present application is to provide a system for playing HLS streaming media.

[0032] The second application objective of the present application is achieved through the following technical solutions:

[0033] A HLS streaming media playback system, comprising:

[0034] An index file acquisition module is used to obtain the M3U8 index file of the HLS streaming media to be played;

[0035] An index file parsing module, used for parsing the M3U8 index file through a main thread to obtain URL addresses of all TS segments of the HLS streaming media to be played;

[0036] The first URL address opening module is used to create a corresponding number of sub-threads according to the number of URL addresses of the TS fragments obtained by the parsing during the main thread parsing the M3U8 index file, and open the URL addresses corresponding to the parsed TS fragments through the sub-threads, wherein:

[0037] The number of newly created child threads is less than or equal to a preset number n of newly created child threads, where n is a positive integer, and the preset number n of newly created child threads is less than the number of TS fragments of the HLS streaming media to be played;

[0038] The playback data downloading module is used to download the playback data corresponding to each TS segment from each opened URL address in sequence through a download thread when the URL address corresponding to the first TS segment is opened.

[0039] Preferably, the system further comprises:

[0040] A URL address retrieval module is used to retrieve in sequence through the main thread whether the URL addresses corresponding to the various TS segments have been opened when the M3U8 index file has been parsed;

[0041] The second URL address opening module performs a URL address opening operation on the URL address corresponding to the TS segment that has not yet been opened according to the search result through the main thread.

[0042] Preferably, the first URL address opening module is specifically used to create a corresponding number of child threads according to the number of URL addresses of the parsed TS fragments, and open the URL addresses corresponding to the parsed TS fragments through the child threads:

[0043] Each time the main thread parses out a URL address of the TS segment, a new sub-thread is created for opening the URL address of the TS segment, and the operation of opening the URL address of the TS segment is performed through the newly created sub-thread.

[0044] Preferably, the system further comprises a retrieval control module, which is used to:

[0045] In the process of sequentially searching the URL addresses corresponding to the TS segments by the main thread to see whether they have been opened, when one of the following preset stop search conditions occurs, the search is stopped:

[0046] Stop retrieval condition 1: The URL address of the nth TS segment has been retrieved, and the URL address of the TS segment has been opened;

[0047] Stop retrieval condition 2: The URL address of the i-th TS segment is retrieved, and the URL address of the i-th TS segment has not been opened yet, where i is a positive integer greater than 1, and i≤n.

[0048] Preferably, the second URL address opening module is specifically used for:

[0049] When the URL address of the nth TS segment is retrieved and the URL address of the TS segment has been opened, the main thread starts to perform the URL address opening operation from the URL address corresponding to the n+1th TS segment; or,

[0050] When the URL address of the i-th TS segment is retrieved, and the URL address of the i-th TS segment has not been opened, the main thread starts to perform the URL address opening operation from the URL address corresponding to the i-th TS segment.

[0051] Preferably, the system further comprises a child thread establishment control module, which is used to:

[0052] After obtaining the M3U8 index file of the HLS streaming media to be played, the size of the M3U8 index file is compared with a preset file size threshold. When the size of the M3U8 index file is greater than the preset file size threshold, the control executes the step of creating a corresponding number of child threads according to the number of URL addresses of the parsed TS fragments during the process of the main thread parsing the M3U8 index file, and opening the URL addresses corresponding to the parsed TS fragments through the child threads.

[0053] Preferably, the preset number n of newly created sub-threads is determined according to device performance and network bandwidth, wherein:

[0054] The device performance includes the number of concurrent connection requests supported by the server, and the CPU performance and memory size of the client;

[0055] The network bandwidth refers to the bandwidth of the communication network between the server and the client.

[0056] The third objective of the present application is to provide a playback device for HLS streaming media.

[0057] The third application objective of this application is achieved through the following technical solutions:

[0058] A HLS streaming media playback device comprises at least one processor and at least one memory connected to the processor via a bus.

[0059] The processor is used to call the program instructions in the memory to execute the HLS streaming media playback method as described in any one of the above-mentioned application purposes.

[0060] The fourth objective of this application is to provide a storage medium.

[0061] The fourth application objective of this application is achieved through the following technical solutions:

[0062] A storage medium stores computer executable instructions, which, when loaded and executed by a processor, implement a method for playing HLS streaming media as described in any one of the above-mentioned application purposes.

[0063] In summary, the present application discloses a method, system, device and storage medium for playing HLS streaming media. When HLS streaming media needs to be played, the M3U8 index file of the HLS streaming media to be played is first obtained; then the M3U8 index file is parsed by the main thread to obtain the URL addresses of all TS fragments of the HLS streaming media to be played; in the process of the main thread parsing the M3U8 index file, a corresponding number of child threads are newly created according to the number of URL addresses of the TS fragments obtained by the parsing, and the URL addresses corresponding to the parsed TS fragments are opened by the child threads, wherein the number of newly created child threads is less than or equal to the preset number n of newly created child threads, n is a positive integer, and the preset number n of newly created child threads is less than the number of TS fragments of the HLS streaming media to be played; when the URL address corresponding to the first TS fragment is opened, the download thread sequentially downloads the playback data corresponding to each TS fragment from each opened URL address.

[0064] In the process of parsing the M3U8 index file through the main thread, the present application creates a corresponding number of child threads to concurrently open the URL addresses corresponding to the parsed TS fragments, effectively avoiding the problem of long start-up time and slow start-up speed during streaming media playback caused by the need to wait for the parsing to be completed and then downloading in the prior art, effectively improving the start-up speed, achieving fast start-up, and effectively avoiding the waste of network bandwidth; at the same time, by pre-setting the number of newly created child threads n to limit the concurrency of child threads, it is effectively avoided that too many newly created threads occupy too many system resources, thereby reducing the impact on the scheduling efficiency of other threads of the system; in the process of opening the URL addresses corresponding to the TS fragments by the child threads, as long as the URL address corresponding to the first TS fragment is opened, the download thread executes the download operation of the playback data corresponding to the TS fragment on the opened URL address, thereby further improving the start-up speed and better avoiding playback jams.

[0065] It can be seen from this that the present application can improve the start-up speed and effectively avoid network bandwidth waste, playback jams and excessive occupation of system resources. The present application is applicable to a wide range of playback scenarios and can be applied to various playback scenarios such as live broadcast, on-demand and playback of HLS streaming media. BRIEF DESCRIPTION OF THE DRAWINGS

[0066] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0067] Figure 1 A flowchart of a method for playing HLS streaming media in an embodiment of the present application;

[0068] Figure 2 This is a structural diagram of a HLS streaming media playback system in an embodiment of the present application;

[0069] Figure 3 This is a schematic diagram of the structure of a HLS streaming media playback device in an embodiment of the present application. DETAILED DESCRIPTION

[0070] In order to enable those skilled in the art to better understand the technical solutions in this application, the technical solutions in the embodiments of this application will be clearly and completely described below. Obviously, the described embodiments are only part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0071] In the embodiments provided in the present application, it should be understood that the disclosed methods and systems can be implemented in other ways. The system embodiments described below are merely schematic. For example, the division of units and modules is only a logical function division. There may be other division methods in actual implementation, such as: multiple units or modules can be combined, or can be integrated into another system, or some features can be ignored, or not executed. In addition, the coupling, direct coupling, or communication connection between the components shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or modules, which can be electrical, mechanical or other forms.

[0072] In addition, all functional units in the embodiments of the present application may be integrated into one processor, or each unit may be a separate device, or two or more units may be integrated into one device; each functional unit in the embodiments of the present application may be implemented in the form of hardware or in the form of hardware plus software functional units.

[0073] A person skilled in the art can understand that all or part of the steps of the following method embodiments can be completed by program instructions and related hardware. The aforementioned program instructions can be stored in a computer-readable storage medium. When the program instructions are executed, the steps of the following method embodiments are executed; and the aforementioned storage medium includes: a mobile storage device, a read-only memory (ROM), a magnetic disk or an optical disk, and other media that can store program codes.

[0074] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Therefore, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the features. In the description of this application, "multiple" and "several" mean two or more, unless otherwise clearly and specifically defined.

[0075] The embodiments of the present application are written in a progressive manner.

[0076] like Figure 1 As shown, an embodiment of the present application provides a method for playing HLS streaming media, and the method may include the following steps:

[0077] S101, obtaining the M3U8 index file of the HLS streaming media to be played;

[0078] From the basic principles of the HLS protocol, we can know that HLS streaming media playback mainly includes the following steps: First, the server (such as the server) cuts the HLS streaming media into multiple TS segments and creates an M3U8 index file corresponding to the TS segments; then, the client first downloads the M3U8 index file from the server, and parses the M3U8 index file to obtain the index address (such as URL address) of each TS segment of the HLS streaming media to be played; finally, the client downloads and plays the corresponding TS segments in sequence according to the index addresses of each TS segment obtained by the analysis, thereby forming streaming media playback.

[0079] Therefore, when HLS streaming media such as audio and video needs to be played, first, the M3U8 index file corresponding to the HLS streaming media to be played needs to be obtained, so as to subsequently obtain the network address information storing the playback data of the HLS streaming media by parsing the M3U8 index file.

[0080] Specifically, in this embodiment, the operation of obtaining the M3U8 index file can be performed in the main thread of the client that needs to play the HLS streaming media. The specific acquisition process is as follows:

[0081] The main thread of the client sends a play request to the server storing the M3U8 index file, wherein the play request may be a live broadcast request, a video-on-demand request, or a playback request;

[0082] The server verifies the client's identity information and establishes an HTTP connection with the client's main thread;

[0083] The main thread of the client downloads the M3U8 index file of the HLS streaming media to be played from the server through the HTTP connection.

[0084] S102, parsing the M3U8 index file through the main thread to obtain the URL addresses of all TS segments of the HLS streaming media to be played;

[0085] After the main thread of the client downloads the M3U8 index file of the HLS streaming media to be played from the server, it performs a parsing operation of the M3U8 index file to obtain the network address information storing the playback data of the HLS streaming media.

[0086] Specifically, in this embodiment, the M3U8 index file is parsed by the main thread to obtain the URL addresses of all TS segments of the HLS streaming media to be played. All TS slices of HLS streaming media are stored in the server, and the M3U8 index file established by the server configures a corresponding URL address (i.e., the network address information of the playback data of the TS segment) for each TS segment, that is, each TS segment corresponds to a URL address, therefore, the URL addresses of all TS segments of the HLS streaming media to be played can be obtained by parsing the M3U8 index file.

[0087] S103, in the process of the main thread parsing the M3U8 index file, a corresponding number of sub-threads are newly created according to the number of URL addresses of the TS fragments obtained by the parsing, and the URL addresses corresponding to the respective TS fragments obtained by the parsing are opened by the sub-threads, wherein:

[0088] The number of newly created child threads is less than or equal to a preset number n of newly created child threads, where n is a positive integer, and the preset number n of newly created child threads is less than the number of TS fragments of the HLS streaming media to be played;

[0089] In the prior art, the URL address opening operation is usually performed after the M3U8 index file is parsed (the URL address opening operation is a pre-order step for downloading the TS segment playback data, i.e., establishing an HTTP connection between the playback data download thread and the server). When the M3U8 index file is large, the process of parsing the M3U8 index file takes a long time, so waiting for the parsing to be completed before downloading will waste time, resulting in a long time and slow start-up speed during streaming media playback.

[0090] In the present embodiment, during the process of the main thread parsing the M3U8 index file, a corresponding number of child threads are newly created according to the number of URL addresses of the TS fragments obtained by the parsing, so as to concurrently open the URL addresses corresponding to the various TS fragments obtained by the parsing by adopting multithreading. In this way, the opening operation of the URL address can be performed concurrently with the parsing operation of the M3U8 index file, without waiting for the M3U8 index file to be parsed, as long as the URL addresses corresponding to the TS fragments are parsed from the M3U8 index file, a corresponding number of child threads are newly created to concurrently open the URL addresses corresponding to the various TS fragments, that is, the opening operations of the multiple URL addresses that have been parsed are also performed concurrently.

[0091] Therefore, this step can effectively avoid the problem of long start-up time and slow start-up speed during streaming media playback caused by the need to wait for the parsing to be completed and then downloading in the prior art, effectively improve the start-up speed and achieve fast start-up. The larger the M3U8 index file, the more obvious the optimization of the start-up time.

[0092] At the same time, in this embodiment, the concurrency of sub-threads is limited by presetting the number n of newly created sub-threads, which can effectively avoid too many newly created threads occupying too many system resources while improving the startup speed, thereby reducing the impact on the scheduling efficiency of other threads in the system.

[0093] Specifically, in this embodiment, the preset number of newly created sub-threads n can be determined according to device performance and network bandwidth. The device performance can specifically include the number of concurrent connection requests supported by the server, and the CPU performance and memory size of the client; the bandwidth refers to the bandwidth of the communication network between the server and the client.

[0094] S104: When the URL address corresponding to the first TS segment is opened, the download thread sequentially downloads the playback data corresponding to each TS segment from each opened URL address.

[0095] In order to further improve the start-up speed and better avoid playback jams, after the URL address corresponding to the first TS segment is opened, the playback data corresponding to each TS segment can be downloaded from each opened URL address in sequence through a download thread. Specifically, the download thread can be created after the URL address corresponding to the first TS segment is opened, or it can be created in advance.

[0096] It should be noted that the download operation of the playback data performed by the download thread can be performed after the main thread completes the parsing operation of the M3U8 index file, or it can be performed during the parsing operation of the M3U8 index file performed by the main thread. In order to maximize the start speed, as long as the URL address corresponding to the first TS segment is opened, a new download thread can be immediately created to start the download operation of the playback data. Specifically, the download operation of the playback data is that the download thread downloads the playback data of the corresponding TS segment from the server according to the opened URL address, so as to realize online playback by performing data parsing and other processing on the downloaded playback data in the future.

[0097] In summary, in the above embodiment, in the process of parsing the M3U8 index file through the main thread, a corresponding number of sub-threads are newly created to concurrently open the URL addresses corresponding to the parsed TS fragments, which effectively avoids the problem of long start-up time and slow start-up speed during streaming media playback caused by the need to wait for the parsing to be completed and then downloading in the prior art, effectively improving the start-up speed and realizing fast start-up; at the same time, by pre-setting the number of newly created sub-threads n to limit the concurrency of sub-threads, it is effectively avoided that too many new threads occupy too many system resources, thereby reducing the impact on the scheduling efficiency of other threads of the system; in the process of opening the URL addresses corresponding to each TS fragment by the sub-thread, as long as the URL address corresponding to the first TS fragment is opened, the download thread concurrently executes the download operation of the playback data corresponding to the TS fragment on the opened URL address, thereby further improving the start-up speed and better avoiding playback jams. Therefore, this embodiment can improve the start-up speed, and effectively avoid network bandwidth waste, playback jams and excessive occupation of system resources. The HLS streaming media playback method of this embodiment is applicable to a wide range of playback scenarios, and can be applied to a variety of playback scenarios such as live broadcast, on-demand and playback of HLS streaming media.

[0098] Based on the above embodiment, the method may further include the following steps:

[0099] When the M3U8 index file has been parsed, the main thread sequentially searches for the URL addresses corresponding to the TS segments to see if they have been opened;

[0100] The main thread performs a URL address opening operation on the URL address corresponding to the TS segment that has not yet been opened according to the search result.

[0101] After the M3U8 index file is parsed, the main thread then performs the URL address opening operation. Since the preset number of newly created child threads n is less than the number of TS segments of the HLS streaming media to be played, after the M3U8 index file is parsed, at least one URL address corresponding to a part of the TS segments will not be opened. In this way, before the main thread performs the URL address opening operation, it is necessary to first sequentially search whether the URL addresses corresponding to the various TS segments have been opened by the newly created child threads, so that the main thread can determine which TS segment corresponds to the URL address to start the URL address opening operation.

[0102] After the main thread completes the search, it can determine which URL addresses corresponding to the TS segments have been opened by the newly created child threads. At this time, the operation of the newly created child thread is stopped, and the main thread performs the URL address opening operation on the URL addresses corresponding to the TS segments that have not yet been opened according to the search results (the URL addresses that have started to be opened but have not yet completed the opening operation continue to be opened by the corresponding child threads). In this way, after the main thread completes the parsing operation, the main thread is fully utilized to perform the URL address opening operation and the operation of the newly created child thread is stopped, which effectively reduces the system resource occupation caused by the newly created child thread, improves the utilization rate of the main thread, and realizes the dynamic adjustment of the balance between network bandwidth utilization and system resource occupation.

[0103] On the basis of the above embodiment, the method of creating a corresponding number of child threads according to the number of URL addresses of the parsed TS fragments, and opening the URL addresses corresponding to the parsed TS fragments through the child threads includes:

[0104] Create a new sub-thread with the same number of URL addresses of the parsed TS fragments, and open the URL addresses of the parsed TS fragments one by one through the newly created sub-threads.

[0105] In this embodiment, during the process of the main thread parsing the M3U8 index file, a number of sub-threads equal to the number of URL addresses of the parsed TS fragments are newly created, and the URL addresses of the parsed TS fragments are opened one by one and concurrently using the newly created sub-threads, that is, a sub-thread is assigned to the URL address of each TS fragment, and the URL addresses of each TS fragment are opened by different sub-threads, respectively, thereby better avoiding the occasional jamming caused by waiting for the URL address of the next TS fragment to be opened, and at the same time improving the network bandwidth utilization rate; in addition, during the process of the main thread parsing the M3U8 index file, a new sub-thread is simultaneously created to open the URL address of the first TS fragment, thereby realizing the early opening of the URL address of the first TS fragment and ensuring the rapid start of HLS streaming media.

[0106] On the basis of the above embodiment, the newly created sub-threads having the same number as the number of URL addresses of the parsed TS fragments, and the newly created sub-threads correspondingly and concurrently opening the URL addresses of the parsed TS fragments one by one include:

[0107] Each time the main thread parses out a URL address of the TS segment, a new sub-thread is created for opening the URL address of the TS segment, and the operation of opening the URL address of the TS segment is performed through the newly created sub-thread.

[0108] In this embodiment, during the process of the main thread parsing the M3U8 index file, as long as the URL address of the TS segment is parsed, a new sub-thread is immediately created to open the URL address of the TS segment, that is, when the URL address of the first TS segment is parsed, a new first sub-thread is created to open the URL address of the first TS segment; when the URL address of the second TS segment is parsed, a new second sub-thread is created to open the URL address of the second TS segment, and so on. In this way, the start speed of HLS streaming media and the utilization rate of network bandwidth can be further improved.

[0109] Based on the above embodiment, the method may further include the following steps:

[0110] In the process of sequentially searching the URL addresses corresponding to the TS segments by the main thread to see whether they have been opened, when one of the following preset stop search conditions occurs, the search is stopped:

[0111] Stop search condition 1: The URL address of the nth TS fragment has been retrieved, and the URL address of the TS fragment has begun to be opened; since the maximum number of newly created child threads is limited to n, therefore, when the main thread completes the parsing operation of the M3U8 index file and performs a search operation, the number of URL addresses of the TS fragments opened is at most n. At this time, if the URL address of the nth TS fragment has been retrieved and the URL address of the TS fragment has begun to be opened, there will be no subsequent TS fragment URL addresses with sequence numbers greater than n that will begin to be opened or have been successfully opened. Therefore, in order to avoid system resource occupation caused by the search, the search can be stopped immediately.

[0112] Stop search condition 2: The URL address of the i-th TS segment is retrieved, and the URL address of the i-th TS segment has not been opened, where i is a positive integer greater than 1, and i≤n. Although the maximum number of newly created child threads is limited to n, it takes a certain amount of time to create a new child thread to open the URL address of the TS segment. Therefore, it may happen that when the main thread completes the parsing operation of the M3U8 index file and performs a sequential search operation, the number of successfully created child threads and the number of URL addresses of the TS segments that have been opened may be less than n. Therefore, when the URL address of the i-th (1<i≤n) TS segment is retrieved, and the URL address of the i-th TS segment has not been opened, in order to avoid system resource occupation caused by the search, the search can also be stopped immediately.

[0113] Based on the above embodiment, performing the URL address opening operation on the URL address corresponding to the TS segment that has not yet been opened according to the search result by the main thread includes:

[0114] When the URL address of the nth TS segment is retrieved and the URL address of the TS segment has been opened, the main thread starts to perform the URL address opening operation from the URL address corresponding to the n+1th TS segment; or,

[0115] When the URL address of the i-th TS segment is retrieved, and the URL address of the i-th TS segment has not been opened, the main thread starts to perform the URL address opening operation from the URL address corresponding to the i-th TS segment.

[0116] This embodiment can effectively improve the utilization rate of the main thread and reduce the concurrent number of newly created sub-threads, thereby effectively avoiding excessive occupation of system resources while increasing the start-up speed.

[0117] On the basis of the above embodiment, after obtaining the M3U8 index file of the HLS streaming media to be played, the method further includes:

[0118] The size of the M3U8 index file is compared with a preset file size threshold. When the size of the M3U8 index file is greater than the preset file size threshold, the step of creating a corresponding number of child threads according to the number of URL addresses of the parsed TS fragments during the process of the main thread parsing the M3U8 index file, and opening the URL addresses corresponding to the parsed TS fragments through the child threads is executed.

[0119] Because the M3U8 index file of the HLS streaming media to be played is large, the time required to parse the M3U8 index file is long. If the M3U8 index file is parsed and then the download playback data is opened according to the URL address obtained by parsing, it may cause a reduction in the start-up speed. Therefore, the present application optimizes the playback data processing flow of the existing HLS streaming media, and the M3U8 index file of the HLS streaming media to be played, the more obvious the optimization effect of the start-up time brought by the playback method of the optimized HLS streaming media of the present application is. However, for some HLS streaming media to be played that are relatively small in the M3U8 index file itself, the playback method of the HLS streaming media in the prior art will not cause the situation that the start-up speed is too slow, so after obtaining the M3U8 index file of the HLS streaming media to be played, it can also be judged whether it is necessary to start the playback method flow of the optimized HLS streaming media corresponding to S103-S104 according to the size of the M3U8 index file, that is, after step S101 (obtaining the M3U8 index file of the HLS streaming media to be played), the method also includes the following steps:

[0120] The size of the M3U8 index file is compared with a preset file size threshold, and when the size of the M3U8 index file is greater than the preset file size threshold, step S103 is performed. It should be noted that, in the process of comparing the size of the M3U8 index file with the preset file size threshold, step S102 can be performed simultaneously, or it can be performed after the size of the M3U8 index file is greater than the preset file size threshold by comparison. Wherein, the preset file size threshold can be set according to an empirical value, for example, the preset file size threshold can be set to 10kb or 20kb.

[0121] like Figure 2 As shown, an embodiment of the present application provides a system for playing HLS streaming media, and the system may include:

[0122] The index file acquisition module 201 is used to acquire the M3U8 index file of the HLS streaming media to be played;

[0123] From the basic principles of the HLS protocol, we can know that HLS streaming media playback mainly includes the following steps: First, the server (such as the server) cuts the HLS streaming media into multiple TS segments and creates an M3U8 index file corresponding to the TS segments; then, the client first downloads the M3U8 index file from the server, and parses the M3U8 index file to obtain the index address (such as URL address) of each TS segment of the HLS streaming media to be played; finally, the client downloads and plays the corresponding TS segments in sequence according to the index addresses of each TS segment obtained by the analysis, thereby forming streaming media playback.

[0124] Therefore, when HLS streaming media such as audio and video needs to be played, first, the M3U8 index file corresponding to the HLS streaming media to be played needs to be obtained, so as to subsequently obtain the network address information storing the playback data of the HLS streaming media by parsing the M3U8 index file.

[0125] Specifically, in this embodiment, the operation of obtaining the M3U8 index file can be performed in the main thread of the client that needs to play the HLS streaming media. The specific acquisition process is as follows:

[0126] The main thread of the client sends a play request to the server storing the M3U8 index file, wherein the play request may be a live broadcast request, a video-on-demand request, or a playback request;

[0127] The server verifies the client's identity information and establishes an HTTP connection with the client's main thread;

[0128] The main thread of the client downloads the M3U8 index file of the HLS streaming media to be played from the server through the HTTP connection.

[0129] An index file parsing module 202 is used to parse the M3U8 index file through a main thread to obtain URL addresses of all TS segments of the HLS streaming media to be played;

[0130] After the main thread of the client downloads the M3U8 index file of the HLS streaming media to be played from the server, it performs a parsing operation of the M3U8 index file to obtain the network address information storing the playback data of the HLS streaming media.

[0131] Specifically, in this embodiment, the M3U8 index file is parsed by the main thread to obtain the URL addresses of all TS segments of the HLS streaming media to be played. All TS slices of HLS streaming media are stored in the server, and the M3U8 index file established by the server configures a corresponding URL address (i.e., the network address information of the playback data of the TS segment) for each TS segment, that is, each TS segment corresponds to a URL address, therefore, the URL addresses of all TS segments of the HLS streaming media to be played can be obtained by parsing the M3U8 index file.

[0132] The first URL address opening module 203 is used to create a corresponding number of sub-threads according to the number of URL addresses of the TS fragments obtained by the parsing during the main thread parsing the M3U8 index file, and open the URL addresses corresponding to the parsed TS fragments through the sub-threads, wherein:

[0133] The number of newly created child threads is less than or equal to a preset number n of newly created child threads, where n is a positive integer, and the preset number n of newly created child threads is less than the number of TS fragments of the HLS streaming media to be played;

[0134] In the prior art, the URL address opening operation is usually performed after the M3U8 index file is parsed (the URL address opening operation is a pre-order step for downloading the TS segment playback data, i.e., establishing an HTTP connection between the playback data download thread and the server). When the M3U8 index file is large, the process of parsing the M3U8 index file takes a long time, so waiting for the parsing to be completed before downloading will waste time, resulting in a long time and slow start-up speed during streaming media playback.

[0135] In the present embodiment, during the process of the main thread parsing the M3U8 index file, a corresponding number of child threads are newly created according to the number of URL addresses of the TS fragments obtained by the parsing, so as to concurrently open the URL addresses corresponding to the various TS fragments obtained by the parsing by adopting multithreading. In this way, the opening operation of the URL address can be performed concurrently with the parsing operation of the M3U8 index file, without waiting for the M3U8 index file to be parsed, as long as the URL addresses corresponding to the TS fragments are parsed from the M3U8 index file, a corresponding number of child threads are newly created to concurrently open the URL addresses corresponding to the various TS fragments, that is, the opening operations of the multiple URL addresses that have been parsed are also performed concurrently.

[0136] Therefore, this step can effectively avoid the problem of long start-up time and slow start-up speed during streaming media playback caused by the need to wait for the parsing to be completed and then downloading in the prior art, effectively improve the start-up speed and achieve fast start-up. The larger the M3U8 index file, the more obvious the optimization of the start-up time.

[0137] At the same time, in this embodiment, the concurrency of sub-threads is limited by presetting the number n of newly created sub-threads, which can effectively avoid too many newly created threads occupying too many system resources while improving the startup speed, thereby reducing the impact on the scheduling efficiency of other threads in the system.

[0138] Specifically, in this embodiment, the preset number of newly created sub-threads n can be determined according to device performance and network bandwidth. The device performance can specifically include the number of concurrent connection requests supported by the server, and the CPU performance and memory size of the client; the bandwidth refers to the bandwidth of the communication network between the server and the client.

[0139] The play data download module 204 is used to download the play data corresponding to each TS segment from each opened URL address in sequence through a download thread when the URL address corresponding to the first TS segment is opened.

[0140] In order to further improve the start-up speed and better avoid playback jams, after the URL address corresponding to the first TS segment is opened, the playback data corresponding to each TS segment can be downloaded from each opened URL address in sequence through a download thread. Specifically, the download thread can be created after the URL address corresponding to the first TS segment is opened, or it can be created in advance.

[0141] It should be noted that the download operation of the playback data performed by the download thread can be performed after the main thread completes the parsing operation of the M3U8 index file, or it can be performed during the parsing operation of the M3U8 index file performed by the main thread. In order to maximize the start speed, as long as the URL address corresponding to the first TS segment is opened, a new download thread can be immediately created to start the download operation of the playback data. Specifically, the download operation of the playback data is that the download thread downloads the playback data of the corresponding TS segment from the server according to the opened URL address, so as to realize online playback by performing data parsing and other processing on the downloaded playback data in the future.

[0142] In summary, in the above embodiment, in the process of parsing the M3U8 index file through the main thread, a corresponding number of sub-threads are newly created to concurrently open the URL addresses corresponding to the parsed TS fragments, which effectively avoids the problem of long start-up time and slow start-up speed during streaming media playback caused by the need to wait for the parsing to be completed and then downloading to waste time in the prior art, effectively improving the start-up speed and realizing fast start-up; at the same time, by pre-setting the number of newly created sub-threads n to limit the concurrency of sub-threads, it is effectively avoided that the number of newly created threads is too large and occupies too many system resources, thereby reducing the impact on the scheduling efficiency of other threads of the system; in the process of opening the URL addresses corresponding to each TS fragment by the sub-thread, as long as the URL address corresponding to the first TS fragment is opened, the download thread concurrently executes the download operation of the playback data corresponding to the TS fragment on the opened URL address, thereby further improving the start-up speed and better avoiding playback jams. Therefore, this embodiment can improve the start-up speed, and effectively avoid network bandwidth waste, playback jams and excessive occupation of system resources. The HLS streaming media playback system of this embodiment is applicable to a wide range of playback scenarios, and can be applied to a variety of playback scenarios such as live broadcast, on-demand and playback of HLS streaming media.

[0143] Based on the above embodiment, the system may further include:

[0144] A URL address retrieval module is used to retrieve in sequence through the main thread whether the URL addresses corresponding to the various TS segments have been opened when the M3U8 index file has been parsed;

[0145] The second URL address opening module performs a URL address opening operation on the URL address corresponding to the TS segment that has not yet been opened according to the search result through the main thread.

[0146] After the M3U8 index file is parsed, the main thread then performs the URL address opening operation. Since the preset number of newly created child threads n is less than the number of TS segments of the HLS streaming media to be played, after the M3U8 index file is parsed, at least one URL address corresponding to a part of the TS segments will not be opened. In this way, before the main thread performs the URL address opening operation, it is necessary to first sequentially search whether the URL addresses corresponding to the various TS segments have been opened by the newly created child threads, so that the main thread can determine which TS segment corresponds to the URL address to start the URL address opening operation.

[0147] After the main thread completes the search, it can determine which URL addresses corresponding to the TS segments have been opened by the newly created child threads. At this time, the operation of the newly created child thread is stopped, and the main thread performs the URL address opening operation on the URL addresses corresponding to the TS segments that have not yet been opened according to the search results (the URL addresses that have started to be opened but have not yet completed the opening operation continue to be opened by the corresponding child threads). In this way, after the main thread completes the parsing operation, the main thread is fully utilized to perform the URL address opening operation and the operation of the newly created child thread is stopped, which effectively reduces the system resource occupation caused by the newly created child thread, improves the utilization rate of the main thread, and realizes the dynamic adjustment of the balance between network bandwidth utilization and system resource occupation.

[0148] Based on the above embodiment, the first URL address opening module is specifically used to create a corresponding number of sub-threads according to the number of URL addresses of the parsed TS fragments, and open the URL addresses corresponding to the parsed TS fragments through the sub-threads:

[0149] Create a new sub-thread with the same number of URL addresses of the parsed TS fragments, and open the URL addresses of the parsed TS fragments one by one through the newly created sub-threads.

[0150] In this embodiment, during the process of the main thread parsing the M3U8 index file, a number of sub-threads equal to the number of URL addresses of the parsed TS fragments are newly created, and the URL addresses of the parsed TS fragments are opened one by one and concurrently using the newly created sub-threads, that is, a sub-thread is assigned to the URL address of each TS fragment, and the URL addresses of each TS fragment are opened by different sub-threads, respectively, thereby better avoiding the occasional jamming caused by waiting for the URL address of the next TS fragment to be opened, and at the same time improving the network bandwidth utilization rate; in addition, during the process of the main thread parsing the M3U8 index file, a new sub-thread is simultaneously created to open the URL address of the first TS fragment, thereby realizing the early opening of the URL address of the first TS fragment and ensuring the rapid start of HLS streaming media.

[0151] Based on the above embodiment, the first URL address opening module is specifically used to create the same number of sub-threads as the number of URL addresses of the parsed TS fragments, and to concurrently open the URL addresses of the parsed TS fragments through the newly created sub-threads one by one:

[0152] Each time the main thread parses out a URL address of the TS segment, a new sub-thread is created for opening the URL address of the TS segment, and the operation of opening the URL address of the TS segment is performed through the newly created sub-thread.

[0153] In this embodiment, during the process of the main thread parsing the M3U8 index file, as long as the URL address of the TS segment is parsed, a new sub-thread is immediately created to open the URL address of the TS segment, that is, when the URL address of the first TS segment is parsed, a new first sub-thread is created to open the URL address of the first TS segment; when the URL address of the second TS segment is parsed, a new second sub-thread is created to open the URL address of the second TS segment, and so on. In this way, the start speed of HLS streaming media and the utilization rate of network bandwidth can be further improved.

[0154] Based on the above embodiment, the system further includes a retrieval control module, which is used to:

[0155] In the process of sequentially searching the URL addresses corresponding to the TS segments by the main thread to see whether they have been opened, when one of the following preset stop search conditions occurs, the search is stopped:

[0156] Stop search condition 1: The URL address of the nth TS fragment has been retrieved, and the URL address of the TS fragment has begun to be opened; since the maximum number of newly created child threads is limited to n, therefore, when the main thread completes the parsing operation of the M3U8 index file and performs a search operation, the number of URL addresses of the TS fragments opened is at most n. At this time, if the URL address of the nth TS fragment has been retrieved and the URL address of the TS fragment has begun to be opened, there will be no subsequent TS fragment URL addresses with sequence numbers greater than n that will begin to be opened or have been successfully opened. Therefore, in order to avoid system resource occupation caused by the search, the search can be stopped immediately.

[0157] Stop search condition 2: The URL address of the i-th TS segment is retrieved, and the URL address of the i-th TS segment has not been opened, where i is a positive integer greater than 1, and i≤n. Although the maximum number of newly created child threads is limited to n, it takes a certain amount of time to create a new child thread to open the URL address of the TS segment. Therefore, it may happen that when the main thread completes the parsing operation of the M3U8 index file and performs a sequential search operation, the number of successfully created child threads and the number of URL addresses of the TS segments that have been opened may be less than n. Therefore, when the URL address of the i-th (1<i≤n) TS segment is retrieved, and the URL address of the i-th TS segment has not been opened, in order to avoid system resource occupation caused by the search, the search can also be stopped immediately.

[0158] Based on the above embodiment, the second URL address opening module is specifically used for:

[0159] When the URL address of the nth TS segment is retrieved and the URL address of the TS segment has been opened, the main thread starts to perform the URL address opening operation from the URL address corresponding to the n+1th TS segment; or,

[0160] When the URL address of the i-th TS segment is retrieved, and the URL address of the i-th TS segment has not been opened, the main thread starts to perform the URL address opening operation from the URL address corresponding to the i-th TS segment.

[0161] This embodiment can effectively improve the utilization rate of the main thread and reduce the concurrent number of newly created sub-threads, thereby effectively avoiding excessive occupation of system resources while increasing the start-up speed.

[0162] Based on the above embodiment, the system further includes a child thread establishment control module, which is used to:

[0163] After obtaining the M3U8 index file of the HLS streaming media to be played, the size of the M3U8 index file is compared with a preset file size threshold. When the size of the M3U8 index file is greater than the preset file size threshold, in the process of the main thread parsing the M3U8 index file, a corresponding number of child threads are created according to the number of URL addresses of the parsed TS fragments, and the URL addresses corresponding to the parsed TS fragments are opened through the child threads.

[0164] Since the M3U8 index file of the HLS streaming media to be played is relatively large, it takes a long time to parse the M3U8 index file. If the M3U8 index file is parsed and then the download playback data is opened according to the URL address obtained by parsing, it may lead to a reduction in the start-up speed. Therefore, the present application optimizes the existing HLS streaming media playback data processing flow, and the M3U8 index file of the HLS streaming media to be played, the optimization effect of the start-up time consumption brought by the optimized HLS streaming media playback method of the present application is more obvious. However, for some HLS streaming media to be played whose M3U8 index files are relatively small, the HLS streaming media playback method in the prior art will not lead to situations such as too slow start-up speed. Therefore, after obtaining the M3U8 index file of the HLS streaming media to be played, it is also possible to first determine whether it is necessary to start the first URL address opening module 203 to execute the process of the main thread parsing the M3U8 index file, according to the number of URL addresses of the TS fragments obtained by parsing, and to create a corresponding number of sub-threads according to the number of URL addresses of the TS fragments obtained by parsing, and to open the URL addresses corresponding to each TS fragment obtained by parsing through the sub-threads. That is, after the index file acquisition module 201 acquires the M3U8 index file of the HLS streaming media to be played, the system can also compare the size of the M3U8 index file with the preset file size threshold through the child thread establishment control module. When the size of the M3U8 index file is greater than the preset file size threshold, the first URL address opening module 203 is started to execute the steps of creating a corresponding number of child threads according to the number of URL addresses of the resolved TS fragments during the process of the main thread parsing the M3U8 index file, and opening the URL addresses corresponding to the resolved TS fragments through the child threads. Among them, the preset file size threshold can be set according to an empirical value, for example, the preset file size threshold can be set to 10kb or 20kb.

[0165] Specifically, the HLS streaming media playback system includes a processor and a memory, and the index file acquisition module 201, the index file parsing module 202, the first URL address opening module 203 and the playback data downloading module 204 are all stored in the memory as program units, and the processor executes the program units stored in the memory to implement the corresponding functions, wherein the processor includes a kernel, and the kernel retrieves the corresponding program unit from the memory. One or more kernels can be set, and the HLS streaming media is played by adjusting the kernel parameters.

[0166] An embodiment of the present application provides a storage medium, in which computer executable instructions are stored. When the computer executable instructions are loaded and executed by a processor, the HLS streaming media playback method is implemented.

[0167] An embodiment of the present application provides a processor, which is used to run a program, wherein the method for playing HLS streaming media is executed when the program is run.

[0168] like Figure 3 As shown, an embodiment of the present invention provides a HLS streaming media playback device 30, which includes at least one processor 301, and at least one memory 302 and a bus 303 connected to the processor 301; wherein the processor 301 and the memory 302 communicate with each other through the bus 303; the processor 301 is used to call the program instructions in the memory 302 to execute the above-mentioned HLS streaming media playback method. The HLS streaming media playback device in this application can be a server, PC, PAD, mobile phone, etc.

[0169] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.

[0170] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.

[0171] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, software modules executed by a processor, or a combination of the two. The software modules may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.

[0172] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A method for playing HLS streaming media, characterized in that: The method comprises: Get the M3U8 index file of the HLS streaming media to be played; Parse the M3U8 index file through the main thread to obtain the URL addresses of all TS segments of the HLS streaming media to be played; In the process of parsing the M3U8 index file by the main thread, a corresponding number of sub-threads are newly created according to the number of URL addresses of the TS fragments obtained by the parsing, and the URL addresses corresponding to the respective TS fragments obtained by the parsing are opened by the sub-threads, wherein: The number of newly created child threads is less than or equal to a preset number n of newly created child threads, where n is a positive integer, and the preset number n of newly created child threads is less than the number of TS fragments of the HLS streaming media to be played; When the URL address corresponding to the first TS segment is opened, the download thread sequentially downloads the playback data corresponding to each TS segment from each opened URL address; The method further comprises: When the M3U8 index file is parsed, the main thread sequentially searches for URL addresses corresponding to the TS segments to see whether they have been opened; and The main thread performs a URL address opening operation on the URL address corresponding to the TS segment that has not yet been opened according to the search result.

2. The method for playing HLS streaming media according to claim 1, characterized in that: The creating of a corresponding number of child threads according to the number of URL addresses of the parsed TS fragments, and opening the URL addresses corresponding to the parsed TS fragments through the child threads includes: Each time the main thread parses out a URL address of the TS segment, a new sub-thread is created for opening the URL address of the TS segment, and the operation of opening the URL address of the TS segment is performed through the newly created sub-thread.

3. The method for playing HLS streaming media according to claim 1, characterized in that: The method further comprises: In the process of sequentially searching the URL addresses corresponding to the TS segments by the main thread to see whether they have been opened, when one of the following preset stop search conditions occurs, the search is stopped: Stop retrieval condition 1: The URL address of the nth TS segment has been retrieved, and the URL address of the TS segment has been opened; Stop retrieval condition 2: The URL address of the i-th TS segment is retrieved, and the URL address of the i-th TS segment has not been opened yet, where i is a positive integer greater than 1, and i≤n.

4. The method for playing HLS streaming media according to claim 3, characterized in that: The performing of the URL address opening operation on the URL address corresponding to the TS segment that has not yet been opened according to the search result by the main thread includes: When the URL address of the nth TS segment is retrieved and the URL address of the TS segment has been opened, the main thread starts to perform the URL address opening operation from the URL address corresponding to the n+1th TS segment; or, When the URL address of the i-th TS segment is retrieved, and the URL address of the i-th TS segment has not been opened, the main thread starts to perform the URL address opening operation from the URL address corresponding to the i-th TS segment.

5. The method for playing HLS streaming media according to claim 1, characterized in that: After obtaining the M3U8 index file of the HLS streaming media to be played, the method further includes: The size of the M3U8 index file is compared with a preset file size threshold. When the size of the M3U8 index file is greater than the preset file size threshold, the step of creating a corresponding number of child threads according to the number of URL addresses of the parsed TS fragments during the process of the main thread parsing the M3U8 index file, and opening the URL addresses corresponding to the parsed TS fragments through the child threads is executed.

6. The method for playing HLS streaming media according to any one of claims 1, 2, 4, and 5, characterized in that: The preset number n of newly created sub-threads is determined according to device performance and network bandwidth, wherein: The device performance includes the number of concurrent connection requests supported by the server, and the CPU performance and memory size of the client; The network bandwidth refers to the bandwidth of the communication network between the server and the client.

7. A HLS streaming media playback system, characterized in that: The system comprises: An index file acquisition module is used to obtain the M3U8 index file of the HLS streaming media to be played; An index file parsing module, used for parsing the M3U8 index file through a main thread to obtain URL addresses of all TS segments of the HLS streaming media to be played; The first URL address opening module is used to create a corresponding number of sub-threads according to the number of URL addresses of the TS fragments obtained by the parsing during the main thread parsing the M3U8 index file, and open the URL addresses corresponding to the respective TS fragments obtained by the parsing through the sub-threads, wherein: The number of newly created child threads is less than or equal to a preset number n of newly created child threads, where n is a positive integer, and the preset number n of newly created child threads is less than the number of TS fragments of the HLS streaming media to be played; The playback data download module is used to download the playback data corresponding to each TS segment from each opened URL address in sequence through the download thread when the URL address corresponding to the first TS segment is opened; A retrieval module is used to retrieve, in order through the main thread, whether the URL addresses corresponding to the respective TS segments have been opened after the parsing of the M3U8 index file is completed; The second URL address opening module is used to perform a URL address opening operation on the URL address corresponding to the TS segment that has not yet started to be opened according to the search result through the main thread.

8. A HLS streaming media playback device, comprising at least one processor and at least one memory connected to the processor via a bus, characterized in that: The processor is used to call the program instructions in the memory to execute the HLS streaming media playback method according to any one of claims 1 to 6.

9. A storage medium storing computer executable instructions, characterized in that: When the computer executable instructions are loaded and executed by the processor, the HLS streaming media playback method according to any one of claims 1 to 6 is implemented.

Citation Information

Patent Citations

  • HDFS multithreaded parallel downloading method

    CN104462324A

  • Resource file downloading method and device, equipment and medium

    CN112311897A