27 | * public void onCreate(Bundle b) { 28 | * super.onCreate(b); 29 | * if (!io.vov.vitamio.LibsChecker.checkVitamioLibs(this)) 30 | * return; 31 | * 32 | * // Code using Vitamio should go below {@link LibsChecker#checkVitamioLibs} 33 | * } 34 | *35 | */ 36 | public final class LibsChecker { 37 | public static final String FROM_ME = "fromVitamioInitActivity"; 38 | 39 | public static final boolean checkVitamioLibs(Activity ctx) { 40 | if (!Vitamio.isInitialized(ctx) && !ctx.getIntent().getBooleanExtra(FROM_ME, false)) { 41 | Intent i = new Intent(); 42 | i.setClassName(Vitamio.getVitamioPackage(), "io.vov.vitamio.activity.InitActivity"); 43 | i.putExtras(ctx.getIntent()); 44 | i.setData(ctx.getIntent().getData()); 45 | i.putExtra("package", ctx.getPackageName()); 46 | i.putExtra("className", ctx.getClass().getName()); 47 | ctx.startActivity(i); 48 | ctx.finish(); 49 | return false; 50 | } 51 | return true; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /vitamio/src/io/vov/vitamio/MediaFile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 The Android Open Source Project 3 | * Copyright (C) 2013 YIXIA.COM 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package io.vov.vitamio; 19 | 20 | import java.util.HashMap; 21 | import java.util.Iterator; 22 | 23 | 24 | public class MediaFile { 25 | protected final static String sFileExtensions; 26 | 27 | public static final int FILE_TYPE_MP3 = 1; 28 | public static final int FILE_TYPE_M4A = 2; 29 | public static final int FILE_TYPE_WAV = 3; 30 | public static final int FILE_TYPE_AMR = 4; 31 | public static final int FILE_TYPE_AWB = 5; 32 | public static final int FILE_TYPE_WMA = 6; 33 | public static final int FILE_TYPE_OGG = 7; 34 | public static final int FILE_TYPE_AAC = 8; 35 | public static final int FILE_TYPE_MKA = 9; 36 | public static final int FILE_TYPE_MID = 10; 37 | public static final int FILE_TYPE_SMF = 11; 38 | public static final int FILE_TYPE_IMY = 12; 39 | public static final int FILE_TYPE_APE = 13; 40 | public static final int FILE_TYPE_FLAC = 14; 41 | private static final int FIRST_AUDIO_FILE_TYPE = FILE_TYPE_MP3; 42 | private static final int LAST_AUDIO_FILE_TYPE = FILE_TYPE_FLAC; 43 | 44 | public static final int FILE_TYPE_MP4 = 701; 45 | public static final int FILE_TYPE_M4V = 702; 46 | public static final int FILE_TYPE_3GPP = 703; 47 | public static final int FILE_TYPE_3GPP2 = 704; 48 | public static final int FILE_TYPE_WMV = 705; 49 | public static final int FILE_TYPE_ASF = 706; 50 | public static final int FILE_TYPE_MKV = 707; 51 | public static final int FILE_TYPE_MP2TS = 708; 52 | public static final int FILE_TYPE_FLV = 709; 53 | public static final int FILE_TYPE_MOV = 710; 54 | public static final int FILE_TYPE_RM = 711; 55 | public static final int FILE_TYPE_DVD = 712; 56 | public static final int FILE_TYPE_DIVX = 713; 57 | public static final int FILE_TYPE_OGV = 714; 58 | public static final int FILE_TYPE_VIVO = 715; 59 | public static final int FILE_TYPE_WTV = 716; 60 | public static final int FILE_TYPE_AVS = 717; 61 | public static final int FILE_TYPE_SWF = 718; 62 | public static final int FILE_TYPE_RAW = 719; 63 | private static final int FIRST_VIDEO_FILE_TYPE = FILE_TYPE_MP4; 64 | private static final int LAST_VIDEO_FILE_TYPE = FILE_TYPE_RAW; 65 | 66 | protected static class MediaFileType { 67 | int fileType; 68 | String mimeType; 69 | 70 | MediaFileType(int fileType, String mimeType) { 71 | this.fileType = fileType; 72 | this.mimeType = mimeType; 73 | } 74 | } 75 | 76 | private static HashMap
Name | Value Type | Description |
---|---|---|
{@link #KEY_MIME} | String | The type of the format. |
{@link #KEY_MAX_INPUT_SIZE} | Integer | optional, maximum size of a buffer of input data |
{@link #KEY_BIT_RATE} | Integer | encoder-only, desired bitrate in bits/second |
Name | Value Type | Description |
---|---|---|
{@link #KEY_WIDTH} | Integer | |
{@link #KEY_HEIGHT} | Integer | |
{@link #KEY_COLOR_FORMAT} | Integer | set by the user 43 | * for encoders, readable in the output format of decoders |
{@link #KEY_FRAME_RATE} | Integer or Float | encoder-only |
{@link #KEY_I_FRAME_INTERVAL} | Integer | encoder-only |
{@link #KEY_MAX_WIDTH} | Integer | decoder-only, optional, max-resolution width |
{@link #KEY_MAX_HEIGHT} | Integer | decoder-only, optional, max-resolution height |
{@link #KEY_REPEAT_PREVIOUS_FRAME_AFTER} | Long | video encoder in surface-mode only |
{@link #KEY_PUSH_BLANK_BUFFERS_ON_STOP} | Integer(1) | video decoder rendering to a surface only |
Name | Value Type | Description |
---|---|---|
{@link #KEY_CHANNEL_COUNT} | Integer | |
{@link #KEY_SAMPLE_RATE} | Integer | |
{@link #KEY_IS_ADTS} | Integer | optional, if decoding AAC audio content, setting this key to 1 indicates that each audio frame is prefixed by the ADTS header. |
{@link #KEY_AAC_PROFILE} | Integer | encoder-only, optional, if content is AAC audio, specifies the desired profile. |
{@link #KEY_CHANNEL_MASK} | Integer | optional, a mask of audio channel assignments |
{@link #KEY_FLAC_COMPRESSION_LEVEL} | Integer | encoder-only, optional, if content is FLAC audio, specifies the desired compression level. |
{@link #KEY_MIME} | String | The type of the format. |
{@link #KEY_LANGUAGE} | String | The language of the content. |
37 | * MediaMetadataRetriever mmr = new MediaMetadataRetriever(this); 38 | * mmr.setDataSource(this, mediaUri); 39 | * String title = mmr.extractMetadata(METADATA_KEY_TITLE); 40 | * Bitmap frame = mmr.getFrameAtTime(-1); 41 | * mmr.release(); 42 | *43 | */ 44 | public class MediaMetadataRetriever { 45 | private AssetFileDescriptor mFD = null; 46 | 47 | static { 48 | String LIB_ROOT = Vitamio.getLibraryPath(); 49 | Log.i("LIB ROOT: %s", LIB_ROOT); 50 | System.load(LIB_ROOT + "libstlport_shared.so"); 51 | System.load(LIB_ROOT + "libvscanner.so"); 52 | loadFFmpeg_native(LIB_ROOT + "libffmpeg.so"); 53 | native_init(); 54 | } 55 | 56 | private int mNativeContext; 57 | 58 | public MediaMetadataRetriever(Context ctx) { 59 | native_setup(); 60 | } 61 | 62 | private static native boolean loadFFmpeg_native(String ffmpegPath); 63 | 64 | public void setDataSource(Context context, Uri uri) throws IOException, IllegalArgumentException, 65 | SecurityException, IllegalStateException { 66 | if (context == null || uri == null) 67 | throw new IllegalArgumentException(); 68 | String scheme = uri.getScheme(); 69 | if (scheme == null || scheme.equals("file")) { 70 | setDataSource(FileUtils.getPath(uri.toString())); 71 | return; 72 | } 73 | 74 | try { 75 | ContentResolver resolver = context.getContentResolver(); 76 | mFD = resolver.openAssetFileDescriptor(uri, "r"); 77 | if (mFD == null) 78 | return; 79 | setDataSource(mFD.getParcelFileDescriptor().getFileDescriptor()); 80 | return; 81 | } catch (Exception e) { 82 | closeFD(); 83 | } 84 | Log.e("Couldn't open file on client side, trying server side %s", uri.toString()); 85 | setDataSource(uri.toString()); 86 | return; 87 | } 88 | 89 | public native void setDataSource(String path) throws IOException, IllegalArgumentException, 90 | IllegalStateException; 91 | 92 | public native void setDataSource(FileDescriptor fd) throws IOException, IllegalArgumentException, 93 | IllegalStateException; 94 | 95 | /** 96 | * Call this method after setDataSource(). This method retrieves the meta data 97 | * value associated with the keyCode. 98 | * 99 | * The keyCode currently supported is listed below as METADATA_XXX constants. 100 | * With any other value, it returns a null pointer. 101 | * 102 | * @param keyCode One of the constants listed below at the end of the class. 103 | * @return The meta data value associate with the given keyCode on success; 104 | * null on failure. 105 | */ 106 | public native String extractMetadata(String keyCode) throws IllegalStateException; 107 | 108 | public native Bitmap getFrameAtTime(long timeUs) throws IllegalStateException; 109 | 110 | /** 111 | * Call this method after setDataSource(). This method finds the optional 112 | * graphic or album/cover art associated associated with the data source. If 113 | * there are more than one pictures, (any) one of them is returned. 114 | * 115 | * @return null if no such graphic is found. 116 | */ 117 | public native byte[] getEmbeddedPicture() throws IllegalStateException; 118 | 119 | private native void _release(); 120 | 121 | private native void native_setup(); 122 | 123 | private static native final void native_init(); 124 | 125 | private native final void native_finalize(); 126 | 127 | public void release() { 128 | _release(); 129 | closeFD(); 130 | } 131 | 132 | @Override 133 | protected void finalize() throws Throwable { 134 | try { 135 | native_finalize(); 136 | } finally { 137 | super.finalize(); 138 | } 139 | } 140 | 141 | private void closeFD() { 142 | if (mFD != null) { 143 | try { 144 | mFD.close(); 145 | } catch (IOException e) { 146 | } 147 | mFD = null; 148 | } 149 | } 150 | 151 | /* 152 | * Do not change these metadata key values without updating their 153 | * counterparts in c file 154 | */ 155 | 156 | /** 157 | * The metadata key to retrieve the information about the album title of the 158 | * data source. 159 | */ 160 | public static final String METADATA_KEY_ALBUM = "album"; 161 | /** 162 | * The metadata key to retrieve the main creator of the set/album, if 163 | * different from artist. e.g. "Various Artists" for compilation albums. 164 | */ 165 | public static final String METADATA_KEY_ALBUM_ARTIST = "album_artist"; 166 | /** 167 | * The metadata key to retrieve the information about the artist of the data 168 | * source. 169 | */ 170 | public static final String METADATA_KEY_ARTIST = "artist"; 171 | 172 | /** 173 | * The metadata key to retrieve the any additional description of the file. 174 | */ 175 | public static final String METADATA_KEY_COMMENT = "comment"; 176 | /** 177 | * The metadata key to retrieve the information about the author of the data 178 | * source. 179 | */ 180 | public static final String METADATA_KEY_AUTHOR = "author"; 181 | /** 182 | * The metadata key to retrieve the information about the composer of the data 183 | * source. 184 | */ 185 | public static final String METADATA_KEY_COMPOSER = "composer"; 186 | /** 187 | * The metadata key to retrieve the name of copyright holder. 188 | */ 189 | public static final String METADATA_KEY_COPYRIGHT = "copyright"; 190 | /** 191 | * The metadata key to retrieve the date when the file was created, preferably 192 | * in ISO 8601. 193 | */ 194 | public static final String METADATA_KEY_CREATION_TIME = "creation_time"; 195 | /** 196 | * The metadata key to retrieve the date when the work was created, preferably 197 | * in ISO 8601. 198 | */ 199 | public static final String METADATA_KEY_DATE = "date"; 200 | /** 201 | * The metadata key to retrieve the number of a subset, e.g. disc in a 202 | * multi-disc collection. 203 | */ 204 | public static final String METADATA_KEY_DISC = "disc"; 205 | /** 206 | * The metadata key to retrieve the name/settings of the software/hardware 207 | * that produced the file. 208 | */ 209 | public static final String METADATA_KEY_ENCODER = "encoder"; 210 | /** 211 | * The metadata key to retrieve the person/group who created the file. 212 | */ 213 | public static final String METADATA_KEY_ENCODED_BY = "encoded_by"; 214 | /** 215 | * The metadata key to retrieve the original name of the file. 216 | */ 217 | public static final String METADATA_KEY_FILENAME = "filename"; 218 | /** 219 | * The metadata key to retrieve the content type or genre of the data source. 220 | */ 221 | public static final String METADATA_KEY_GENRE = "genre"; 222 | /** 223 | * The metadata key to retrieve the main language in which the work is 224 | * performed, preferably in ISO 639-2 format. Multiple languages can be 225 | * specified by separating them with commas. 226 | */ 227 | public static final String METADATA_KEY_LANGUAGE = "language"; 228 | /** 229 | * The metadata key to retrieve the artist who performed the work, if 230 | * different from artist. E.g for "Also sprach Zarathustra", artist would be 231 | * "Richard Strauss" and performer "London Philharmonic Orchestra". 232 | */ 233 | public static final String METADATA_KEY_PERFORMER = "performer"; 234 | /** 235 | * The metadata key to retrieve the name of the label/publisher. 236 | */ 237 | public static final String METADATA_KEY_PUBLISHER = "publisher"; 238 | /** 239 | * The metadata key to retrieve the name of the service in broadcasting 240 | * (channel name). 241 | */ 242 | public static final String METADATA_KEY_SERVICE_NAME = "service_name"; 243 | /** 244 | * The metadata key to retrieve the name of the service provider in 245 | * broadcasting. 246 | */ 247 | public static final String METADATA_KEY_SERVICE_PROVIDER = "service_provider"; 248 | /** 249 | * The metadata key to retrieve the data source title. 250 | */ 251 | public static final String METADATA_KEY_TITLE = "title"; 252 | /** 253 | * The metadata key to retrieve the number of this work in the set, can be in 254 | * form current/total. 255 | */ 256 | public static final String METADATA_KEY_TRACK = "track"; 257 | /** 258 | * The metadata key to retrieve the total bitrate of the bitrate variant that 259 | * the current stream is part of. 260 | */ 261 | public static final String METADATA_KEY_VARIANT_BITRATE = "bitrate"; 262 | /** 263 | * The metadata key to retrieve the playback duration of the data source. 264 | */ 265 | public static final String METADATA_KEY_DURATION = "duration"; 266 | /** 267 | * The metadata key to retrieve the audio codec of the work. 268 | */ 269 | public static final String METADATA_KEY_AUDIO_CODEC = "audio_codec"; 270 | /** 271 | * The metadata key to retrieve the video codec of the work. 272 | */ 273 | public static final String METADATA_KEY_VIDEO_CODEC = "video_codec"; 274 | /** 275 | * This key retrieves the video rotation angle in degrees, if available. The 276 | * video rotation angle may be 0, 90, 180, or 270 degrees. 277 | */ 278 | public static final String METADATA_KEY_VIDEO_ROTATION = "rotate"; 279 | /** 280 | * If the media contains video, this key retrieves its width. 281 | */ 282 | public static final String METADATA_KEY_VIDEO_WIDTH = "width"; 283 | /** 284 | * If the media contains video, this key retrieves its height. 285 | */ 286 | public static final String METADATA_KEY_VIDEO_HEIGHT = "height"; 287 | /** 288 | * The metadata key to retrieve the number of tracks, such as audio, video, 289 | * text, in the data source, such as a mp4 or 3gpp file. 290 | */ 291 | public static final String METADATA_KEY_NUM_TRACKS = "num_tracks"; 292 | /** 293 | * If this key exists the media contains audio content. if has audio, return 294 | * 1. 295 | */ 296 | public static final String METADATA_KEY_HAS_AUDIO = "has_audio"; 297 | /** 298 | * If this key exists the media contains video content. if has video, return 299 | * 1. 300 | */ 301 | public static final String METADATA_KEY_HAS_VIDEO = "has_video"; 302 | 303 | } -------------------------------------------------------------------------------- /vitamio/src/io/vov/vitamio/MediaScanner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 The Android Open Source Project 3 | * Copyright (C) 2013 YIXIA.COM 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package io.vov.vitamio; 19 | 20 | import android.content.ContentProviderClient; 21 | import android.content.ContentUris; 22 | import android.content.ContentValues; 23 | import android.content.Context; 24 | import android.database.Cursor; 25 | import android.database.SQLException; 26 | import android.net.Uri; 27 | import android.os.RemoteException; 28 | import android.text.TextUtils; 29 | 30 | import io.vov.vitamio.provider.MediaStore; 31 | import io.vov.vitamio.provider.MediaStore.Video; 32 | import io.vov.vitamio.utils.ContextUtils; 33 | import io.vov.vitamio.utils.FileUtils; 34 | import io.vov.vitamio.utils.Log; 35 | 36 | import java.io.File; 37 | import java.util.HashMap; 38 | import java.util.Iterator; 39 | 40 | public class MediaScanner { 41 | private static final String[] VIDEO_PROJECTION = new String[]{Video.Media._ID, Video.Media.DATA, Video.Media.DATE_MODIFIED,}; 42 | private static final int ID_VIDEO_COLUMN_INDEX = 0; 43 | private static final int PATH_VIDEO_COLUMN_INDEX = 1; 44 | private static final int DATE_MODIFIED_VIDEO_COLUMN_INDEX = 2; 45 | private Context mContext; 46 | private ContentProviderClient mProvider; 47 | private boolean mCaseInsensitivePaths; 48 | private HashMap
32 | * Bitmap thumb = ThumbnailUtils.createVideoThumbnail(this, videoPath, MINI_KIND); 33 | *34 | */ 35 | public class ThumbnailUtils { 36 | private static final int OPTIONS_NONE = 0x0; 37 | private static final int OPTIONS_SCALE_UP = 0x1; 38 | public static final int OPTIONS_RECYCLE_INPUT = 0x2; 39 | public static final int TARGET_SIZE_MINI_THUMBNAIL_WIDTH = 426; 40 | public static final int TARGET_SIZE_MINI_THUMBNAIL_HEIGHT = 320; 41 | public static final int TARGET_SIZE_MICRO_THUMBNAIL_WIDTH = 212; 42 | public static final int TARGET_SIZE_MICRO_THUMBNAIL_HEIGHT = 160; 43 | 44 | 45 | public static Bitmap createVideoThumbnail(Context ctx, String filePath, int kind) { 46 | if (!Vitamio.isInitialized(ctx)) { 47 | return null; 48 | } 49 | Bitmap bitmap = null; 50 | MediaMetadataRetriever retriever = null; 51 | try { 52 | retriever = new MediaMetadataRetriever(ctx); 53 | retriever.setDataSource(filePath); 54 | bitmap = retriever.getFrameAtTime(-1); 55 | } catch (Exception ex) { 56 | } finally { 57 | try { 58 | retriever.release(); 59 | } catch (RuntimeException ex) { 60 | } 61 | } 62 | 63 | if (bitmap != null) { 64 | if (kind == Video.Thumbnails.MICRO_KIND) 65 | bitmap = extractThumbnail(bitmap, TARGET_SIZE_MICRO_THUMBNAIL_WIDTH, TARGET_SIZE_MICRO_THUMBNAIL_HEIGHT, OPTIONS_RECYCLE_INPUT); 66 | else if (kind == Video.Thumbnails.MINI_KIND) 67 | bitmap = extractThumbnail(bitmap, TARGET_SIZE_MINI_THUMBNAIL_WIDTH, TARGET_SIZE_MINI_THUMBNAIL_HEIGHT, OPTIONS_RECYCLE_INPUT); 68 | } 69 | return bitmap; 70 | } 71 | 72 | public static Bitmap extractThumbnail(Bitmap source, int width, int height) { 73 | return extractThumbnail(source, width, height, OPTIONS_NONE); 74 | } 75 | 76 | public static Bitmap extractThumbnail(Bitmap source, int width, int height, int options) { 77 | if (source == null) 78 | return null; 79 | 80 | float scale; 81 | if (source.getWidth() < source.getHeight()) 82 | scale = width / (float) source.getWidth(); 83 | else 84 | scale = height / (float) source.getHeight(); 85 | Matrix matrix = new Matrix(); 86 | matrix.setScale(scale, scale); 87 | Bitmap thumbnail = transform(matrix, source, width, height, OPTIONS_SCALE_UP | options); 88 | return thumbnail; 89 | } 90 | 91 | private static Bitmap transform(Matrix scaler, Bitmap source, int targetWidth, int targetHeight, int options) { 92 | boolean scaleUp = (options & OPTIONS_SCALE_UP) != 0; 93 | boolean recycle = (options & OPTIONS_RECYCLE_INPUT) != 0; 94 | 95 | int deltaX = source.getWidth() - targetWidth; 96 | int deltaY = source.getHeight() - targetHeight; 97 | if (!scaleUp && (deltaX < 0 || deltaY < 0)) { 98 | Bitmap b2 = Bitmap.createBitmap(targetWidth, targetHeight, Bitmap.Config.ARGB_8888); 99 | Canvas c = new Canvas(b2); 100 | 101 | int deltaXHalf = Math.max(0, deltaX / 2); 102 | int deltaYHalf = Math.max(0, deltaY / 2); 103 | Rect src = new Rect(deltaXHalf, deltaYHalf, deltaXHalf + Math.min(targetWidth, source.getWidth()), deltaYHalf + Math.min(targetHeight, source.getHeight())); 104 | int dstX = (targetWidth - src.width()) / 2; 105 | int dstY = (targetHeight - src.height()) / 2; 106 | Rect dst = new Rect(dstX, dstY, targetWidth - dstX, targetHeight - dstY); 107 | c.drawBitmap(source, src, dst, null); 108 | if (recycle) 109 | source.recycle(); 110 | return b2; 111 | } 112 | 113 | float bitmapWidthF = source.getWidth(); 114 | float bitmapHeightF = source.getHeight(); 115 | float bitmapAspect = bitmapWidthF / bitmapHeightF; 116 | float viewAspect = (float) targetWidth / targetHeight; 117 | 118 | float scale = bitmapAspect > viewAspect ? targetHeight / bitmapHeightF : targetWidth / bitmapWidthF; 119 | if (scale < .9F || scale > 1F) 120 | scaler.setScale(scale, scale); 121 | else 122 | scaler = null; 123 | 124 | Bitmap b1; 125 | if (scaler != null) 126 | b1 = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), scaler, true); 127 | else 128 | b1 = source; 129 | 130 | if (recycle && b1 != source) 131 | source.recycle(); 132 | 133 | int dx1 = Math.max(0, b1.getWidth() - targetWidth); 134 | int dy1 = Math.max(0, b1.getHeight() - targetHeight); 135 | 136 | Bitmap b2 = Bitmap.createBitmap(b1, dx1 / 2, dy1 / 2, targetWidth, targetHeight); 137 | 138 | if (b2 != b1 && (recycle || b1 != source)) 139 | b1.recycle(); 140 | 141 | return b2; 142 | } 143 | 144 | } -------------------------------------------------------------------------------- /vitamio/src/io/vov/vitamio/VIntent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 YIXIA.COM 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 | 17 | package io.vov.vitamio; 18 | 19 | /** 20 | * Common intent actions used by Vitamio component. 21 | */ 22 | public class VIntent { 23 | public static final String ACTION_MEDIA_SCANNER_SCAN_DIRECTORY = "com.yixia.vitamio.action.MEDIA_SCANNER_SCAN_DIRECTORY"; 24 | public static final String ACTION_MEDIA_SCANNER_SCAN_FILE = "com.yixia.vitamio.action.MEDIA_SCANNER_SCAN_FILE"; 25 | public static final String ACTION_MEDIA_SCANNER_STARTED = "com.yixia.vitamio.action.MEDIA_SCANNER_STARTED"; 26 | public static final String ACTION_MEDIA_SCANNER_FINISHED = "com.yixia.vitamio.action.MEDIA_SCANNER_FINISHED"; 27 | } 28 | -------------------------------------------------------------------------------- /vitamio/src/io/vov/vitamio/Vitamio.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 YIXIA.COM 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 | 17 | package io.vov.vitamio; 18 | 19 | import android.content.Context; 20 | 21 | import io.vov.vitamio.utils.CPU; 22 | import io.vov.vitamio.utils.ContextUtils; 23 | import io.vov.vitamio.utils.IOUtils; 24 | import io.vov.vitamio.utils.Log; 25 | 26 | import java.io.BufferedInputStream; 27 | import java.io.BufferedReader; 28 | import java.io.File; 29 | import java.io.FileOutputStream; 30 | import java.io.FileReader; 31 | import java.io.FileWriter; 32 | import java.io.IOException; 33 | import java.io.InputStream; 34 | import java.util.ArrayList; 35 | import java.util.Arrays; 36 | import java.util.List; 37 | 38 | /** 39 | * Inspect this class before using any other Vitamio classes. 40 | * 41 | * Don't modify this class, or the full Vitamio library may be broken. 42 | */ 43 | public class Vitamio { 44 | private static final String[] LIBS_ARM_CODECS = {"libvvo.7.so", "libvvo.8.so", "libffmpeg.so", "libOMX.9.so", "libOMX.11.so", "libOMX.14.so", "libOMX.18.so"}; 45 | private static final String[] LIBS_X86_CODECS = {"libffmpeg.so", "libOMX.9.so", "libOMX.14.so", "libOMX.18.so"}; 46 | private static final String[] LIBS_MIPS_CODECS = {"libffmpeg.so", "libOMX.14.so"}; 47 | private static final String[] LIBS_PLAYER = {"libvplayer.so"}; 48 | private static final String[] LIBS_SCANNER = {"libvscanner.so"}; 49 | private static final String[] LIBS_AV = {"libvao.0.so", "libvvo.0.so", "libvvo.9.so", "libvvo.j.so"}; 50 | private static final String LIBS_LOCK = ".lock"; 51 | private static final int VITAMIO_NOT_SUPPORTED = -1; 52 | private static final int VITAMIO_MIPS = 40; 53 | private static final int VITAMIO_X86 = 50; 54 | private static final int VITAMIO_ARMV6 = 60; 55 | private static final int VITAMIO_ARMV6_VFP = 61; 56 | private static final int VITAMIO_ARMV7_VFPV3 = 70; 57 | private static final int VITAMIO_ARMV7_NEON = 71; 58 | private static final int vitamioType; 59 | 60 | static { 61 | int cpu = CPU.getFeature(); 62 | if ((cpu & CPU.FEATURE_ARM_NEON) > 0) 63 | vitamioType = VITAMIO_ARMV7_NEON; 64 | else if ((cpu & CPU.FEATURE_ARM_VFPV3) > 0 && (cpu & CPU.FEATURE_ARM_V7A) > 0) 65 | vitamioType = VITAMIO_ARMV7_VFPV3; 66 | else if ((cpu & CPU.FEATURE_ARM_VFP) > 0 && (cpu & CPU.FEATURE_ARM_V6) > 0) 67 | vitamioType = VITAMIO_ARMV6_VFP; 68 | else if ((cpu & CPU.FEATURE_ARM_V6) > 0) 69 | vitamioType = VITAMIO_ARMV6; 70 | else if ((cpu & CPU.FEATURE_X86) > 0) 71 | vitamioType = VITAMIO_X86; 72 | else if ((cpu & CPU.FEATURE_MIPS) > 0) 73 | vitamioType = VITAMIO_MIPS; 74 | else 75 | vitamioType = VITAMIO_NOT_SUPPORTED; 76 | } 77 | 78 | private static String vitamioPackage; 79 | private static String vitamioLibraryPath; 80 | 81 | /** 82 | * Call this method before using any other Vitamio specific classes. 83 | * 84 | * This method will use {@link #isInitialized(Context)} to check if Vitamio is 85 | * initialized at this device, and initialize it if not initialized. 86 | * 87 | * @param ctx Android Context 88 | * @return true if the Vitamio initialized successfully. 89 | */ 90 | public static boolean initialize(Context ctx) { 91 | return isInitialized(ctx) || extractLibs(ctx, R.raw.libarm); 92 | } 93 | 94 | /** 95 | * Same as {@link #initialize(Context)} 96 | * 97 | * @param ctx Android Context 98 | * @param rawId R.raw.libarm 99 | * @return true if the Vitamio initialized successfully. 100 | */ 101 | public static boolean initialize(Context ctx, int rawId) { 102 | return isInitialized(ctx) || extractLibs(ctx, rawId); 103 | } 104 | 105 | /** 106 | * Check if Vitamio is initialized at this device 107 | * 108 | * @param ctx Android Context 109 | * @return true if the Vitamio has been initialized. 110 | */ 111 | public static boolean isInitialized(Context ctx) { 112 | vitamioPackage = ctx.getPackageName(); 113 | vitamioLibraryPath = ContextUtils.getDataDir(ctx) + "libs/"; 114 | File dir = new File(getLibraryPath()); 115 | if (dir.exists() && dir.isDirectory()) { 116 | String[] libs = dir.list(); 117 | if (libs != null) { 118 | Arrays.sort(libs); 119 | for (String L : getRequiredLibs()) { 120 | if (Arrays.binarySearch(libs, L) < 0) { 121 | Log.e("Native libs %s not exists!", L); 122 | return false; 123 | } 124 | } 125 | File lock = new File(getLibraryPath() + LIBS_LOCK); 126 | BufferedReader buffer = null; 127 | try { 128 | buffer = new BufferedReader(new FileReader(lock)); 129 | int appVersion = ContextUtils.getVersionCode(ctx); 130 | int libVersion = Integer.valueOf(buffer.readLine()); 131 | Log.i("isNativeLibsInited, APP VERSION: %d, Vitamio Library version: %d", appVersion, libVersion); 132 | if (libVersion == appVersion) 133 | return true; 134 | } catch (IOException e) { 135 | Log.e("isNativeLibsInited", e); 136 | } catch (NumberFormatException e) { 137 | Log.e("isNativeLibsInited", e); 138 | } finally { 139 | IOUtils.closeSilently(buffer); 140 | } 141 | } 142 | } 143 | return false; 144 | } 145 | 146 | public static String getVitamioPackage() { 147 | return vitamioPackage; 148 | } 149 | 150 | public static int getVitamioType() { 151 | return vitamioType; 152 | } 153 | 154 | public static final String getLibraryPath() { 155 | return vitamioLibraryPath; 156 | } 157 | 158 | private static final List