Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
沉迷打码的小凳子
glide
提交
512fcec1
G
glide
项目概览
沉迷打码的小凳子
/
glide
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
glide
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
512fcec1
编写于
6月 17, 2014
作者:
S
Sam Judd
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix NPE in ImageVideoBitmapDecoder.
上级
ac17cee9
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
118 addition
and
4 deletion
+118
-4
library/src/main/java/com/bumptech/glide/load/resource/bitmap/ImageVideoBitmapDecoder.java
...h/glide/load/resource/bitmap/ImageVideoBitmapDecoder.java
+4
-1
library/src/main/java/com/bumptech/glide/load/resource/bitmap/VideoBitmapDecoder.java
...mptech/glide/load/resource/bitmap/VideoBitmapDecoder.java
+25
-2
library/src/test/java/com/bumptech/glide/load/resource/bitmap/ImageVideoBitmapDecoderTest.java
...ide/load/resource/bitmap/ImageVideoBitmapDecoderTest.java
+10
-1
library/src/test/java/com/bumptech/glide/load/resource/bitmap/VideoBitmapDecoderTest.java
...ch/glide/load/resource/bitmap/VideoBitmapDecoderTest.java
+79
-0
未找到文件。
library/src/main/java/com/bumptech/glide/load/resource/bitmap/ImageVideoBitmapDecoder.java
浏览文件 @
512fcec1
...
...
@@ -36,7 +36,10 @@ public class ImageVideoBitmapDecoder implements ResourceDecoder<ImageVideoWrappe
}
if
(
result
==
null
)
{
result
=
fileDescriptorDecoder
.
decode
(
source
.
getFileDescriptor
(),
width
,
height
);
ParcelFileDescriptor
fileDescriptor
=
source
.
getFileDescriptor
();
if
(
fileDescriptor
!=
null
)
{
result
=
fileDescriptorDecoder
.
decode
(
source
.
getFileDescriptor
(),
width
,
height
);
}
}
return
result
;
}
...
...
library/src/main/java/com/bumptech/glide/load/resource/bitmap/VideoBitmapDecoder.java
浏览文件 @
512fcec1
...
...
@@ -9,11 +9,27 @@ import com.bumptech.glide.load.DecodeFormat;
import
java.io.IOException
;
public
class
VideoBitmapDecoder
implements
BitmapDecoder
<
ParcelFileDescriptor
>
{
private
static
final
DefaultFactory
DEFAULT_FACTORY
=
new
DefaultFactory
();
private
MediaMetadataRetrieverFactory
factory
;
interface
MediaMetadataRetrieverFactory
{
public
MediaMetadataRetriever
build
();
}
public
VideoBitmapDecoder
()
{
this
(
DEFAULT_FACTORY
);
}
VideoBitmapDecoder
(
MediaMetadataRetrieverFactory
factory
)
{
this
.
factory
=
factory
;
}
@Override
public
Bitmap
decode
(
ParcelFileDescriptor
resource
,
BitmapPool
bitmapPool
,
int
outWidth
,
int
outHeight
,
DecodeFormat
decodeFormat
)
throws
IOException
{
MediaMetadataRetriever
mediaMetadataRetriever
=
new
MediaMetadataRetriever
();
MediaMetadataRetriever
mediaMetadataRetriever
=
factory
.
build
();
mediaMetadataRetriever
.
setDataSource
(
resource
.
getFileDescriptor
());
Bitmap
result
=
mediaMetadataRetriever
.
getFrameAtTime
();
mediaMetadataRetriever
.
release
();
...
...
@@ -23,6 +39,13 @@ public class VideoBitmapDecoder implements BitmapDecoder<ParcelFileDescriptor> {
@Override
public
String
getId
()
{
return
"VideoBitmapDecoder.com.bumptech.glide.load.data.bitmap"
;
return
"VideoBitmapDecoder.com.bumptech.glide.load.resource.bitmap"
;
}
private
static
class
DefaultFactory
implements
MediaMetadataRetrieverFactory
{
@Override
public
MediaMetadataRetriever
build
()
{
return
new
MediaMetadataRetriever
();
}
}
}
library/src/test/java/com/bumptech/glide/load/resource/bitmap/ImageVideoBitmapDecoderTest.java
浏览文件 @
512fcec1
...
...
@@ -82,6 +82,16 @@ public class ImageVideoBitmapDecoderTest {
verify
(
harness
.
streamDecoder
,
never
()).
decode
(
any
(
InputStream
.
class
),
anyInt
(),
anyInt
());
}
@Test
public
void
testDoesNotTryToDecodeNullFileDescriptor
()
throws
IOException
{
when
(
harness
.
wrapper
.
getStream
()).
thenReturn
(
null
);
when
(
harness
.
wrapper
.
getFileDescriptor
()).
thenReturn
(
null
);
harness
.
decoder
.
decode
(
harness
.
wrapper
,
100
,
102
);
verify
(
harness
.
fileDescriptorDecoder
,
never
()).
decode
(
any
(
ParcelFileDescriptor
.
class
),
anyInt
(),
anyInt
());
}
@Test
public
void
testHasValidId
()
{
Util
.
assertClassHasValidId
(
ImageVideoBitmapDecoder
.
class
,
harness
.
decoder
.
getId
());
...
...
@@ -94,6 +104,5 @@ public class ImageVideoBitmapDecoderTest {
ResourceDecoder
<
ParcelFileDescriptor
,
Bitmap
>
fileDescriptorDecoder
=
mock
(
ResourceDecoder
.
class
);
ImageVideoBitmapDecoder
decoder
=
new
ImageVideoBitmapDecoder
(
streamDecoder
,
fileDescriptorDecoder
);
ImageVideoWrapper
wrapper
=
mock
(
ImageVideoWrapper
.
class
);
}
}
library/src/test/java/com/bumptech/glide/load/resource/bitmap/VideoBitmapDecoderTest.java
0 → 100644
浏览文件 @
512fcec1
package
com.bumptech.glide.load.resource.bitmap
;
import
android.graphics.Bitmap
;
import
android.media.MediaMetadataRetriever
;
import
android.os.ParcelFileDescriptor
;
import
com.bumptech.glide.load.DecodeFormat
;
import
com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool
;
import
com.bumptech.glide.tests.Util
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.robolectric.RobolectricTestRunner
;
import
java.io.FileDescriptor
;
import
java.io.IOException
;
import
static
junit
.
framework
.
Assert
.
assertEquals
;
import
static
org
.
mockito
.
Matchers
.
eq
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
@RunWith
(
RobolectricTestRunner
.
class
)
public
class
VideoBitmapDecoderTest
{
private
BitmapPool
bitmapPool
;
private
DecodeFormat
decodeFormat
;
private
ParcelFileDescriptor
resource
;
private
VideoBitmapDecoder
decoder
;
private
VideoBitmapDecoder
.
MediaMetadataRetrieverFactory
factory
;
private
MediaMetadataRetriever
retriever
;
@Before
public
void
setup
()
{
bitmapPool
=
mock
(
BitmapPool
.
class
);
decodeFormat
=
DecodeFormat
.
ALWAYS_ARGB_8888
;
resource
=
mock
(
ParcelFileDescriptor
.
class
);
factory
=
mock
(
VideoBitmapDecoder
.
MediaMetadataRetrieverFactory
.
class
);
retriever
=
mock
(
MediaMetadataRetriever
.
class
);
when
(
factory
.
build
()).
thenReturn
(
retriever
);
decoder
=
new
VideoBitmapDecoder
(
new
VideoBitmapDecoder
.
MediaMetadataRetrieverFactory
()
{
@Override
public
MediaMetadataRetriever
build
()
{
return
factory
.
build
();
}
});
}
@Test
public
void
testReturnsRetrievedFrameForResource
()
throws
IOException
{
Bitmap
expected
=
Bitmap
.
createBitmap
(
100
,
100
,
Bitmap
.
Config
.
ARGB_8888
);
when
(
retriever
.
getFrameAtTime
()).
thenReturn
(
expected
);
FileDescriptor
toSet
=
FileDescriptor
.
in
;
when
(
resource
.
getFileDescriptor
()).
thenReturn
(
toSet
);
Bitmap
result
=
decoder
.
decode
(
resource
,
bitmapPool
,
100
,
100
,
decodeFormat
);
verify
(
retriever
).
setDataSource
(
eq
(
toSet
));
assertEquals
(
expected
,
result
);
}
@Test
public
void
testReleasesMediaMetadataRetriever
()
throws
IOException
{
decoder
.
decode
(
resource
,
bitmapPool
,
1
,
2
,
decodeFormat
);
verify
(
retriever
).
release
();
}
@Test
public
void
testClosesResource
()
throws
IOException
{
decoder
.
decode
(
resource
,
bitmapPool
,
1
,
2
,
decodeFormat
);
verify
(
resource
).
close
();
}
@Test
public
void
testHasValidId
()
{
Util
.
assertClassHasValidId
(
VideoBitmapDecoder
.
class
,
decoder
.
getId
());
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录