1 // Copyright (c) 2013 Intel Corporation. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 package org.xwalk.runtime.extension.api.device_capabilities;
9 import org.json.JSONObject;
11 import android.os.Build;
13 abstract class XWalkMediaCodec {
14 private static final String TAG = "XWalkMediaCodec";
16 /** Android MediaCodec API reports codec with namespace instead of common codec name.
17 * For example: "OMX.google.h263.decoder", what this API want to report is "h263".
19 * The below static lists are used to parse out the common codec name. The codec names
20 * are referenced by below links, it maybe adjusted on demand.
22 * http://www.chromium.org/audio-video
23 * https://developer.mozilla.org/en-US/docs/HTML/Supported_media_formats
25 protected static final String[] AUDIO_CODEC_NAMES =
26 {"ALAC", "MP3", "AMRNB", "AMRWB", "AAC", "G711", "VORBIS", "WMA", "FLAC", "OPUS"};
27 protected static final String[] VIDEO_CODEC_NAMES =
28 {"H263", "H264", "MPEG4", "AVC", "WMV", "VP8", "Theora"};
30 protected Set<AudioCodecElement> mAudioCodecsSet;
31 protected Set<VideoCodecElement> mVideoCodecsSet;
33 protected DeviceCapabilities mDeviceCapabilities;
34 private static XWalkMediaCodec sInstance;
36 protected class AudioCodecElement {
37 public String codecName;
39 public AudioCodecElement(String name) {
43 // Objects of this class need to be added to a HashSet, so we implement equals()
44 // and hashCode() to support comparison operation.
45 public boolean equals(Object obj) {
46 return this.codecName.equals(((AudioCodecElement)obj).codecName);
49 public int hashCode() {
50 return codecName.hashCode();
54 protected class VideoCodecElement {
55 public String codecName;
56 public boolean isEncoder;
57 public boolean hwAccel;
59 public VideoCodecElement(String name, boolean encoder, boolean hardware) {
65 // Objects of this class need to be added to a HashSet, so we implement equals()
66 // and hashCode() to support comparison operation.
67 public boolean equals(Object obj) {
68 return this.codecName.equals(((VideoCodecElement)obj).codecName)
69 && this.isEncoder == ((VideoCodecElement)obj).isEncoder
70 && this.hwAccel == ((VideoCodecElement)obj).hwAccel;
73 public int hashCode() {
74 return codecName.hashCode();
78 public static XWalkMediaCodec getInstance(DeviceCapabilities instance) {
79 if (sInstance == null) {
80 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
81 sInstance = new MediaCodec(instance);
83 sInstance = new MediaCodecNull(instance);
89 public abstract JSONObject getCodecsInfo();