The described technology is directed to the field of background processing techniques.
Video editing refers to generating a video sequence, in some cases a video sequence that includes music or other audio. For example, a user can specify a sequence of still images, graphics surfaces, and/or video clips, audio mixing, visual compositions and transitions between them, accompanying audio resources, and timing aspects about which components start when. Producing a video sequence based upon such input from a user generally involves performing format conversion, video resolution changes, and audio sampling rate changes, from various resource types such as images, audio sequences, and video sequences.
Recently, video editing applications have become available that permit users of smart phones to perform video editing.
A facility for completing a set of operations is described. In one example facility, under the control of an application, the facility registers the background task to perform the set of operations. In response to the receipt registration of the background task, the facility repeatedly invokes the background task to perform the set of operations.
The inventors have recognized that conventional video editing applications for smartphones have significant disadvantages. In particular, after collecting user input specifying how the video sequence should be constructed, these applications tend to do the format conversions and other operations needed to generate the resulting video sequence in the main application thread. These format conversions are typically processor-intensive, especially on a smart phone that has a significantly less-powerful processors than a desktop or laptop computer; as a result, successfully generating a video sequence with such conventional applications usually requires that, after specifying how a video sequence should be constructed, the user permit the application to continue running uninterrupted for a significant period of time—often a minute or more—while it performs the necessary conversions and saves the video sequence. This is a difficult proposition for many smart phone users, who instead tend to switch to one or more other applications, causing the video-editing application to run slowly, be suspended, or even be swapped out of working memory or terminated. When this happens, the video sequence does not end up being generated and saved, and the user is discouraged.
In response to this recognition, the inventors have conceived and reduced to practice a software and/or hardware facility for performing processing intensive operations—such as video-editing and associated format conversion and/or transcoding—on smart phones, tablet computers, wearable computers, and other multi-tasking, limited-capacity devices (“the facility”).
The facility makes use of a mechanism, such as one provided by an operating system, for invoking background tasks for performing processing-intensive operations. In accordance with the facility, an application (1) isolates code for performing the processing-intensive operations, such as video transcoding, and (2) registers a trigger used to automatically invoke this application code for performing the processing-intensive operations in a background task. In some examples, as part of registering the trigger, the application can establish conditions that are to be satisfied in order for the application's processing-intensive code to be invoked. Available conditions include maximum ambient processing loads, minimum amount of time since the last user interaction, a maximum number of background tasks executing for other applications, etc. In some examples, some of these conditions are established automatically by the facility, either as a matter of course, or based upon some analysis of the application's processing-intensive code, the application's importance, etc.
In response to registration of the trigger, until the trigger is disabled, the facility periodically invokes the application's processing-intensive code in the background task, subject to any conditions specified during the trigger's registration.
In some examples, when the background task finishes executing the application's processing-intensive code, the application's main code is notified. For example, for the video-editing application, upon receiving such a notification, it can make the resulting video sequence available for playing by the user, sharing or uploading by the user, etc.
In some examples, when the background task finishes executing the application's processing-intensive code, the trigger is disabled. In various examples, this is done in the background task, or in the application's main code upon notification that the background task has completed.
In some examples, the facility includes a resource manager that observes the use of resources by the background task, and compares them to resource limits established for the background task. For example, in various examples, the facility supports specification of resource limits such as a maximum memory allocation for the background thread, a maximum processing allocation for the background thread, etc. If, while executing, the background task exceeds any of these resource limits, the resource manager kills the background task without disabling its trigger. Accordingly, the facility will later reinvoke the background task based upon the trigger, and the background task continues based on the previous ending point.
In some examples, the processing-intensive code executed in the background task is structured to do its processing in discrete, low-overhead “chunks,” each of whose result is saved persistently as soon as it is completed, to facilitate performing the processing-intensive operations across multiple invocations of the background thread, where the background thread is terminated by the resource manager for over-use of resources, by restarting the device or its operating system, etc. For example, in the case of video-editing, each chunk is the transcoding needed to generate output video for a subsequent span of time, such as 5 seconds, such that the background thread can generate 10 seconds of the result in the first invocation, the next 5 seconds in the second implication, the next 20 seconds in the third implication, etc.
In some examples, rather than or in addition to being established for known inputs like a human-authored video-editing composition, a trigger is established in accordance with the facility to execute the background task against inputs that arise over time, such as to examine the photographs and video clips that that have recently been shot with the phone, automatically author a composition that incorporates them, and perform the necessary transcoding to generate the resulting video sequence. In some such examples, the facility establishes rigorous conditions for invoking the background tasks for these triggers, so that these background tasks are scheduled at times when the risk of them competing for resources is low, such as when the screen is off, or when the user hasn't provided any input for an extended period such as five minutes.
In some examples, the facility offloads the processing of certain processing-intensive operations to a separate device, such as to a cloud server, or to a desktop or laptop computer having extra processing capacity.
By performing in some or all of the ways described above, the facility facilitates the completion of processing-intensive operations on multi-tasking devices—such as those with limited capacity—in a manner that interferes minimally with use of the device for other purposes.
In line 1, the facility instantiates a new object of class ResourcelntensiveTrigger called trigger. In line 2, the facility instantiates a new object of the class BackgroundTaskBuilder( ) called builder. In lines 3-6, the facility initializes the builder object. In particular, in line 4, the facility initializes a TaskEntryPoint data member of the builder object within entry point for the application code that will run in the background task. In line 5, the facility invokes a SetTrigger method of the builder object to associate the trigger object with the builder object. Finally, in line 6, the facility invokes a Register method of the builder object to register the background task and its trigger.
At 303, the facility serializes the composition built in step 301; that is, it saves the composition in a manner that makes it accessible to the background task, such as within the application container. At 304, the facility fires a trigger associated with the background task, such as by executing the pseudocode shown in Table 2 below to invoke the RequestAsync method on the trigger object instantiated and initialized in Table 1 above.
After act 304, the acts shown in
Those skilled in the art will appreciate that the steps shown in
In a variety of examples, the facility is adapted to perform a variety of different kinds of processing-intensive operations and other operations. For example, in various examples, the facility performs operations such as selecting the best photos or other media resources among the group; improving the quality of photos, video clips, audio sequences, or media resources of other types; detecting faces in visual media resources; tagging media resources, such as with GPS information identifying the place where they were captured; mixing audio resources; etc.
In some examples, a method in a computing system configured to generate a video sequence is performed. The method comprises: under the control of the video-editing application, registering a background task of the application to generate a video sequence based upon a video composition generated with the video-editing application; in response to the registration of the background task, repeatedly invoking the background task to generate the video sequence; and, when the background task is completed generation of the video sequence, notifying the video-editing application.
In some examples, one or more instances of computer-readable media collectively having contents configured to cause a computing system to perform a method configured to complete a set of operations is provided. The method comprises: under the control of an application, registering a background task to perform the set of operations; and, in response to the registration of the background task, repeatedly invoking the background task to perform a set of operations.
In some examples, one or more instances of computer-readable media correctly having contents comprising a trigger data structure for background tasks is provided. The data structure comprises: a plurality of entries each corresponding to a different background task designated by an application, each entry comprising information usable to automatically invoked the background task to which the entry corresponds, such that the contents the data structure can be used to automatically invoked the background task to which any entry corresponds.
It will be appreciated by those skilled in the art that the above-described facility may be straightforwardly adapted or extended in various ways. While the foregoing description makes reference to particular examples, the scope of the invention is defined solely by the claims that follow and the elements recited therein.