Home | History | Annotate | Download | only in cts
      1 /*
      2  * Copyright (C) 2017 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package android.media.cts;
     18 
     19 import android.media.MediaCodec;
     20 import android.media.MediaCodec.BufferInfo;
     21 import android.media.MediaCodec.Callback;
     22 import android.media.MediaFormat;
     23 import android.os.Bundle;
     24 import java.nio.ByteBuffer;
     25 
     26 public class SdkMediaCodec implements MediaCodecWrapper {
     27 
     28     private final MediaCodec mCodec;
     29     private final boolean mAsync;
     30     private ByteBuffer[] mOutputBuffers;
     31     private ByteBuffer[] mInputBuffers;
     32 
     33     public SdkMediaCodec(MediaCodec codec, boolean async) {
     34         this.mCodec = codec;
     35         this.mAsync = async;
     36     }
     37 
     38     public SdkMediaCodec(MediaCodec codec) {
     39         this(codec, false);
     40     }
     41 
     42     public MediaCodec getMediaCodec() {
     43         return mCodec;
     44     }
     45 
     46     @Override
     47     public final void release() {
     48         mCodec.release();
     49     }
     50 
     51     @Override
     52     public void configure(MediaFormat format, int flags) {
     53         mCodec.configure(format, null, null, flags);
     54     }
     55 
     56     @Override
     57     public void setInputSurface(InputSurfaceInterface surface) {
     58         surface.configure(mCodec);
     59     }
     60 
     61     @Override
     62     public final InputSurfaceInterface createInputSurface() {
     63         return new InputSurface(mCodec.createInputSurface());
     64     }
     65 
     66     @Override
     67     public final void start() {
     68         mCodec.start();
     69     }
     70 
     71     @Override
     72     public final void stop() {
     73         mCodec.stop();
     74     }
     75 
     76     @Override
     77     public final int dequeueOutputBuffer(BufferInfo info, long timeoutUs) {
     78         return mCodec.dequeueOutputBuffer(info, timeoutUs);
     79     }
     80 
     81     @Override
     82     public final void releaseOutputBuffer(int index, boolean render) {
     83         mCodec.releaseOutputBuffer(index, render);
     84     }
     85 
     86     @Override
     87     public final void signalEndOfInputStream() {
     88         mCodec.signalEndOfInputStream();
     89     }
     90 
     91     @Override
     92     public ByteBuffer[] getOutputBuffers() {
     93         return mOutputBuffers = mCodec.getOutputBuffers();
     94     }
     95 
     96     @Override
     97     public final String getOutputFormatString() {
     98         return mCodec.getOutputFormat().toString();
     99     }
    100 
    101     @Override
    102     public ByteBuffer getOutputBuffer(int index) {
    103         return mAsync? mCodec.getOutputBuffer(index) : mOutputBuffers[index];
    104     }
    105 
    106     @Override
    107     public ByteBuffer[] getInputBuffers() {
    108         return mInputBuffers = mCodec.getInputBuffers();
    109     }
    110 
    111     @Override
    112     public ByteBuffer getInputBuffer(int index) {
    113         return mAsync? mCodec.getInputBuffer(index) : mInputBuffers[index];
    114     }
    115 
    116     @Override
    117     public void queueInputBuffer(
    118             int index,
    119             int offset,
    120             int size,
    121             long presentationTimeUs,
    122             int flags) {
    123         mCodec.queueInputBuffer(index, offset, size, presentationTimeUs, flags);
    124     }
    125 
    126     @Override
    127     public int dequeueInputBuffer(long timeoutUs) {
    128         return mCodec.dequeueInputBuffer(timeoutUs);
    129     }
    130 
    131     @Override
    132     public void setParameters(Bundle params) {
    133         mCodec.setParameters(params);
    134     }
    135 
    136     @Override
    137     public void setCallback(Callback mCallback) {
    138         mCodec.setCallback(mCallback);
    139     }
    140 
    141 }
    142