2017年3月14日 星期二

Class.forName, asSubclass, getConstructor(), newInstance()

/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.android.exoplayer2.extractor;

import java.util.ArrayList;
import java.util.List;

/**
 * An {@link ExtractorsFactory} that provides an array of extractors for the following formats:
 *
 * <ul>
 * <li>MP4, including M4A ({@link com.google.android.exoplayer2.extractor.mp4.Mp4Extractor})</li>
 * <li>fMP4 ({@link com.google.android.exoplayer2.extractor.mp4.FragmentedMp4Extractor})</li>
 * <li>Matroska and WebM ({@link com.google.android.exoplayer2.extractor.mkv.MatroskaExtractor})
 * </li>
 * <li>Ogg Vorbis/FLAC ({@link com.google.android.exoplayer2.extractor.ogg.OggExtractor}</li>
 * <li>MP3 ({@link com.google.android.exoplayer2.extractor.mp3.Mp3Extractor})</li>
 * <li>AAC ({@link com.google.android.exoplayer2.extractor.ts.AdtsExtractor})</li>
 * <li>MPEG TS ({@link com.google.android.exoplayer2.extractor.ts.TsExtractor})</li>
 * <li>MPEG PS ({@link com.google.android.exoplayer2.extractor.ts.PsExtractor})</li>
 * <li>FLV ({@link com.google.android.exoplayer2.extractor.flv.FlvExtractor})</li>
 * <li>WAV ({@link com.google.android.exoplayer2.extractor.wav.WavExtractor})</li>
 * <li>FLAC (only available if the FLAC extension is built and included)</li>
 * </ul>
 */
public final class DefaultExtractorsFactory implements ExtractorsFactory {

  // Lazily initialized default extractor classes in priority order.
  private static List<Class<? extends Extractor>> defaultExtractorClasses;

  /**
   * Creates a new factory for the default extractors.
   */
  public DefaultExtractorsFactory() {
    synchronized (DefaultExtractorsFactory.class) {
      if (defaultExtractorClasses == null) {
        // Lazily initialize defaultExtractorClasses.
        List<Class<? extends Extractor>> extractorClasses = new ArrayList<>();
        // We reference extractors using reflection so that they can be deleted cleanly.
        // Class.forName is used so that automated tools like proguard can detect the use of
        // reflection (see http://proguard.sourceforge.net/FAQ.html#forname).
        try {
          extractorClasses.add(
              Class.forName("com.google.android.exoplayer2.extractor.mkv.MatroskaExtractor")
                  .asSubclass(Extractor.class));
        } catch (ClassNotFoundException e) {
          // Extractor not found.
        }
        try {
          extractorClasses.add(
              Class.forName("com.google.android.exoplayer2.extractor.mp4.FragmentedMp4Extractor")
                  .asSubclass(Extractor.class));
        } catch (ClassNotFoundException e) {
          // Extractor not found.
        }
        try {
          extractorClasses.add(
              Class.forName("com.google.android.exoplayer2.extractor.mp4.Mp4Extractor")
                  .asSubclass(Extractor.class));
        } catch (ClassNotFoundException e) {
          // Extractor not found.
        }
        try {
          extractorClasses.add(
              Class.forName("com.google.android.exoplayer2.extractor.mp3.Mp3Extractor")
                  .asSubclass(Extractor.class));
        } catch (ClassNotFoundException e) {
          // Extractor not found.
        }
        try {
          extractorClasses.add(
              Class.forName("com.google.android.exoplayer2.extractor.ts.AdtsExtractor")
                  .asSubclass(Extractor.class));
        } catch (ClassNotFoundException e) {
          // Extractor not found.
        }
        try {
          extractorClasses.add(
              Class.forName("com.google.android.exoplayer2.extractor.ts.Ac3Extractor")
                  .asSubclass(Extractor.class));
        } catch (ClassNotFoundException e) {
          // Extractor not found.
        }
        try {
          extractorClasses.add(
              Class.forName("com.google.android.exoplayer2.extractor.ts.TsExtractor")
                  .asSubclass(Extractor.class));
        } catch (ClassNotFoundException e) {
          // Extractor not found.
        }
        try {
          extractorClasses.add(
              Class.forName("com.google.android.exoplayer2.extractor.flv.FlvExtractor")
                  .asSubclass(Extractor.class));
        } catch (ClassNotFoundException e) {
          // Extractor not found.
        }
        try {
          extractorClasses.add(
              Class.forName("com.google.android.exoplayer2.extractor.ogg.OggExtractor")
                  .asSubclass(Extractor.class));
        } catch (ClassNotFoundException e) {
          // Extractor not found.
        }
        try {
          extractorClasses.add(
              Class.forName("com.google.android.exoplayer2.extractor.ts.PsExtractor")
                  .asSubclass(Extractor.class));
        } catch (ClassNotFoundException e) {
          // Extractor not found.
        }
        try {
          extractorClasses.add(
              Class.forName("com.google.android.exoplayer2.extractor.wav.WavExtractor")
                  .asSubclass(Extractor.class));
        } catch (ClassNotFoundException e) {
          // Extractor not found.
        }
        try {
          extractorClasses.add(
              Class.forName("com.google.android.exoplayer2.ext.flac.FlacExtractor")
                  .asSubclass(Extractor.class));
        } catch (ClassNotFoundException e) {
          // Extractor not found.
        }
        defaultExtractorClasses = extractorClasses;
      }
    }
  }

  @Override
  public Extractor[] createExtractors() {
    Extractor[] extractors = new Extractor[defaultExtractorClasses.size()];
    for (int i = 0; i < extractors.length; i++) {
      try {
        extractors[i] = defaultExtractorClasses.get(i).getConstructor().newInstance();
      } catch (Exception e) {
        // Should never happen.
        throw new IllegalStateException("Unexpected error creating default extractor", e);
      }
    }
    return extractors;
  }

}

Class.forName
asSubclass
getConstructor
https://docs.oracle.com/javase/7/docs/api/java/lang/Class.html#getConstructor(java.lang.Class...)

newInstance
https://docs.oracle.com/javase/7/docs/api/java/lang/Class.html#newInstance()

Github markdown tool

https://jbt.github.io/markdown-editor/#

http://dillinger.io/

2017年1月17日 星期二

shaka player

https://shaka-player-demo.appspot.com/docs/api/index.html

What does "tunnelled video" mean for Andorid

To summarize, when Tunneled video playback is active,
  • OMX Component has advertised the support for the same
  • Complete feature is a vendor specific implementation and framework doesn't come into picture for resource allocation or synchronization
  • A/V Sync is handled at the hardware level - Support is required in Audio HAL to retrieve the references for the same
  • Video Decoder pushes the current frame directly to the display hardware
  • The Display hardware "probably" composes this picture on top of current picture being displayed and directly outputs to the screen
  • If the underlying HW is unable to support, a solid color is displayed

Ref: