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.core.internal.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;
35 protected class AudioCodecElement {
36 public String codecName;
38 public AudioCodecElement(String name) {
42 // Objects of this class need to be added to a HashSet, so we implement equals()
43 // and hashCode() to support comparison operation.
44 public boolean equals(Object obj) {
45 return this.codecName.equals(((AudioCodecElement)obj).codecName);
48 public int hashCode() {
49 return codecName.hashCode();
53 protected class VideoCodecElement {
54 public String codecName;
55 public boolean isEncoder;
56 public boolean hwAccel;
58 public VideoCodecElement(String name, boolean encoder, boolean hardware) {
64 // Objects of this class need to be added to a HashSet, so we implement equals()
65 // and hashCode() to support comparison operation.
66 public boolean equals(Object obj) {
67 return this.codecName.equals(((VideoCodecElement)obj).codecName)
68 && this.isEncoder == ((VideoCodecElement)obj).isEncoder
69 && this.hwAccel == ((VideoCodecElement)obj).hwAccel;
72 public int hashCode() {
73 return codecName.hashCode();
77 public static XWalkMediaCodec Create(DeviceCapabilities instance) {
78 XWalkMediaCodec codec;
79 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
80 codec = new MediaCodec(instance);
82 codec = new MediaCodecNull(instance);
87 public abstract JSONObject getCodecsInfo();