Home | History | Annotate | Download | only in lvpp
      1 /*
      2  * Copyright (C) 2011 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 #include <stdint.h>
     18 
     19 #include <utils/RefBase.h>
     20 #include <utils/threads.h>
     21 
     22 #include <media/stagefright/MediaSource.h>
     23 
     24 #include "AudioBufferProvider.h"
     25 #include "AudioResampler.h"
     26 
     27 namespace android {
     28 
     29 struct MediaBuffer;
     30 
     31 class VideoEditorSRC : public MediaSource , public AudioBufferProvider {
     32 
     33     public:
     34         VideoEditorSRC(
     35             const sp<MediaSource> &source);
     36 
     37         virtual status_t start (MetaData *params = NULL);
     38         virtual status_t stop();
     39         virtual sp<MetaData> getFormat();
     40         virtual status_t read (
     41             MediaBuffer **buffer, const ReadOptions *options = NULL);
     42 
     43         virtual status_t getNextBuffer(Buffer* buffer);
     44         virtual void releaseBuffer(Buffer* buffer);
     45 
     46     enum { //Sampling freq
     47         kFreq8000Hz = 8000,
     48         kFreq11025Hz = 11025,
     49         kFreq12000Hz = 12000,
     50         kFreq16000Hz = 16000,
     51         kFreq22050Hz = 22050,
     52         kFreq240000Hz = 24000,
     53         kFreq32000Hz = 32000,
     54         kFreq44100 = 44100,
     55         kFreq48000 = 48000,
     56     };
     57 
     58     static const uint16_t UNITY_GAIN = 0x1000;
     59     static const int32_t DEFAULT_SAMPLING_FREQ = (int32_t)kFreq32000Hz;
     60 
     61     protected :
     62         virtual ~VideoEditorSRC();
     63     private:
     64 
     65         VideoEditorSRC();
     66         VideoEditorSRC &operator=(const VideoEditorSRC &);
     67 
     68         void checkAndSetResampler();
     69 
     70         AudioResampler        *mResampler;
     71         sp<MediaSource>      mSource;
     72         int mChannelCnt;
     73         int mSampleRate;
     74         int32_t mOutputSampleRate;
     75         bool mStarted;
     76         sp<MetaData> mOutputFormat;
     77 
     78         MediaBuffer* mBuffer;
     79         int32_t mLeftover;
     80         bool mFormatChanged;
     81 
     82         int64_t mInitialTimeStampUs;
     83         int64_t mAccuOutBufferSize;
     84 
     85         int64_t mSeekTimeUs;
     86         ReadOptions::SeekMode mSeekMode;
     87 };
     88 
     89 } //namespce android
     90 
     91