The present disclosure relates to the technical field of communications and, more particularly, relates to a video stream redirecting method, device, and an electronic apparatus.
In existing methods, redirecting a stream to a designated proxy server is usually realized through the process steps shown in
However, in a video requesting process in the UIWebView widget, the step of determining whether a proxy is set in the system cannot be performed. That is, the stream cannot be redirected according to the above-described stream redirecting method. Accordingly, existing stream redirecting methods are not suitable for redirecting video stream UIWebView,
In view of the alcove defects in the existing technologies, the present disclosure provides a video stream redirecting method, device, and an electronic apparatus, to solve the problems in the existing technologies which are not able to redirect the stream generated during video playback in UIWebView.
To achieve the above and other related objects, the present disclosure provides a video stream redirecting method, which includes: constructing a new initialization function for video URL, parameters and a return value of which are the same as those of an original initialization function; hijacking the original initialization function, such that when a system calls the original initialization function to request a corresponding video, the new initialization function for video URL is executed, changing a target address in the URL to an address of a designated proxy server so as to redirect the video stream to the designated proxy server.
Optionally, hijacking the original initialization function includes: exchanging actual, code addresses of the new initialization function for video URL and the original initialization function, such that when the system calls the original initialization function to request the corresponding video, the new initialization function for video URL is executed.
Optionally, the new initialization function for video URL is an AVUrlAsset class initialization method.
Optionally, executing the new initialization function for video URL to redirect the video stream to the designated proxy server includes: determining whether a host name of the URL parameter in the original initialization function is the same as a host name of the designated proxy server; if so, directly calling back the original initialization function to request the corresponding video, to redirect the video stream to the designated proxy server; and if not, changing the host name of the URL parameter to the host name of the designated proxy server, extracting the host name and a path of the URL parameter before being changed as a path of the URL parameter after being changed, and then calling back the original initialization function to request the corresponding video, to redirect the video stream to the designated proxy server.
Optionally, before determining whether the host name of the URL parameter in the original initialization function is the same as the host name of the designated proxy server, it is determined whether the accessing mode of the URL parameter in the original initialization function is http or https; if not, the original initialization function is called back directly to request the corresponding video; and if so, determining whether the host name of the URLfunction in the original initialization function is the same as the host name of the designated proxy server is performed.
To achieve the above and other related objects, the present disclosure also provides a video stream redirecting device, including: a function construction module, configured to construct a new initialization function for video URL, parameters and a returned value of which are the same as those of an original initialization function; a stream redirecting module, configured to hijack the original initialization function, such that when a system calls the original initialization function to request a corresponding video, the new initialization function for video URL is executed, changing a target address in the URL to an address of a designated proxy server so as to redirect the video stream to the designated proxy server.
Optionally, hijacking the original initialization function by the stream redirecting module includes exchanging actual code addresses of the new initialization function for video URL and the original initialization function, such that when the system calls the original initialization function to request the corresponding video, the new initialization function for video URL is executed.
Optionally, the new initialization function for video URL is an AVUrlAsset initialization method.
Optionally, executing the new initialization function for video URL by the stream redirecting module to redirect the video stream to the designated proxy server includes: determining whether a host name of a URL parameter in the original initialization function is the same as a host name of the designated proxy server; if so, directly calling back the original initialization function to request the corresponding video; and if not, changing the host name of the URL parameter to the host name of the designated proxy server, extracting the host name and a path of the URL parameter before being changed as a path of the URL parameter after being changed, and then calling back the original initialization function to request the corresponding video, to redirect the video stream to the designated proxy server.
Optionally, the stream redirecting module is further configured to, before determining whether the host name of the URL parameter in the original initialization function is the same as the host name of the designated proxy server, determine whether an accessing mode of the URL parameter in the original initialization function is http or https; if not, then directly call back the original initialization function to request the corresponding video; and if so, then perform determining whether the host name of the URL parameter in the original initialization function is the same as the host name of the designated proxy server.
To achieve the above or other related objects, the present disclosure also provides an electronic apparatus. A system of the electronic apparatus is the iOS system. The electronic apparatus includes a video stream redirecting device according to any one of the above, to perform stream redirecting on a received video request.
Optionally, the electronic apparatus is a smart phone or a tablet.
As described above, a video stream redirecting method, device, and an electronic apparatus according to the present disclosure hijacks an original initialization function by constructing a new initialization function for video URL and exchanging addresses of the original initialization function and the new initialization function for video URL. That is, when the system calls the original initialization function to request a corresponding video, the new initialization function for video URL is executed to redirect the video stream to a designated proxy server, and thus realizing the stream redirecting of video requests for the UIWebView widget in iOS.
Modes of implementing the disclosure will be described below through specific embodiments. One of ordinary skill in the art can easily understand other advantages and effects of the present disclosure based on the disclosure of the present specification. The present disclosure can also be implemented or applied through other different modes. Details in the present specification can also be modified or changed based on different views and applications, without departing the spirit of the present disclosure. It is to be noted that the following embodiments and the features in the embodiments can be combined as long as they do not conflict with each other.
It is to be noted that the drawings provided in the following embodiments merely schematically illustrate basic concept of the present disclosure. Each drawing only shows components relevant to the present disclosure, but does not show the number, shapes, and sizes of the components during actual implementation. During the actual implementation, the configuration, number, and dimensions of respective components can be Changed as needed, and the arrangement of the components may be more complicated.
S11: constructing a new initialization function for video URL. Parameters and a returned value of the new initialization function for video URL are the saint as those of an original initialization function.
For example, a new initialization method, hookInitWithURL, can be constructed in a newly-defined AVUrlAsset class. The parameters and returned value of this method are kept the same as those of the original initialization method, InitWithURL, in the AVUrlAsset class.
S12: hijacking the original initialization function, such that when a system calls the original initialization function to request a corresponding video, the new initialization function for video URL is executed, changing a target address in the URL to an address of a designated proxy server so as to redirect the video stream to the designated proxy server. That is, before playing the video link using the UIWebView widget, the iOS system calls InitWithUrl in the AVUrlAsset class to perform initialization, at which time the constructed new method, hookInitWithURL, will be called but the original initialization method will not be called. As such, the video stream can be redirected to the designated proxy server.
Further,
S21: constructing a new initialization function for video URL. Parameters and a returned value of the new initialization function for video URL are the same as those of an original initialization function. The process in S21 is the same as the process in S11 in the embodiment shown in
Further, the step of hijacking the original initialization function in S12 in the embodiment shown in
S22: exchanging actual code addresses of the new initialization function for video URL and the original initialization function, such that when the system calls the original initialization function to request the corresponding video, the new initialization function for video URL is executed. That is, actual code addresses of the newly-constructed initialization function and the original initialization function are obtained, respectively. After the exchanging, realization of InitWithURL will be executed when hookInitWithURL is called, while realization of hookInitWithURL will be executed when InitWithURL is called.
Further, in S12 in the embodiment shown in
S23: determining whether an accessing mode of a URL parameter in the original initialization function is http or https. If so, S24 is executed. If not, S25 is executed. That is, in this embodiment, the video stream redirecting may be performed only on accesses having an http or https accessing mode.
S24: determining whether a host name of the URL parameter in the original initialization function is the same as a host name of the designated proxy server. If so, S25 is executed. If not, S26 is executed.
S25: directly calling back the original initialization function to request the corresponding video, to redirect the video stream to the designated proxy server.
S26: changing the host name of the URL parameter to the host name of the designated proxy server, extracting the host name and a path of the URL parameter before being changed as a path of the URL parameter after being changed, and then calling back the original initialization function to request the corresponding video, to redirect the video stream to the designated proxy server.
Further, before determining whether the host name of the URL parameter in the original initialization function is the same as the host name of the designated proxy server, it is determined whether the accessing mode of the URL parameter in the original initialization function is http or https. If not, the original initialization function is called back directly to request the corresponding video. If so, determining whether the host name of the URL function in the original initialization function is the same as the host name of the designated proxy server is performed.
For example, in a specific application, assume the URL of a video request is: http://hostnameA.com/video, and the address of the designated proxy server is: 127.0.0.1:8123, then when the iOS system initializes an AVUrlAsset object, the newly-constructed initialization function is executed by hijacking the original initialization function. That is, the following is performed:
Because the accessing mode of the URL is http, it is further determined whether the host name of the URL parameter is the same as the host name of the designated proxy server.
In this application example, the host name of the URL parameter is different from the host name of the designated proxy server. Thus, the host name of the URL is changed to 127.0.0.1:8123, and the path is changed to hostnameA.com/video. The new URL, http://127.0.0.1:8123/hostnameA.com/video, is formed. The original initialization function is then called back using the changed URL as a parameter to request the corresponding video, to redirect the video stream to the designated proxy server 127.0.0.1:8123.
The present disclosure is explained with respect to the video stream in the iOS system. One of ordinary skill in the art should understand that, based on similar inventive concept, adaptive parameter modifications can be performed on another system such as the android system, and the purpose of redirecting videos can also be achieved. It should also fall in the scope of protection of the present disclosure.
The function construction module 11 is configured to construct a new initialization function for video URL. Parameters and a returned value of the new initialization function for video URL are the same as those of an original initialization function.
The stream redirecting module 12 is configured to hijack the original initialization function, such that when a system calls the original initialization function to request a corresponding video, the new initialization function for video URL is executed, changing a target address in the URL to an address of a designated proxy server so as to redirect the video stream to the designated proxy server.
Further, in another embodiment, hijacking the original initialization function by the stream redirecting module 12 includes exchanging actual code addresses of the new initialization function for video URL and the original initialization function, such that when the system calls the original initialization function to request the corresponding video, the new initialization function for video URL is executed.
Further, in another embodiment, executing the new initialization function for video URL by the stream redirecting module 12 to redirect the video stream to the designated proxy server includes: determining whether a host name of a URL parameter in the original initialization function is the same as a host name of the designated proxy server; if so, directly calling back the original initialization function to request the corresponding video; and if not, changing the host name of the URL parameter to the host name of the designated proxy server, extracting the host name and a path of the URL parameter before being changed as a path of the URL parameter after being changed, and then calling back the original function to request the corresponding video, to redirect the video stream to the designated proxy server.
Further, in another embodiment, the stream redirecting module 12 is further configured to, before determining whether the host name of the URL parameter in the original initialization function is the same as the host, name of the designated proxy server, determine whether an accessing mode of the URL parameter in the original initialization function is http or https; if not, then directly call back the original initialization function to request the corresponding video; and if so, then perform determining whether the host name of the URL parameter in the original initialization function is the same as the host name of the designated proxy server.
The application principle and the technical features of the video stream redirecting device 1 correspond to the video stream redirecting methods shown in
In summary, a video stream redirecting method, device, and an electronic apparatus according to the present disclosure hijacks an original initialization function by constructing a new initialization function for video URL and exchanging addresses of the original initialization function and the new initialization function for video URL. That is, when the system calls the original initialization function to request a corresponding video, the new initialization function for video URL is executed to redirect the video stream to a designated proxy server, and thus realizing the stream redirecting of video requests for the UIWebView widget in iOS. Therefore, the present disclosure overcomes various defects in the existing technologies, and thus has a high value in industrial applications.
The above-described embodiments are merely examples for explaining the principles and effects of the present disclosure, but not to limit the present disclosure. Any person familiar with the technology can modify or change the above-described embodiments without departing from the spirit and scope of the present disclosure. Therefore, any equivalent modification and change accomplished by a person of ordinary skill in the art without departing the spirit and technical idea disclosed by the present disclosure should be covered by the claims set forth below.
Number | Date | Country | Kind |
---|---|---|---|
2015103597945 | Jun 2015 | CN | national |
Filing Document | Filing Date | Country | Kind |
---|---|---|---|
PCT/CN2015/094270 | 11/11/2015 | WO | 00 |