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.setParameters() is available on the device. | 36 // Returns true if MediaCodec.setParameters() is available on the device. |
51 static bool SupportsSetParameters(); | 37 static bool SupportsSetParameters(); |
52 | 38 |
53 // Returns whether MediaCodecBridge has a decoder that |is_secure| and can | 39 // Returns whether if it's possible to create a MediaCodec for the given |
54 // decode |codec| type. | 40 // mime type and secureness. |
55 static bool CanDecode(const std::string& codec, bool is_secure); | 41 static bool CanDecode(const std::string& mime_type, bool is_secure); |
56 | 42 |
57 // Returns a vector of supported codecs profiles and levels. | 43 // Returns a vector of supported codecs profiles and levels. |
58 static bool AddSupportedCodecProfileLevels( | 44 static bool AddSupportedCodecProfileLevels( |
59 std::vector<CodecProfileLevel>* out); | 45 std::vector<CodecProfileLevel>* out); |
60 | 46 |
61 // Get a list of encoder supported color formats for |mime_type|. | 47 // Get a list of encoder supported color formats for |mime_type|. |
62 // The mapping of color format name and its value refers to | 48 // The mapping of color format name and its value refers to |
63 // MediaCodecInfo.CodecCapabilities. | 49 // MediaCodecInfo.CodecCapabilities. |
64 static std::set<int> GetEncoderColorFormats(const std::string& mime_type); | 50 static std::set<int> GetEncoderColorFormats(const std::string& mime_type); |
65 | 51 |
66 // Returns true if |mime_type| is known to be unaccelerated (i.e. backed by a | 52 // Returns true if |mime_type| is known to be unaccelerated (i.e. backed by a |
67 // software codec instead of a hardware one). | 53 // software codec instead of a hardware one). |
68 static bool IsKnownUnaccelerated(const std::string& mime_type, | 54 static bool IsKnownUnaccelerated(VideoCodec codec, |
69 MediaCodecDirection direction); | 55 MediaCodecDirection direction); |
70 | 56 |
71 // Test whether a URL contains "m3u8". | 57 // Test whether a URL contains "m3u8". |
72 static bool IsHLSURL(const GURL& url); | 58 static bool IsHLSURL(const GURL& url); |
73 | 59 |
74 // Test whether the path of a URL ends with ".m3u8". | 60 // Test whether the path of a URL ends with ".m3u8". |
75 static bool IsHLSPath(const GURL& url); | 61 static bool IsHLSPath(const GURL& url); |
76 | 62 |
77 // Indicates if the vp8 decoder or encoder is available on this device. | 63 // Indicates if the vp8 decoder or encoder is available on this device. |
78 static bool IsVp8DecoderAvailable(); | 64 static bool IsVp8DecoderAvailable(); |
(...skipping 14 matching lines...) Expand all Loading... |
93 // Indicates if the decoder is known to fail when flushed. (b/8125974, | 79 // Indicates if the decoder is known to fail when flushed. (b/8125974, |
94 // b/8347958) | 80 // b/8347958) |
95 // When true, the client should work around the issue by releasing the | 81 // When true, the client should work around the issue by releasing the |
96 // decoder and instantiating a new one rather than flushing the current one. | 82 // decoder and instantiating a new one rather than flushing the current one. |
97 static bool CodecNeedsFlushWorkaround(MediaCodecBridge* codec); | 83 static bool CodecNeedsFlushWorkaround(MediaCodecBridge* codec); |
98 }; | 84 }; |
99 | 85 |
100 } // namespace media | 86 } // namespace media |
101 | 87 |
102 #endif // MEDIA_BASE_ANDROID_MEDIA_CODEC_UTIL_H_ | 88 #endif // MEDIA_BASE_ANDROID_MEDIA_CODEC_UTIL_H_ |
OLD | NEW |