OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MEDIA_BASE_ANDROID_MEDIA_CODEC_UTIL_H_ | 5 #ifndef MEDIA_BASE_ANDROID_MEDIA_CODEC_UTIL_H_ |
6 #define MEDIA_BASE_ANDROID_MEDIA_CODEC_UTIL_H_ | 6 #define MEDIA_BASE_ANDROID_MEDIA_CODEC_UTIL_H_ |
7 | 7 |
8 #include <jni.h> | 8 #include <jni.h> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "media/base/android/media_codec_direction.h" | 15 #include "media/base/android/media_codec_direction.h" |
| 16 #include "media/base/audio_codecs.h" |
16 #include "media/base/media_export.h" | 17 #include "media/base/media_export.h" |
17 #include "media/base/video_codecs.h" | 18 #include "media/base/video_codecs.h" |
18 | 19 |
19 class GURL; | 20 class GURL; |
20 | 21 |
21 namespace media { | 22 namespace media { |
22 | 23 |
23 class MediaCodecBridge; | 24 class MediaCodecBridge; |
24 | 25 |
25 // Helper macro to skip the test if MediaCodecBridge isn't available. | |
26 #define SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE() \ | |
27 do { \ | |
28 if (!MediaCodecUtil::IsMediaCodecAvailable()) { \ | |
29 VLOG(0) << "Could not run test - not supported on device."; \ | |
30 return; \ | |
31 } \ | |
32 } while (0) | |
33 | |
34 // Helper macro to skip the test if VP8 decoding isn't supported. | |
35 #define SKIP_TEST_IF_VP8_DECODER_IS_NOT_SUPPORTED() \ | |
36 do { \ | |
37 if (!MediaCodecUtil::IsVp8DecoderAvailable()) { \ | |
38 VLOG(0) << "Could not run test - not supported on device."; \ | |
39 return; \ | |
40 } \ | |
41 } while (0) | |
42 | |
43 class MEDIA_EXPORT MediaCodecUtil { | 26 class MEDIA_EXPORT MediaCodecUtil { |
44 public: | 27 public: |
| 28 static std::string CodecToAndroidMimeType(AudioCodec codec); |
| 29 static std::string CodecToAndroidMimeType(VideoCodec codec); |
| 30 |
45 // Returns true if MediaCodec is available on the device. | 31 // Returns true if MediaCodec is available on the device. |
46 // All other static methods check IsAvailable() internally. There's no need | 32 // All other static methods check IsAvailable() internally. There's no need |
47 // to check IsAvailable() explicitly before calling them. | 33 // to check IsAvailable() explicitly before calling them. |
48 static bool IsMediaCodecAvailable(); | 34 static bool IsMediaCodecAvailable(); |
49 | 35 |
50 // Returns true if MediaCodec is available, with |sdk| as the sdk version and | 36 // Returns true if MediaCodec is available, with |sdk| as the sdk version and |
51 // |model| as the model. This is provided for unit tests; you probably want | 37 // |model| as the model. This is provided for unit tests; you probably want |
52 // IsMediaCodecAvailable() otherwise. | 38 // IsMediaCodecAvailable() otherwise. |
53 // TODO(liberato): merge this with IsMediaCodecAvailable, and provide a way | 39 // TODO(liberato): merge this with IsMediaCodecAvailable, and provide a way |
54 // to mock BuildInfo instead. | 40 // to mock BuildInfo instead. |
55 static bool IsMediaCodecAvailableFor(int sdk, const char* model); | 41 static bool IsMediaCodecAvailableFor(int sdk, const char* model); |
56 | 42 |
57 // Returns true if MediaCodec.setParameters() is available on the device. | 43 // Returns true if MediaCodec.setParameters() is available on the device. |
58 static bool SupportsSetParameters(); | 44 static bool SupportsSetParameters(); |
59 | 45 |
60 // Returns whether MediaCodecBridge has a decoder that |is_secure| and can | 46 // Returns whether it's possible to create a MediaCodec for the given codec |
61 // decode |codec| type. | 47 // and secureness. |
62 static bool CanDecode(const std::string& codec, bool is_secure); | 48 static bool CanDecode(VideoCodec codec, bool is_secure); |
| 49 static bool CanDecode(AudioCodec codec); |
63 | 50 |
64 // Returns a vector of supported codecs profiles and levels. | 51 // Returns a vector of supported codecs profiles and levels. |
65 static bool AddSupportedCodecProfileLevels( | 52 static bool AddSupportedCodecProfileLevels( |
66 std::vector<CodecProfileLevel>* out); | 53 std::vector<CodecProfileLevel>* out); |
67 | 54 |
68 // Get a list of encoder supported color formats for |mime_type|. | 55 // Get a list of encoder supported color formats for |mime_type|. |
69 // The mapping of color format name and its value refers to | 56 // The mapping of color format name and its value refers to |
70 // MediaCodecInfo.CodecCapabilities. | 57 // MediaCodecInfo.CodecCapabilities. |
71 static std::set<int> GetEncoderColorFormats(const std::string& mime_type); | 58 static std::set<int> GetEncoderColorFormats(const std::string& mime_type); |
72 | 59 |
73 // Returns true if |mime_type| is known to be unaccelerated (i.e. backed by a | 60 // Returns true if |mime_type| is known to be unaccelerated (i.e. backed by a |
74 // software codec instead of a hardware one). | 61 // software codec instead of a hardware one). |
75 static bool IsKnownUnaccelerated(const std::string& mime_type, | 62 static bool IsKnownUnaccelerated(VideoCodec codec, |
76 MediaCodecDirection direction); | 63 MediaCodecDirection direction); |
77 | 64 |
78 // Test whether a URL contains "m3u8". | 65 // Test whether a URL contains "m3u8". |
79 static bool IsHLSURL(const GURL& url); | 66 static bool IsHLSURL(const GURL& url); |
80 | 67 |
81 // Test whether the path of a URL ends with ".m3u8". | 68 // Test whether the path of a URL ends with ".m3u8". |
82 static bool IsHLSPath(const GURL& url); | 69 static bool IsHLSPath(const GURL& url); |
83 | 70 |
84 // Indicates if the vp8 decoder or encoder is available on this device. | 71 // Indicates if the vp8 decoder or encoder is available on this device. |
85 static bool IsVp8DecoderAvailable(); | 72 static bool IsVp8DecoderAvailable(); |
86 static bool IsVp8EncoderAvailable(); | 73 static bool IsVp8EncoderAvailable(); |
87 | 74 |
88 // Indicates if the vp9 decoder is available on this device. | 75 // Indicates if the vp9 decoder is available on this device. |
89 static bool IsVp9DecoderAvailable(); | 76 static bool IsVp9DecoderAvailable(); |
90 | 77 |
91 // Indicates if the h264 encoder is available on this device. | 78 // Indicates if the h264 encoder is available on this device. |
92 static bool IsH264EncoderAvailable(); | 79 static bool IsH264EncoderAvailable(); |
93 | 80 |
94 // Indicates if SurfaceView and MediaCodec work well together on this device. | 81 // Indicates if SurfaceView and MediaCodec work well together on this device. |
95 static bool IsSurfaceViewOutputSupported(); | 82 static bool IsSurfaceViewOutputSupported(); |
96 | 83 |
97 // Indicates if MediaCodec.setOutputSurface() works on this device. | 84 // Indicates if MediaCodec.setOutputSurface() works on this device. |
98 static bool IsSetOutputSurfaceSupported(); | 85 static bool IsSetOutputSurfaceSupported(); |
99 | 86 |
100 // Indicates if the decoder is known to fail when flushed. (b/8125974, | 87 // Indicates if the decoder is known to fail when flushed. (b/8125974, |
101 // b/8347958) | 88 // b/8347958) |
102 // When true, the client should work around the issue by releasing the | 89 // When true, the client should work around the issue by releasing the |
103 // decoder and instantiating a new one rather than flushing the current one. | 90 // decoder and instantiating a new one rather than flushing the current one. |
104 static bool CodecNeedsFlushWorkaround(MediaCodecBridge* codec); | 91 static bool CodecNeedsFlushWorkaround(MediaCodecBridge* codec); |
| 92 |
| 93 private: |
| 94 static bool CanDecodeInternal(const std::string& mime, bool is_secure); |
105 }; | 95 }; |
106 | 96 |
107 } // namespace media | 97 } // namespace media |
108 | 98 |
109 #endif // MEDIA_BASE_ANDROID_MEDIA_CODEC_UTIL_H_ | 99 #endif // MEDIA_BASE_ANDROID_MEDIA_CODEC_UTIL_H_ |
OLD | NEW |