AudioEncoder extends Encoder { public AudioEncoder(IMediaCodec mediaCodec) { super(mediaCodec); } AudioEncoder(IMediaCodec mediaCodec); @Override void setMediaFormat(MediaFormat mediaFormat); @Override void setInputMediaFormat(MediaFormat mediaFormat); @Override boolean isLastFile(); @Override void setOutputSurface(ISurface surface); @Override void waitForSurface(long pts); @Override void drain(int bufferIndex); @Override void push(Frame frame); int getSampleRate(); int getChannelCount(); int getBitRate(); void setSampleRate(int sampleRateInHz); void setChannelCount(int channelCount); void resampleAudioFrame(Frame frame); void addResampler(Resampler resampler);  }
@Test public void uponEncoderStart_CommandQueuesAreEmpty() { AudioEncoder encoder = create.audioEncoder().construct(); encoder.start(); assertThat(encoder.getInputCommandQueue()).isEmpty(); assertThat(encoder.getOutputCommandQueue()).isEmpty(); }
@Test public void fillCommandQueues_AddsNeedDataToEmptyInputCommandQueue() { AudioEncoder encoder = create.audioEncoder().construct(); encoder.start(); encoder.fillCommandQueues(); assertThat(encoder.getInputCommandQueue()).equalsTo(Command.NeedData); }
@Test public void fillCommandQueues_InputCommandQueueSizeDoesNotExceedTheNumberOfAvailableInputBuffers() { AudioEncoder encoder = create.audioEncoder().withDequeueInputBufferIndex(-1, -1, 0, 1).construct(); encoder.start(); for(int i = 0; i < 100; i++) { encoder.fillCommandQueues(); } assertThat(encoder.getInputCommandQueue()).equalsTo(Command.NeedData, Command.NeedData); }
@Test public void saysNeedData_whenHasInputBuffer() { AudioEncoder encoder = create.audioEncoder().withDequeueInputBufferIndex(2).construct(); encoder.start(); encoder.fillCommandQueues(); assertThat(encoder.getInputCommandQueue()).equalsTo(Command.NeedData); }
@Test public void doesNotSayNeedData_whenHasNoInputBuffer() { AudioEncoder encoder = create.audioEncoder().withDequeueInputBufferIndex(-1).construct(); encoder.start(); encoder.fillCommandQueues(); assertThat(encoder.getInputCommandQueue()).isEmpty(); }
@Test public void findFreeFrameReturnsNull_whenFillCommandQueuesNotCalled() { AudioEncoder encoder = create.audioEncoder().withDequeueInputBufferIndex(2).construct(); encoder.start(); Frame frame = encoder.findFreeFrame(); assertNull(frame); }
@Test public void findFreeFrameReturnsCorrectBufferIndex_whenHasInputBuffer() { AudioEncoder encoder = create.audioEncoder().withDequeueInputBufferIndex(0, 1).construct(); encoder.start(); Frame frame; encoder.fillCommandQueues(); encoder.fillCommandQueues(); frame = encoder.findFreeFrame(); assertEquals(0, frame.getBufferIndex()); frame = encoder.findFreeFrame(); assertEquals(1, frame.getBufferIndex()); }