1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.messaging.datamodel.media;
17 
18 import java.util.List;
19 
20 /**
21  * Keeps track of a media loading request. MediaResourceManager uses this interface to load, encode,
22  * decode, and cache different types of media resource.
23  *
24  * This interface defines a media request class that's threading-model-blind. Wrapper classes
25  * (such as {@link AsyncMediaRequestWrapper} wraps around any base media request to offer async
26  * extensions).
27  */
28 public interface MediaRequest<T extends RefCountedMediaResource> {
29     public static final int REQUEST_ENCODE_MEDIA = 1;
30     public static final int REQUEST_DECODE_MEDIA = 2;
31     public static final int REQUEST_LOAD_MEDIA = 3;
32 
33     /**
34      * Returns a unique key used for storing and looking up the MediaRequest.
35      */
getKey()36     String getKey();
37 
38     /**
39      * This method performs the heavy-lifting work of synchronously loading the media bytes for
40      * this MediaRequest on a single threaded executor.
41      * @param chainedTask subsequent tasks to be performed after this request is complete. For
42      * example, an image request may need to compress the image resource before putting it in the
43      * cache
44      */
loadMediaBlocking(List<MediaRequest<T>> chainedTask)45     T loadMediaBlocking(List<MediaRequest<T>> chainedTask) throws Exception;
46 
47     /**
48      * Returns the media cache where this MediaRequest wants to store the loaded
49      * media resource.
50      */
getMediaCache()51     MediaCache<T> getMediaCache();
52 
53     /**
54      * Returns the id of the cache where this MediaRequest wants to store the loaded
55      * media resource.
56      */
getCacheId()57     int getCacheId();
58 
59     /**
60      * Returns the request type of this media request, i.e. one of {@link #REQUEST_ENCODE_MEDIA},
61      * {@link #REQUEST_DECODE_MEDIA}, or {@link #REQUEST_LOAD_MEDIA}. The default is
62      * {@link #REQUEST_LOAD_MEDIA}
63      */
getRequestType()64     int getRequestType();
65 
66     /**
67      * Returns the descriptor defining the request.
68      */
getDescriptor()69     MediaRequestDescriptor<T> getDescriptor();
70 }