Commit 8669233f authored by Finnur Thorarinsson's avatar Finnur Thorarinsson Committed by Commit Bot

[Android] PhotoPicker: Release MediaMetadataRetriever after use.

As per documentation, it should be released as soon as we're
done with it.

Bug: 895776, 656015
Change-Id: Icbdcdb0fb515070d00cde1f7fac52ce1ab594993
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2056811Reviewed-by: default avatarBoris Sazonov <bsazonov@chromium.org>
Commit-Queue: Finnur Thorarinsson <finnur@chromium.org>
Auto-Submit: Finnur Thorarinsson <finnur@chromium.org>
Cr-Commit-Position: refs/heads/master@{#742138}
parent e7bae43a
...@@ -139,10 +139,11 @@ class DecodeVideoTask extends AsyncTask<List<Bitmap>> { ...@@ -139,10 +139,11 @@ class DecodeVideoTask extends AsyncTask<List<Bitmap>> {
if (isCancelled()) return null; if (isCancelled()) return null;
AssetFileDescriptor afd = null; // TODO(finnur): Apply try-with-resources to MediaMetadataRetriever once Chrome no longer
try { // supports versions below Build.VERSION_CODES.N.
afd = mContentResolver.openAssetFileDescriptor(mUri, "r"); MediaMetadataRetriever retriever = null;
MediaMetadataRetriever retriever = new MediaMetadataRetriever(); try (AssetFileDescriptor afd = mContentResolver.openAssetFileDescriptor(mUri, "r")) {
retriever = new MediaMetadataRetriever();
retriever.setDataSource(afd.getFileDescriptor()); retriever.setDataSource(afd.getFileDescriptor());
String duration = String duration =
retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION); retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
...@@ -158,6 +159,7 @@ class DecodeVideoTask extends AsyncTask<List<Bitmap>> { ...@@ -158,6 +159,7 @@ class DecodeVideoTask extends AsyncTask<List<Bitmap>> {
retriever, afd.getFileDescriptor(), mSize, mFrames, mFullWidth, mIntervalMs); retriever, afd.getFileDescriptor(), mSize, mFrames, mFullWidth, mIntervalMs);
mDuration = duration; mDuration = duration;
mRatio = bitmaps.second; mRatio = bitmaps.second;
mDecodingResult = DecodingResult.SUCCESS;
return bitmaps.first; return bitmaps.first;
} catch (FileNotFoundException exception) { } catch (FileNotFoundException exception) {
mDecodingResult = DecodingResult.FILE_ERROR; mDecodingResult = DecodingResult.FILE_ERROR;
...@@ -165,14 +167,11 @@ class DecodeVideoTask extends AsyncTask<List<Bitmap>> { ...@@ -165,14 +167,11 @@ class DecodeVideoTask extends AsyncTask<List<Bitmap>> {
} catch (RuntimeException exception) { } catch (RuntimeException exception) {
mDecodingResult = DecodingResult.RUNTIME_ERROR; mDecodingResult = DecodingResult.RUNTIME_ERROR;
return null; return null;
} catch (IOException exception) {
mDecodingResult = DecodingResult.IO_ERROR;
return null;
} finally { } finally {
try { if (retriever != null) retriever.release();
if (afd != null) afd.close();
mDecodingResult = DecodingResult.SUCCESS;
} catch (IOException exception) {
mDecodingResult = DecodingResult.IO_ERROR;
return null;
}
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment